diff options
author | Stef Walter <stefw@collabora.co.uk> | 2011-04-06 20:08:05 +0200 |
---|---|---|
committer | Stef Walter <stefw@collabora.co.uk> | 2011-04-06 22:31:07 +0200 |
commit | e61a7b36b008541843fc7385e45d157701232ed1 (patch) | |
tree | 065c6910c1ab52b466da211d22bc8ed842a6e0be | |
parent | 3fe36de1ef0e93c86021d7a0a256db189ce1e4f1 (diff) | |
download | gnome-keyring-e61a7b36b008541843fc7385e45d157701232ed1.tar.gz |
gcr: Modernize tests. Use standard gtest type setup.
-rw-r--r-- | .gitignore | 9 | ||||
-rw-r--r-- | gcr/gcr-parser.c | 2 | ||||
-rw-r--r-- | gcr/gcr-parser.h | 2 | ||||
-rw-r--r-- | gcr/tests/Makefile.am | 92 | ||||
-rw-r--r-- | gcr/tests/files/RSA_Root_Certificate_1.pem (renamed from gcr/tests/test-data/RSA_Root_Certificate_1.pem) | 0 | ||||
-rw-r--r-- | gcr/tests/files/RSA_Security_1024_v3.pem (renamed from gcr/tests/test-data/RSA_Security_1024_v3.pem) | 0 | ||||
-rw-r--r-- | gcr/tests/files/RSA_Security_2048_v3.pem (renamed from gcr/tests/test-data/RSA_Security_2048_v3.pem) | 0 | ||||
-rw-r--r-- | gcr/tests/files/Thawte_Personal_Basic_CA.pem (renamed from gcr/tests/test-data/Thawte_Personal_Basic_CA.pem) | 0 | ||||
-rw-r--r-- | gcr/tests/files/Thawte_Personal_Freemail_CA.pem (renamed from gcr/tests/test-data/Thawte_Personal_Freemail_CA.pem) | 0 | ||||
-rw-r--r-- | gcr/tests/files/Thawte_Personal_Premium_CA.pem (renamed from gcr/tests/test-data/Thawte_Personal_Premium_CA.pem) | 0 | ||||
-rw-r--r-- | gcr/tests/files/Thawte_Premium_Server_CA.pem (renamed from gcr/tests/test-data/Thawte_Premium_Server_CA.pem) | 0 | ||||
-rw-r--r-- | gcr/tests/files/Thawte_Server_CA.pem (renamed from gcr/tests/test-data/Thawte_Server_CA.pem) | 0 | ||||
-rw-r--r-- | gcr/tests/files/Thawte_Time_Stamping_CA.pem (renamed from gcr/tests/test-data/Thawte_Time_Stamping_CA.pem) | 0 | ||||
-rw-r--r-- | gcr/tests/files/ca-certificates.crt (renamed from gcr/tests/test-data/ca-certificates.crt) | 0 | ||||
-rw-r--r-- | gcr/tests/files/cacert.org.pem (renamed from gcr/tests/test-data/cacert.org.pem) | 0 | ||||
-rw-r--r-- | gcr/tests/files/collabora-ca.cer (renamed from gcr/tests/test-data/collabora-ca.cer) | bin | 1536 -> 1536 bytes | |||
-rwxr-xr-x | gcr/tests/files/der-certificate-dsa.cer (renamed from gcr/tests/test-data/der-certificate-dsa.cer) | bin | 1639 -> 1639 bytes | |||
-rw-r--r-- | gcr/tests/files/der-certificate.crt (renamed from gcr/tests/test-data/der-certificate.crt) | bin | 747 -> 747 bytes | |||
-rw-r--r-- | gcr/tests/files/der-dsa-1024.key (renamed from gcr/tests/test-data/der-dsa-1024.key) | bin | 447 -> 447 bytes | |||
-rw-r--r-- | gcr/tests/files/der-pkcs8-PBE-MD5-DES.key (renamed from gcr/tests/test-data/der-pkcs8-PBE-MD5-DES.key) | bin | 677 -> 677 bytes | |||
-rw-r--r-- | gcr/tests/files/der-pkcs8-PBE-SHA1-3DES.key (renamed from gcr/tests/test-data/der-pkcs8-PBE-SHA1-3DES.key) | bin | 678 -> 678 bytes | |||
-rw-r--r-- | gcr/tests/files/der-pkcs8-PBE-SHA1-DES.key (renamed from gcr/tests/test-data/der-pkcs8-PBE-SHA1-DES.key) | bin | 677 -> 677 bytes | |||
-rw-r--r-- | gcr/tests/files/der-pkcs8-PBE-SHA1-RC2-40.key (renamed from gcr/tests/test-data/der-pkcs8-PBE-SHA1-RC2-40.key) | bin | 678 -> 678 bytes | |||
-rw-r--r-- | gcr/tests/files/der-pkcs8-PBE-SHA1-RC4-128.key (renamed from gcr/tests/test-data/der-pkcs8-PBE-SHA1-RC4-128.key) | bin | 673 -> 673 bytes | |||
-rw-r--r-- | gcr/tests/files/der-pkcs8-dsa.key (renamed from gcr/tests/test-data/der-pkcs8-dsa.key) | bin | 335 -> 335 bytes | |||
-rw-r--r-- | gcr/tests/files/der-pkcs8-encrypted-pkcs5.key (renamed from gcr/tests/test-data/der-pkcs8-encrypted-pkcs5.key) | bin | 677 -> 677 bytes | |||
-rw-r--r-- | gcr/tests/files/der-pkcs8-v2-des.key (renamed from gcr/tests/test-data/der-pkcs8-v2-des.key) | bin | 711 -> 711 bytes | |||
-rw-r--r-- | gcr/tests/files/der-pkcs8-v2-des3.key (renamed from gcr/tests/test-data/der-pkcs8-v2-des3.key) | bin | 714 -> 714 bytes | |||
-rw-r--r-- | gcr/tests/files/der-pkcs8.key (renamed from gcr/tests/test-data/der-pkcs8.key) | bin | 635 -> 635 bytes | |||
-rw-r--r-- | gcr/tests/files/der-rsa-1024.key (renamed from gcr/tests/test-data/der-rsa-1024.key) | bin | 609 -> 609 bytes | |||
-rw-r--r-- | gcr/tests/files/dhansak-collabora.cer (renamed from gcr/tests/test-data/dhansak-collabora.cer) | bin | 1200 -> 1200 bytes | |||
-rw-r--r-- | gcr/tests/files/email.p12 (renamed from gcr/tests/test-data/email.p12) | bin | 2488 -> 2488 bytes | |||
-rw-r--r-- | gcr/tests/files/pem-dsa-1024.key (renamed from gcr/tests/test-data/pem-dsa-1024.key) | 0 | ||||
-rw-r--r-- | gcr/tests/files/pem-pkcs8.key (renamed from gcr/tests/test-data/pem-pkcs8.key) | 0 | ||||
-rw-r--r-- | gcr/tests/files/pem-rsa-enc.key (renamed from gcr/tests/test-data/pem-rsa-enc.key) | 0 | ||||
-rwxr-xr-x | gcr/tests/files/test-x509-swiss.p7b (renamed from gcr/tests/test-data/test-x509-swiss.p7b) | bin | 1002 -> 1002 bytes | |||
-rw-r--r-- | gcr/tests/files/unclient.p12 (renamed from gcr/tests/test-data/unclient.p12) | bin | 1476 -> 1476 bytes | |||
-rw-r--r-- | gcr/tests/frob-certificate.c (renamed from gcr/tests/ui-test-certificate.c) | 0 | ||||
-rw-r--r-- | gcr/tests/frob-key.c (renamed from gcr/tests/ui-test-key.c) | 0 | ||||
-rwxr-xr-x | gcr/tests/frob-selector | 148 | ||||
-rw-r--r-- | gcr/tests/frob-unlock-options.c (renamed from gcr/tests/ui-test-unlock-options.c) | 0 | ||||
-rw-r--r-- | gcr/tests/test-certificate-chain.c | 227 | ||||
-rw-r--r-- | gcr/tests/test-certificate.c | 197 | ||||
-rw-r--r-- | gcr/tests/test-parser.c (renamed from gcr/tests/unit-test-parser.c) | 113 | ||||
-rw-r--r-- | gcr/tests/test-pkcs11-certificate.c | 130 | ||||
-rw-r--r-- | gcr/tests/test-simple-certificate.c | 63 | ||||
-rw-r--r-- | gcr/tests/test-trust.c | 150 |
47 files changed, 766 insertions, 367 deletions
@@ -104,6 +104,15 @@ run-tests /gck/tests/test-gck-slot /gck/tests/test-gck-uri +/gcr/tests/frob-certificate +/gcr/tests/frob-key +/gcr/tests/frob-unlock-options +/gcr/tests/test-certificate +/gcr/tests/test-certificate-chain +/gcr/tests/test-parser +/gcr/tests/test-pkcs11-certificate +/gcr/tests/test-simple-certificate +/gcr/tests/test-trust /daemon/dbus/tests/test-secret-util diff --git a/gcr/gcr-parser.c b/gcr/gcr-parser.c index 3953ffea..bc00f317 100644 --- a/gcr/gcr-parser.c +++ b/gcr/gcr-parser.c @@ -1535,7 +1535,7 @@ gcr_parser_add_password (GcrParser *self, const gchar *password) } gboolean -gcr_parser_parse_data (GcrParser *self, const guchar *data, +gcr_parser_parse_data (GcrParser *self, gconstpointer data, gsize n_data, GError **err) { ForeachArgs args = { self, data, n_data, GCR_ERROR_UNRECOGNIZED }; diff --git a/gcr/gcr-parser.h b/gcr/gcr-parser.h index d7ef25b5..4d9bc106 100644 --- a/gcr/gcr-parser.h +++ b/gcr/gcr-parser.h @@ -75,7 +75,7 @@ gboolean gcr_parser_format_supported (GcrParser *self, gint format); gboolean gcr_parser_parse_data (GcrParser *self, - const guchar *data, + gconstpointer data, gsize n_data, GError **err); diff --git a/gcr/tests/Makefile.am b/gcr/tests/Makefile.am index fab95d81..1e57e92e 100644 --- a/gcr/tests/Makefile.am +++ b/gcr/tests/Makefile.am @@ -1,70 +1,48 @@ -# Test files should be listed in order they need to run -TESTING_FILES = \ - test-certificate.c \ - test-certificate-chain.c \ - test-simple-certificate.c \ - test-pkcs11-certificate.c \ - test-trust.c \ - unit-test-parser.c +INCLUDES = \ + -I$(top_srcdir)/egg \ + -I$(top_srcdir)/gcr \ + -DSRCDIR=$(srcdir) \ + -DGCR_API_SUBJECT_TO_CHANGE \ + -DGCK_API_SUBJECT_TO_CHANGE \ + $(GLIB_CFLAGS) \ + $(GTK_CFLAGS) \ + $(LIBGCRYPT_CFLAGS) -TESTING_LIBS = \ +LDADD = \ $(top_builddir)/gcr/libgcr@GCR_VERSION_SUFFIX@.la \ $(top_builddir)/egg/libegg.la \ $(top_builddir)/egg/libegg-entry-buffer.la \ - $(top_builddir)/gck/libgck.la - -TESTING_FLAGS = \ - -DGCR_API_SUBJECT_TO_CHANGE \ - -DGCK_API_SUBJECT_TO_CHANGE - -include $(top_srcdir)/testing/testing.make - -EXTRA_DIST += \ - test-data - -# ------------------------------------------------------------------ - -noinst_PROGRAMS += \ - ui-test-certificate \ - ui-test-key \ - ui-test-unlock-options - -ui_test_certificate_SOURCES = \ - ui-test-certificate.c - -ui_test_certificate_CFLAGS = \ - -DGCR_API_SUBJECT_TO_CHANGE \ - $(GTK_CFLAGS) - -ui_test_certificate_LDADD = \ - $(top_builddir)/gcr/libgcr@GCR_VERSION_SUFFIX@.la \ $(top_builddir)/gck/libgck.la \ $(GTK_LIBS) \ - $(LIBGCRYPT_LIBS) + $(GLIB_LIBS) \ + $(LIBGCRYT_LIBS) -ui_test_unlock_options_SOURCES = \ - ui-test-unlock-options.c +TEST_PROGS = \ + test-certificate \ + test-certificate-chain \ + test-pkcs11-certificate \ + test-simple-certificate \ + test-trust \ + test-parser -ui_test_unlock_options_CFLAGS = \ - -DGCR_API_SUBJECT_TO_CHANGE \ - $(GTK_CFLAGS) +check_PROGRAMS = $(TEST_PROGS) -ui_test_unlock_options_LDADD = \ - $(top_builddir)/gcr/libgcr@GCR_VERSION_SUFFIX@.la \ - $(top_builddir)/gck/libgck.la \ - $(GTK_LIBS) \ - $(LIBGCRYPT_LIBS) +test: $(TEST_PROGS) + SRCDIR='$(srcdir)' gtester -k --verbose ${TEST_PROGS} -ui_test_key_SOURCES = \ - ui-test-key.c +check-local: test -ui_test_key_CFLAGS = \ - -DGCR_API_SUBJECT_TO_CHANGE \ - $(GTK_CFLAGS) +if WITH_TESTS +all-local: $(check_PROGRAMS) +endif -ui_test_key_LDADD = \ - $(top_builddir)/gcr/libgcr@GCR_VERSION_SUFFIX@.la \ - $(top_builddir)/gck/libgck.la \ - $(GTK_LIBS) \ - $(LIBGCRYPT_LIBS) +EXTRA_DIST = \ + test-data + +# ------------------------------------------------------------------ + +noinst_PROGRAMS = \ + frob-certificate \ + frob-key \ + frob-unlock-options diff --git a/gcr/tests/test-data/RSA_Root_Certificate_1.pem b/gcr/tests/files/RSA_Root_Certificate_1.pem index f6cdfcd0..f6cdfcd0 100644 --- a/gcr/tests/test-data/RSA_Root_Certificate_1.pem +++ b/gcr/tests/files/RSA_Root_Certificate_1.pem diff --git a/gcr/tests/test-data/RSA_Security_1024_v3.pem b/gcr/tests/files/RSA_Security_1024_v3.pem index 94e0ad13..94e0ad13 100644 --- a/gcr/tests/test-data/RSA_Security_1024_v3.pem +++ b/gcr/tests/files/RSA_Security_1024_v3.pem diff --git a/gcr/tests/test-data/RSA_Security_2048_v3.pem b/gcr/tests/files/RSA_Security_2048_v3.pem index 86c907eb..86c907eb 100644 --- a/gcr/tests/test-data/RSA_Security_2048_v3.pem +++ b/gcr/tests/files/RSA_Security_2048_v3.pem diff --git a/gcr/tests/test-data/Thawte_Personal_Basic_CA.pem b/gcr/tests/files/Thawte_Personal_Basic_CA.pem index 22c2a8db..22c2a8db 100644 --- a/gcr/tests/test-data/Thawte_Personal_Basic_CA.pem +++ b/gcr/tests/files/Thawte_Personal_Basic_CA.pem diff --git a/gcr/tests/test-data/Thawte_Personal_Freemail_CA.pem b/gcr/tests/files/Thawte_Personal_Freemail_CA.pem index 565a4be1..565a4be1 100644 --- a/gcr/tests/test-data/Thawte_Personal_Freemail_CA.pem +++ b/gcr/tests/files/Thawte_Personal_Freemail_CA.pem diff --git a/gcr/tests/test-data/Thawte_Personal_Premium_CA.pem b/gcr/tests/files/Thawte_Personal_Premium_CA.pem index 688c3ae1..688c3ae1 100644 --- a/gcr/tests/test-data/Thawte_Personal_Premium_CA.pem +++ b/gcr/tests/files/Thawte_Personal_Premium_CA.pem diff --git a/gcr/tests/test-data/Thawte_Premium_Server_CA.pem b/gcr/tests/files/Thawte_Premium_Server_CA.pem index aa37cfc9..aa37cfc9 100644 --- a/gcr/tests/test-data/Thawte_Premium_Server_CA.pem +++ b/gcr/tests/files/Thawte_Premium_Server_CA.pem diff --git a/gcr/tests/test-data/Thawte_Server_CA.pem b/gcr/tests/files/Thawte_Server_CA.pem index ac4e25bf..ac4e25bf 100644 --- a/gcr/tests/test-data/Thawte_Server_CA.pem +++ b/gcr/tests/files/Thawte_Server_CA.pem diff --git a/gcr/tests/test-data/Thawte_Time_Stamping_CA.pem b/gcr/tests/files/Thawte_Time_Stamping_CA.pem index fecbd15e..fecbd15e 100644 --- a/gcr/tests/test-data/Thawte_Time_Stamping_CA.pem +++ b/gcr/tests/files/Thawte_Time_Stamping_CA.pem diff --git a/gcr/tests/test-data/ca-certificates.crt b/gcr/tests/files/ca-certificates.crt index c30335f8..c30335f8 100644 --- a/gcr/tests/test-data/ca-certificates.crt +++ b/gcr/tests/files/ca-certificates.crt diff --git a/gcr/tests/test-data/cacert.org.pem b/gcr/tests/files/cacert.org.pem index e7dfc829..e7dfc829 100644 --- a/gcr/tests/test-data/cacert.org.pem +++ b/gcr/tests/files/cacert.org.pem diff --git a/gcr/tests/test-data/collabora-ca.cer b/gcr/tests/files/collabora-ca.cer Binary files differindex 2842c696..2842c696 100644 --- a/gcr/tests/test-data/collabora-ca.cer +++ b/gcr/tests/files/collabora-ca.cer diff --git a/gcr/tests/test-data/der-certificate-dsa.cer b/gcr/tests/files/der-certificate-dsa.cer Binary files differindex 024f3c1b..024f3c1b 100755 --- a/gcr/tests/test-data/der-certificate-dsa.cer +++ b/gcr/tests/files/der-certificate-dsa.cer diff --git a/gcr/tests/test-data/der-certificate.crt b/gcr/tests/files/der-certificate.crt Binary files differindex 56fa8491..56fa8491 100644 --- a/gcr/tests/test-data/der-certificate.crt +++ b/gcr/tests/files/der-certificate.crt diff --git a/gcr/tests/test-data/der-dsa-1024.key b/gcr/tests/files/der-dsa-1024.key Binary files differindex 61af5251..61af5251 100644 --- a/gcr/tests/test-data/der-dsa-1024.key +++ b/gcr/tests/files/der-dsa-1024.key diff --git a/gcr/tests/test-data/der-pkcs8-PBE-MD5-DES.key b/gcr/tests/files/der-pkcs8-PBE-MD5-DES.key Binary files differindex 71b7d61b..71b7d61b 100644 --- a/gcr/tests/test-data/der-pkcs8-PBE-MD5-DES.key +++ b/gcr/tests/files/der-pkcs8-PBE-MD5-DES.key diff --git a/gcr/tests/test-data/der-pkcs8-PBE-SHA1-3DES.key b/gcr/tests/files/der-pkcs8-PBE-SHA1-3DES.key Binary files differindex 1c37fe10..1c37fe10 100644 --- a/gcr/tests/test-data/der-pkcs8-PBE-SHA1-3DES.key +++ b/gcr/tests/files/der-pkcs8-PBE-SHA1-3DES.key diff --git a/gcr/tests/test-data/der-pkcs8-PBE-SHA1-DES.key b/gcr/tests/files/der-pkcs8-PBE-SHA1-DES.key Binary files differindex 99896139..99896139 100644 --- a/gcr/tests/test-data/der-pkcs8-PBE-SHA1-DES.key +++ b/gcr/tests/files/der-pkcs8-PBE-SHA1-DES.key diff --git a/gcr/tests/test-data/der-pkcs8-PBE-SHA1-RC2-40.key b/gcr/tests/files/der-pkcs8-PBE-SHA1-RC2-40.key Binary files differindex 820926cc..820926cc 100644 --- a/gcr/tests/test-data/der-pkcs8-PBE-SHA1-RC2-40.key +++ b/gcr/tests/files/der-pkcs8-PBE-SHA1-RC2-40.key diff --git a/gcr/tests/test-data/der-pkcs8-PBE-SHA1-RC4-128.key b/gcr/tests/files/der-pkcs8-PBE-SHA1-RC4-128.key Binary files differindex 2888450c..2888450c 100644 --- a/gcr/tests/test-data/der-pkcs8-PBE-SHA1-RC4-128.key +++ b/gcr/tests/files/der-pkcs8-PBE-SHA1-RC4-128.key diff --git a/gcr/tests/test-data/der-pkcs8-dsa.key b/gcr/tests/files/der-pkcs8-dsa.key Binary files differindex 8b61684e..8b61684e 100644 --- a/gcr/tests/test-data/der-pkcs8-dsa.key +++ b/gcr/tests/files/der-pkcs8-dsa.key diff --git a/gcr/tests/test-data/der-pkcs8-encrypted-pkcs5.key b/gcr/tests/files/der-pkcs8-encrypted-pkcs5.key Binary files differindex 68c6b4a5..68c6b4a5 100644 --- a/gcr/tests/test-data/der-pkcs8-encrypted-pkcs5.key +++ b/gcr/tests/files/der-pkcs8-encrypted-pkcs5.key diff --git a/gcr/tests/test-data/der-pkcs8-v2-des.key b/gcr/tests/files/der-pkcs8-v2-des.key Binary files differindex 4cd80348..4cd80348 100644 --- a/gcr/tests/test-data/der-pkcs8-v2-des.key +++ b/gcr/tests/files/der-pkcs8-v2-des.key diff --git a/gcr/tests/test-data/der-pkcs8-v2-des3.key b/gcr/tests/files/der-pkcs8-v2-des3.key Binary files differindex 9e2999c8..9e2999c8 100644 --- a/gcr/tests/test-data/der-pkcs8-v2-des3.key +++ b/gcr/tests/files/der-pkcs8-v2-des3.key diff --git a/gcr/tests/test-data/der-pkcs8.key b/gcr/tests/files/der-pkcs8.key Binary files differindex 16505632..16505632 100644 --- a/gcr/tests/test-data/der-pkcs8.key +++ b/gcr/tests/files/der-pkcs8.key diff --git a/gcr/tests/test-data/der-rsa-1024.key b/gcr/tests/files/der-rsa-1024.key Binary files differindex 878fda5b..878fda5b 100644 --- a/gcr/tests/test-data/der-rsa-1024.key +++ b/gcr/tests/files/der-rsa-1024.key diff --git a/gcr/tests/test-data/dhansak-collabora.cer b/gcr/tests/files/dhansak-collabora.cer Binary files differindex c411e7d6..c411e7d6 100644 --- a/gcr/tests/test-data/dhansak-collabora.cer +++ b/gcr/tests/files/dhansak-collabora.cer diff --git a/gcr/tests/test-data/email.p12 b/gcr/tests/files/email.p12 Binary files differindex d45d0f8d..d45d0f8d 100644 --- a/gcr/tests/test-data/email.p12 +++ b/gcr/tests/files/email.p12 diff --git a/gcr/tests/test-data/pem-dsa-1024.key b/gcr/tests/files/pem-dsa-1024.key index ccb1e7b9..ccb1e7b9 100644 --- a/gcr/tests/test-data/pem-dsa-1024.key +++ b/gcr/tests/files/pem-dsa-1024.key diff --git a/gcr/tests/test-data/pem-pkcs8.key b/gcr/tests/files/pem-pkcs8.key index 1f0d5edb..1f0d5edb 100644 --- a/gcr/tests/test-data/pem-pkcs8.key +++ b/gcr/tests/files/pem-pkcs8.key diff --git a/gcr/tests/test-data/pem-rsa-enc.key b/gcr/tests/files/pem-rsa-enc.key index 65439fe6..65439fe6 100644 --- a/gcr/tests/test-data/pem-rsa-enc.key +++ b/gcr/tests/files/pem-rsa-enc.key diff --git a/gcr/tests/test-data/test-x509-swiss.p7b b/gcr/tests/files/test-x509-swiss.p7b Binary files differindex d45b9e0e..d45b9e0e 100755 --- a/gcr/tests/test-data/test-x509-swiss.p7b +++ b/gcr/tests/files/test-x509-swiss.p7b diff --git a/gcr/tests/test-data/unclient.p12 b/gcr/tests/files/unclient.p12 Binary files differindex 321b4475..321b4475 100644 --- a/gcr/tests/test-data/unclient.p12 +++ b/gcr/tests/files/unclient.p12 diff --git a/gcr/tests/ui-test-certificate.c b/gcr/tests/frob-certificate.c index 2a181ac6..2a181ac6 100644 --- a/gcr/tests/ui-test-certificate.c +++ b/gcr/tests/frob-certificate.c diff --git a/gcr/tests/ui-test-key.c b/gcr/tests/frob-key.c index cd02be6c..cd02be6c 100644 --- a/gcr/tests/ui-test-key.c +++ b/gcr/tests/frob-key.c diff --git a/gcr/tests/frob-selector b/gcr/tests/frob-selector new file mode 100755 index 00000000..310a6bfd --- /dev/null +++ b/gcr/tests/frob-selector @@ -0,0 +1,148 @@ +#! /bin/bash + +# frob-selector - temporary wrapper script for .libs/frob-selector +# Generated by ltmain.sh (GNU libtool) 2.2.6b Debian-2.2.6b-2ubuntu3 +# +# The frob-selector program cannot be directly executed until all the libtool +# libraries that it depends on are installed. +# +# This wrapper script should never be moved out of the build directory. +# If it is, it will not operate correctly. + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +Xsed='/bin/sed -e 1s/^X//' +sed_quote_subst='s/\([`"$\\]\)/\\\1/g' + +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +relink_command="(cd /data/projects/gnome-keyring/gcr/tests; { test -z \"\${LIBRARY_PATH+set}\" || unset LIBRARY_PATH || { LIBRARY_PATH=; export LIBRARY_PATH; }; }; { test -z \"\${COMPILER_PATH+set}\" || unset COMPILER_PATH || { COMPILER_PATH=; export COMPILER_PATH; }; }; { test -z \"\${GCC_EXEC_PREFIX+set}\" || unset GCC_EXEC_PREFIX || { GCC_EXEC_PREFIX=; export GCC_EXEC_PREFIX; }; }; { test -z \"\${LD_RUN_PATH+set}\" || unset LD_RUN_PATH || { LD_RUN_PATH=; export LD_RUN_PATH; }; }; LD_LIBRARY_PATH=/usr/lib/jvm/java-6-openjdk/jre/lib/i386/client:/usr/lib/jvm/java-6-openjdk/jre/lib/i386:/usr/lib/xulrunner-devel-2.0:/usr/lib/xulrunner-devel-2.0; export LD_LIBRARY_PATH; PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games; export PATH; gcc -Wall -Wchar-subscripts -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wcast-align -Wsign-compare -g -O2 -g -O0 -Wall -DG_DISABLE_DEPRECATED -DGDK_PIXBUF_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED -Wno-strict-aliasing -Wno-sign-compare -Werror -o \$progdir/\$file frob-selector.o -pthread ../../gcr/.libs/libgcr-3.so ../../egg/.libs/libegg.a ../../egg/.libs/libegg-entry-buffer.a ../../gck/.libs/libgck.so -L/usr/lib/i386-linux-gnu /usr/lib/libgtk-3.so /usr/lib/libgdk-3.so /usr/lib/i386-linux-gnu/libatk-1.0.so /usr/lib/libcairo-gobject.so /usr/lib/i386-linux-gnu/libgio-2.0.so /usr/lib/i386-linux-gnu/libpangoft2-1.0.so /usr/lib/i386-linux-gnu/libpangocairo-1.0.so -lgdk_pixbuf-2.0 -lm /usr/lib/libcairo.so /usr/lib/i386-linux-gnu/libpango-1.0.so /usr/lib/i386-linux-gnu/libfreetype.so -lfontconfig /usr/lib/i386-linux-gnu/libgobject-2.0.so /usr/lib/i386-linux-gnu/libgmodule-2.0.so /usr/lib/i386-linux-gnu/libgthread-2.0.so -lrt /usr/lib/i386-linux-gnu/libglib-2.0.so -pthread -Wl,-rpath -Wl,/data/projects/gnome-keyring/gcr/.libs -Wl,-rpath -Wl,/data/projects/gnome-keyring/gck/.libs)" + +# This environment variable determines our operation mode. +if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then + # install mode needs the following variables: + generated_by_libtool_version='2.2.6b' + notinst_deplibs=' ../../gcr/libgcr-3.la ../../gck/libgck.la' +else + # When we are sourced in execute mode, $file and $ECHO are already set. + if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then + ECHO="echo" + file="$0" + # Make sure echo works. + if test "X$1" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift + elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t'; then + # Yippee, $ECHO works! + : + else + # Restart under the correct shell, and then maybe $ECHO will work. + exec /bin/bash "$0" --no-reexec ${1+"$@"} + fi + fi + + # Find the directory that this script lives in. + thisdir=`$ECHO "X$file" | $Xsed -e 's%/[^/]*$%%'` + test "x$thisdir" = "x$file" && thisdir=. + + # Follow symbolic links until we get to the real thisdir. + file=`ls -ld "$file" | /bin/sed -n 's/.*-> //p'` + while test -n "$file"; do + destdir=`$ECHO "X$file" | $Xsed -e 's%/[^/]*$%%'` + + # If there was a directory component, then change thisdir. + if test "x$destdir" != "x$file"; then + case "$destdir" in + [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;; + *) thisdir="$thisdir/$destdir" ;; + esac + fi + + file=`$ECHO "X$file" | $Xsed -e 's%^.*/%%'` + file=`ls -ld "$thisdir/$file" | /bin/sed -n 's/.*-> //p'` + done + + + # Usually 'no', except on cygwin/mingw when embedded into + # the cwrapper. + WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no + if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then + # special case for '.' + if test "$thisdir" = "."; then + thisdir=`pwd` + fi + # remove .libs from thisdir + case "$thisdir" in + *[\\/].libs ) thisdir=`$ECHO "X$thisdir" | $Xsed -e 's%[\\/][^\\/]*$%%'` ;; + .libs ) thisdir=. ;; + esac + fi + + # Try to get the absolute directory name. + absdir=`cd "$thisdir" && pwd` + test -n "$absdir" && thisdir="$absdir" + + program=lt-'frob-selector' + progdir="$thisdir/.libs" + + if test ! -f "$progdir/$program" || + { file=`ls -1dt "$progdir/$program" "$progdir/../$program" 2>/dev/null | /bin/sed 1q`; \ + test "X$file" != "X$progdir/$program"; }; then + + file="$$-$program" + + if test ! -d "$progdir"; then + mkdir "$progdir" + else + rm -f "$progdir/$file" + fi + + # relink executable if necessary + if test -n "$relink_command"; then + if relink_command_output=`eval $relink_command 2>&1`; then : + else + echo "$relink_command_output" >&2 + rm -f "$progdir/$file" + exit 1 + fi + fi + + mv -f "$progdir/$file" "$progdir/$program" 2>/dev/null || + { rm -f "$progdir/$program"; + mv -f "$progdir/$file" "$progdir/$program"; } + rm -f "$progdir/$file" + fi + + if test -f "$progdir/$program"; then + if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then + # Run the actual program with our arguments. + + exec "$progdir/$program" ${1+"$@"} + + $ECHO "$0: cannot exec $program $*" 1>&2 + exit 1 + fi + else + # The program doesn't exist. + $ECHO "$0: error: \`$progdir/$program' does not exist" 1>&2 + $ECHO "This script is just a wrapper for $program." 1>&2 + echo "See the libtool documentation for more information." 1>&2 + exit 1 + fi +fi diff --git a/gcr/tests/ui-test-unlock-options.c b/gcr/tests/frob-unlock-options.c index 96b9ff53..96b9ff53 100644 --- a/gcr/tests/ui-test-unlock-options.c +++ b/gcr/tests/frob-unlock-options.c diff --git a/gcr/tests/test-certificate-chain.c b/gcr/tests/test-certificate-chain.c index 92284ec5..16562629 100644 --- a/gcr/tests/test-certificate-chain.c +++ b/gcr/tests/test-certificate-chain.c @@ -1,13 +1,34 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* + Copyright (C) 2010 Collabora Ltd -#include "config.h" -#include "test-suite.h" + The Gnome Keyring Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. -#include "egg/egg-asn1x.h" -#include "egg/egg-asn1-defs.h" + The Gnome Keyring Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Author: Stef Walter <stefw@collabora.co.uk> +*/ + +#include "config.h" #include "gcr/gcr.h" #include "gcr/gcr-internal.h" +#include "egg/egg-asn1x.h" +#include "egg/egg-asn1-defs.h" +#include "egg/egg-testing.h" + #include "gck/gck-mock.h" #include "gck/gck-test.h" @@ -16,6 +37,7 @@ #include <glib.h> +#include <errno.h> #include <string.h> /* --------------------------------------------------------------------------- @@ -42,7 +64,8 @@ typedef struct _MockCertificateClass { static void mock_certificate_iface (GcrCertificateIface *iface); G_DEFINE_TYPE_WITH_CODE (MockCertificate, mock_certificate, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (GCR_TYPE_CERTIFICATE, mock_certificate_iface)); + G_IMPLEMENT_INTERFACE (GCR_TYPE_CERTIFICATE, mock_certificate_iface); +); static void mock_certificate_init (MockCertificate *self) @@ -95,16 +118,19 @@ mock_certificate_new (gconstpointer data, gsize n_data) * TESTS */ -static GcrCertificate *cert_self = NULL; -static GcrCertificate *cert_ca = NULL; -static GcrCertificate *cert_signed = NULL; -static CK_FUNCTION_LIST funcs; +typedef struct { + GcrCertificate *cert_self; + GcrCertificate *cert_ca; + GcrCertificate *cert_signed; + CK_FUNCTION_LIST funcs; +} Test; -TESTING_SETUP (certificate_chain) +static void +setup (Test *test, gconstpointer unused) { GList *modules = NULL; CK_FUNCTION_LIST_PTR f; - guchar *contents; + gchar *contents; gsize n_contents; const gchar *uris[2]; CK_RV rv; @@ -112,14 +138,14 @@ TESTING_SETUP (certificate_chain) rv = gck_mock_C_GetFunctionList (&f); gck_assert_cmprv (rv, ==, CKR_OK); - memcpy (&funcs, f, sizeof (funcs)); + memcpy (&test->funcs, f, sizeof (test->funcs)); /* Open a session */ - rv = (funcs.C_Initialize) (NULL); + rv = (test->funcs.C_Initialize) (NULL); gck_assert_cmprv (rv, ==, CKR_OK); g_assert (!modules); - module = gck_module_new (&funcs, 0); + module = gck_module_new (&test->funcs, 0); modules = g_list_prepend (modules, module); gcr_pkcs11_set_modules (modules); uris[0] = GCK_MOCK_SLOT_ONE_URI; @@ -129,18 +155,21 @@ TESTING_SETUP (certificate_chain) gck_list_unref_free (modules); /* A self-signed certificate */ - contents = testing_data_read ("der-certificate.crt", &n_contents); - cert_self = gcr_simple_certificate_new (contents, n_contents); + if (!g_file_get_contents ("files/der-certificate.crt", &contents, &n_contents, NULL)) + g_assert_not_reached (); + test->cert_self = gcr_simple_certificate_new (contents, n_contents); g_free (contents); /* A signed certificate */ - contents = testing_data_read ("dhansak-collabora.cer", &n_contents); - cert_signed = mock_certificate_new (contents, n_contents); + if (!g_file_get_contents ("files/dhansak-collabora.cer", &contents, &n_contents, NULL)) + g_assert_not_reached (); + test->cert_signed = mock_certificate_new (contents, n_contents); g_free (contents); /* The signer for the above certificate */ - contents = testing_data_read ("collabora-ca.cer", &n_contents); - cert_ca = mock_certificate_new (contents, n_contents); + if (!g_file_get_contents ("files/collabora-ca.cer", &contents, &n_contents, NULL)) + g_assert_not_reached (); + test->cert_ca = mock_certificate_new (contents, n_contents); g_free (contents); } @@ -208,24 +237,21 @@ add_pinned_to_module (GcrCertificate *certificate, const gchar *purpose, const g gck_mock_module_take_object (attrs); } -TESTING_TEARDOWN (certificate_chain) +static void +teardown (Test *test, gconstpointer unused) { CK_RV rv; - g_object_unref (cert_self); - cert_self = NULL; - - g_object_unref (cert_signed); - cert_signed = NULL; - - g_object_unref (cert_ca); - cert_ca = NULL; + g_object_unref (test->cert_self); + g_object_unref (test->cert_signed); + g_object_unref (test->cert_ca); - rv = (funcs.C_Finalize) (NULL); + rv = (test->funcs.C_Finalize) (NULL); gck_assert_cmprv (rv, ==, CKR_OK); } -TESTING_TEST (certificate_chain_new) +static void +test_new (Test *test, gconstpointer unused) { GcrCertificateChain *chain; @@ -240,15 +266,16 @@ TESTING_TEST (certificate_chain_new) g_object_unref (chain); } -TESTING_TEST (certificate_chain_new_with_cert) +static void +test_new_with_cert (Test *test, gconstpointer unused) { GcrCertificateChain *chain; GcrCertificate *check; guint status, length; chain = gcr_certificate_chain_new (); - gcr_certificate_chain_add (chain, cert_signed); - gcr_certificate_chain_add (chain, cert_ca); + gcr_certificate_chain_add (chain, test->cert_signed); + gcr_certificate_chain_add (chain, test->cert_ca); g_assert_cmpuint (gcr_certificate_chain_get_status (chain), ==, GCR_CERTIFICATE_CHAIN_UNKNOWN); @@ -261,19 +288,20 @@ TESTING_TEST (certificate_chain_new_with_cert) g_assert_cmpuint (length, ==, 2); check = gcr_certificate_chain_get_certificate (chain, 1); - g_assert (check == cert_ca); + g_assert (check == test->cert_ca); /* Not yet completed */ check = gcr_certificate_chain_get_anchor (chain); g_assert (check == NULL); check = gcr_certificate_chain_get_endpoint (chain); - g_assert (check == cert_signed); + g_assert (check == test->cert_signed); g_object_unref (chain); } -TESTING_TEST (certificate_chain_selfsigned) +static void +test_selfsigned (Test *test, gconstpointer unused) { GcrCertificateChain *chain; GError *error = NULL; @@ -281,7 +309,7 @@ TESTING_TEST (certificate_chain_selfsigned) chain = gcr_certificate_chain_new (); /* Add a self-signed certificate */ - gcr_certificate_chain_add (chain, cert_self); + gcr_certificate_chain_add (chain, test->cert_self); if (!gcr_certificate_chain_build (chain, GCR_PURPOSE_CLIENT_AUTH, NULL, 0, NULL, &error)) @@ -294,7 +322,8 @@ TESTING_TEST (certificate_chain_selfsigned) g_object_unref (chain); } -TESTING_TEST (certificate_chain_incomplete) +static void +test_incomplete (Test *test, gconstpointer unused) { GcrCertificateChain *chain; GError *error = NULL; @@ -302,7 +331,7 @@ TESTING_TEST (certificate_chain_incomplete) chain = gcr_certificate_chain_new (); /* Add a signed certificate */ - gcr_certificate_chain_add (chain, cert_signed); + gcr_certificate_chain_add (chain, test->cert_signed); if (!gcr_certificate_chain_build (chain, GCR_PURPOSE_CLIENT_AUTH, NULL, 0, NULL, &error)) @@ -315,7 +344,8 @@ TESTING_TEST (certificate_chain_incomplete) g_object_unref (chain); } -TESTING_TEST (certificate_chain_empty) +static void +test_empty (Test *test, gconstpointer unused) { GcrCertificateChain *chain; GError *error = NULL; @@ -335,7 +365,8 @@ TESTING_TEST (certificate_chain_empty) g_object_unref (chain); } -TESTING_TEST (certificate_chain_trim_extras) +static void +test_trim_extras (Test *test, gconstpointer unused) { GcrCertificateChain *chain; GError *error = NULL; @@ -343,8 +374,8 @@ TESTING_TEST (certificate_chain_trim_extras) chain = gcr_certificate_chain_new (); /* Add two unrelated certificates */ - gcr_certificate_chain_add (chain, cert_self); - gcr_certificate_chain_add (chain, cert_signed); + gcr_certificate_chain_add (chain, test->cert_self); + gcr_certificate_chain_add (chain, test->cert_signed); g_assert_cmpuint (gcr_certificate_chain_get_length (chain), ==, 2); @@ -365,10 +396,11 @@ fetch_async_result (GObject *source, GAsyncResult *result, gpointer user_data) { *((GAsyncResult**)user_data) = result; g_object_ref (result); - testing_wait_stop (); + egg_test_wait_stop (); } -TESTING_TEST (certificate_chain_complete_async) +static void +test_complete_async (Test *test, gconstpointer unused) { GcrCertificateChain *chain; GError *error = NULL; @@ -377,13 +409,13 @@ TESTING_TEST (certificate_chain_complete_async) chain = gcr_certificate_chain_new (); /* Add a whole bunch of certificates */ - gcr_certificate_chain_add (chain, cert_signed); - gcr_certificate_chain_add (chain, cert_ca); - gcr_certificate_chain_add (chain, cert_self); + gcr_certificate_chain_add (chain, test->cert_signed); + gcr_certificate_chain_add (chain, test->cert_ca); + gcr_certificate_chain_add (chain, test->cert_self); gcr_certificate_chain_build_async (chain, GCR_PURPOSE_CLIENT_AUTH, NULL, 0, NULL, fetch_async_result, &result); - testing_wait_until (500); + egg_test_wait_until (500); if (!gcr_certificate_chain_build_finish (chain, result, &error)) g_assert_not_reached (); g_assert_no_error (error); @@ -396,7 +428,8 @@ TESTING_TEST (certificate_chain_complete_async) g_object_unref (chain); } -TESTING_TEST (certificate_chain_with_anchor) +static void +test_with_anchor (Test *test, gconstpointer unused) { GcrCertificateChain *chain; GError *error = NULL; @@ -404,9 +437,9 @@ TESTING_TEST (certificate_chain_with_anchor) chain = gcr_certificate_chain_new (); /* Two certificates in chain with ca trust anchor */ - gcr_certificate_chain_add (chain, cert_signed); - gcr_certificate_chain_add (chain, cert_ca); - add_anchor_to_module (cert_ca, GCR_PURPOSE_CLIENT_AUTH); + gcr_certificate_chain_add (chain, test->cert_signed); + gcr_certificate_chain_add (chain, test->cert_ca); + add_anchor_to_module (test->cert_ca, GCR_PURPOSE_CLIENT_AUTH); g_assert_cmpuint (gcr_certificate_chain_get_length (chain), ==, 2); @@ -418,12 +451,13 @@ TESTING_TEST (certificate_chain_with_anchor) g_assert_cmpuint (gcr_certificate_chain_get_status (chain), ==, GCR_CERTIFICATE_CHAIN_ANCHORED); g_assert_cmpuint (gcr_certificate_chain_get_length (chain), ==, 2); - g_assert (gcr_certificate_chain_get_anchor (chain) == cert_ca); + g_assert (gcr_certificate_chain_get_anchor (chain) == test->cert_ca); g_object_unref (chain); } -TESTING_TEST (certificate_chain_with_anchor_and_lookup_ca) +static void +test_with_anchor_and_lookup_ca (Test *test, gconstpointer unused) { GcrCertificateChain *chain; GError *error = NULL; @@ -431,9 +465,9 @@ TESTING_TEST (certificate_chain_with_anchor_and_lookup_ca) chain = gcr_certificate_chain_new (); /* One signed certificate, with CA in pkcs11, and trust anchor */ - gcr_certificate_chain_add (chain, cert_signed); - add_certificate_to_module (cert_ca); - add_anchor_to_module (cert_ca, GCR_PURPOSE_CLIENT_AUTH); + gcr_certificate_chain_add (chain, test->cert_signed); + add_certificate_to_module (test->cert_ca); + add_anchor_to_module (test->cert_ca, GCR_PURPOSE_CLIENT_AUTH); g_assert_cmpuint (gcr_certificate_chain_get_length (chain), ==, 1); @@ -450,7 +484,8 @@ TESTING_TEST (certificate_chain_with_anchor_and_lookup_ca) g_object_unref (chain); } -TESTING_TEST (certificate_chain_with_pinned) +static void +test_with_pinned (Test *test, gconstpointer unused) { GcrCertificateChain *chain; GError *error = NULL; @@ -458,9 +493,9 @@ TESTING_TEST (certificate_chain_with_pinned) chain = gcr_certificate_chain_new (); /* One certificate, and add CA to pkcs11 */ - gcr_certificate_chain_add (chain, cert_signed); - gcr_certificate_chain_add (chain, cert_ca); - add_pinned_to_module (cert_signed, GCR_PURPOSE_CLIENT_AUTH, "pinned.example.com"); + gcr_certificate_chain_add (chain, test->cert_signed); + gcr_certificate_chain_add (chain, test->cert_ca); + add_pinned_to_module (test->cert_signed, GCR_PURPOSE_CLIENT_AUTH, "pinned.example.com"); g_assert_cmpuint (gcr_certificate_chain_get_length (chain), ==, 2); @@ -478,7 +513,8 @@ TESTING_TEST (certificate_chain_with_pinned) g_object_unref (chain); } -TESTING_TEST (certificate_chain_without_lookups) +static void +test_without_lookups (Test *test, gconstpointer unused) { GcrCertificateChain *chain; GError *error = NULL; @@ -486,8 +522,8 @@ TESTING_TEST (certificate_chain_without_lookups) chain = gcr_certificate_chain_new (); /* One certificate, and add CA to pkcs11 */ - gcr_certificate_chain_add (chain, cert_signed); - add_certificate_to_module (cert_ca); + gcr_certificate_chain_add (chain, test->cert_signed); + add_certificate_to_module (test->cert_ca); g_assert_cmpuint (gcr_certificate_chain_get_length (chain), ==, 1); @@ -506,19 +542,20 @@ TESTING_TEST (certificate_chain_without_lookups) g_object_unref (chain); } -TESTING_TEST (certificate_chain_with_lookup_error) +static void +test_with_lookup_error (Test *test, gconstpointer unused) { GcrCertificateChain *chain; GError *error = NULL; /* Make the lookup fail */ - funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue; + test->funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue; chain = gcr_certificate_chain_new (); /* Two certificates in chain with ca trust anchor */ - gcr_certificate_chain_add (chain, cert_signed); - add_certificate_to_module (cert_ca); + gcr_certificate_chain_add (chain, test->cert_signed); + add_certificate_to_module (test->cert_ca); g_assert_cmpuint (gcr_certificate_chain_get_length (chain), ==, 1); @@ -534,19 +571,20 @@ TESTING_TEST (certificate_chain_with_lookup_error) g_object_unref (chain); } -TESTING_TEST (certificate_chain_with_anchor_error) +static void +test_with_anchor_error (Test *test, gconstpointer unused) { GcrCertificateChain *chain; GError *error = NULL; /* Make the lookup fail */ - funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue; + test->funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue; chain = gcr_certificate_chain_new (); /* Two certificates in chain with ca trust anchor */ - gcr_certificate_chain_add (chain, cert_signed); - add_certificate_to_module (cert_ca); + gcr_certificate_chain_add (chain, test->cert_signed); + add_certificate_to_module (test->cert_ca); if (gcr_certificate_chain_build (chain, GCR_PURPOSE_CLIENT_AUTH, NULL, 0, NULL, &error)) @@ -560,24 +598,25 @@ TESTING_TEST (certificate_chain_with_anchor_error) g_object_unref (chain); } -TESTING_TEST (certificate_chain_with_anchor_error_async) +static void +test_with_anchor_error_async (Test *test, gconstpointer unused) { GcrCertificateChain *chain; GError *error = NULL; GAsyncResult *result; /* Make the lookup fail */ - funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue; + test->funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue; chain = gcr_certificate_chain_new (); /* Two certificates in chain with ca trust anchor */ - gcr_certificate_chain_add (chain, cert_signed); - add_certificate_to_module (cert_ca); + gcr_certificate_chain_add (chain, test->cert_signed); + add_certificate_to_module (test->cert_ca); gcr_certificate_chain_build_async (chain, GCR_PURPOSE_CLIENT_AUTH, NULL, 0, NULL, fetch_async_result, &result); - testing_wait_until (500); + egg_test_wait_until (500); if (gcr_certificate_chain_build_finish (chain, result, &error)) g_assert_not_reached (); g_assert_error (error, GCK_ERROR, CKR_FUNCTION_FAILED); @@ -589,3 +628,33 @@ TESTING_TEST (certificate_chain_with_anchor_error_async) g_object_unref (chain); } + +int +main (int argc, char **argv) +{ + const gchar *srcdir; + + g_type_init (); + g_test_init (&argc, &argv, NULL); + + srcdir = g_getenv ("SRCDIR"); + if (srcdir && chdir (srcdir) < 0) + g_error ("couldn't change directory to: %s: %s", srcdir, g_strerror (errno)); + + g_test_add ("/gcr/certificate-chain/new", Test, NULL, setup, test_new, teardown); + g_test_add ("/gcr/certificate-chain/new_with_cert", Test, NULL, setup, test_new_with_cert, teardown); + g_test_add ("/gcr/certificate-chain/selfsigned", Test, NULL, setup, test_selfsigned, teardown); + g_test_add ("/gcr/certificate-chain/incomplete", Test, NULL, setup, test_incomplete, teardown); + g_test_add ("/gcr/certificate-chain/empty", Test, NULL, setup, test_empty, teardown); + g_test_add ("/gcr/certificate-chain/trim_extras", Test, NULL, setup, test_trim_extras, teardown); + g_test_add ("/gcr/certificate-chain/complete_async", Test, NULL, setup, test_complete_async, teardown); + g_test_add ("/gcr/certificate-chain/with_anchor", Test, NULL, setup, test_with_anchor, teardown); + g_test_add ("/gcr/certificate-chain/with_anchor_and_lookup_ca", Test, NULL, setup, test_with_anchor_and_lookup_ca, teardown); + g_test_add ("/gcr/certificate-chain/with_pinned", Test, NULL, setup, test_with_pinned, teardown); + g_test_add ("/gcr/certificate-chain/without_lookups", Test, NULL, setup, test_without_lookups, teardown); + g_test_add ("/gcr/certificate-chain/with_lookup_error", Test, NULL, setup, test_with_lookup_error, teardown); + g_test_add ("/gcr/certificate-chain/with_anchor_error", Test, NULL, setup, test_with_anchor_error, teardown); + g_test_add ("/gcr/certificate-chain/with_anchor_error_async", Test, NULL, setup, test_with_anchor_error_async, teardown); + + return egg_tests_run_in_thread_with_loop (); +} diff --git a/gcr/tests/test-certificate.c b/gcr/tests/test-certificate.c index ec84c2fd..89d17411 100644 --- a/gcr/tests/test-certificate.c +++ b/gcr/tests/test-certificate.c @@ -1,144 +1,180 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* + Copyright (C) 2010 Collabora Ltd + + The Gnome Keyring Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Keyring Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Author: Stef Walter <stefw@collabora.co.uk> +*/ #include "config.h" -#include "test-suite.h" #include "gcr/gcr.h" #include "gcr/gcr-internal.h" +#include "egg/egg-testing.h" + #include <glib.h> +#include <errno.h> #include <string.h> -static GcrCertificate *certificate = NULL; -static GcrCertificate *dsa_cert = NULL; -static GcrCertificate *dhansak_cert = NULL; +typedef struct { + GcrCertificate *certificate; + GcrCertificate *dsa_cert; + GcrCertificate *dhansak_cert; +} Test; -TESTING_SETUP(certificate) +static void +setup (Test *test, gconstpointer unused) { - guchar *contents; + gchar *contents; gsize n_contents; - contents = testing_data_read ("der-certificate.crt", &n_contents); - certificate = gcr_simple_certificate_new (contents, n_contents); - g_assert (certificate); + if (!g_file_get_contents ("files/der-certificate.crt", &contents, &n_contents, NULL)) + g_assert_not_reached (); + test->certificate = gcr_simple_certificate_new (contents, n_contents); + g_assert (test->certificate); g_free (contents); - contents = testing_data_read ("der-certificate-dsa.cer", &n_contents); - dsa_cert = gcr_simple_certificate_new (contents, n_contents); - g_assert (dsa_cert); + if (!g_file_get_contents ("files/der-certificate-dsa.cer", &contents, &n_contents, NULL)) + g_assert_not_reached (); + test->dsa_cert = gcr_simple_certificate_new (contents, n_contents); + g_assert (test->dsa_cert); g_free (contents); - contents = testing_data_read ("dhansak-collabora.cer", &n_contents); - dhansak_cert = gcr_simple_certificate_new (contents, n_contents); - g_assert (certificate); + if (!g_file_get_contents ("files/dhansak-collabora.cer", &contents, &n_contents, NULL)) + g_assert_not_reached (); + test->dhansak_cert = gcr_simple_certificate_new (contents, n_contents); + g_assert (test->certificate); g_free (contents); } -TESTING_TEARDOWN(certificate) +static void +teardown (Test *test, gconstpointer unused) { - g_object_unref (certificate); - certificate = NULL; - g_object_unref (dsa_cert); - dsa_cert = NULL; - g_object_unref (dhansak_cert); - dhansak_cert = NULL; + g_object_unref (test->certificate); + g_object_unref (test->dsa_cert); + g_object_unref (test->dhansak_cert); } -TESTING_TEST(issuer_cn) +static void +test_issuer_cn (Test *test, gconstpointer unused) { - gchar *cn = gcr_certificate_get_issuer_cn (certificate); + gchar *cn = gcr_certificate_get_issuer_cn (test->certificate); g_assert (cn); g_assert_cmpstr (cn, ==, "http://www.valicert.com/"); g_free (cn); } -TESTING_TEST(issuer_dn) +static void +test_issuer_dn (Test *test, gconstpointer unused) { - gchar *dn = gcr_certificate_get_issuer_dn (certificate); + gchar *dn = gcr_certificate_get_issuer_dn (test->certificate); g_assert (dn); g_assert_cmpstr (dn, ==, "L=ValiCert Validation Network, O=ValiCert, Inc., OU=ValiCert Class 3 Policy Validation Authority, CN=http://www.valicert.com/, EMAIL=info@valicert.com"); g_free (dn); } -TESTING_TEST(issuer_part) +static void +test_issuer_part (Test *test, gconstpointer unused) { - gchar *part = gcr_certificate_get_issuer_part (certificate, "l"); + gchar *part = gcr_certificate_get_issuer_part (test->certificate, "l"); g_assert (part); g_assert_cmpstr (part, ==, "ValiCert Validation Network"); g_free (part); } -TESTING_TEST(issuer_raw) +static void +test_issuer_raw (Test *test, gconstpointer unused) { gpointer der; gsize n_der; - der = gcr_certificate_get_issuer_raw (certificate, &n_der); + der = gcr_certificate_get_issuer_raw (test->certificate, &n_der); g_assert (der); - g_assert_cmpsize (n_der, ==, 190); + egg_assert_cmpsize (n_der, ==, 190); g_free (der); } -TESTING_TEST(subject_cn) +static void +test_subject_cn (Test *test, gconstpointer unused) { - gchar *cn = gcr_certificate_get_subject_cn (certificate); + gchar *cn = gcr_certificate_get_subject_cn (test->certificate); g_assert (cn); g_assert_cmpstr (cn, ==, "http://www.valicert.com/"); g_free (cn); - cn = gcr_certificate_get_subject_cn (dhansak_cert); + cn = gcr_certificate_get_subject_cn (test->dhansak_cert); g_assert (cn); g_assert_cmpstr (cn, ==, "dhansak.collabora.co.uk"); g_free (cn); } -TESTING_TEST(subject_dn) +static void +test_subject_dn (Test *test, gconstpointer unused) { - gchar *dn = gcr_certificate_get_subject_dn (certificate); + gchar *dn = gcr_certificate_get_subject_dn (test->certificate); g_assert (dn); g_assert_cmpstr (dn, ==, "L=ValiCert Validation Network, O=ValiCert, Inc., OU=ValiCert Class 3 Policy Validation Authority, CN=http://www.valicert.com/, EMAIL=info@valicert.com"); g_free (dn); - dn = gcr_certificate_get_subject_dn (dhansak_cert); + dn = gcr_certificate_get_subject_dn (test->dhansak_cert); g_assert (dn); g_assert_cmpstr (dn, ==, "CN=dhansak.collabora.co.uk, EMAIL=sysadmin@collabora.co.uk"); g_free (dn); } -TESTING_TEST(subject_part) +static void +test_subject_part (Test *test, gconstpointer unused) { - gchar *part = gcr_certificate_get_subject_part (certificate, "OU"); + gchar *part = gcr_certificate_get_subject_part (test->certificate, "OU"); g_assert (part); g_assert_cmpstr (part, ==, "ValiCert Class 3 Policy Validation Authority"); g_free (part); - part = gcr_certificate_get_subject_part (dhansak_cert, "EMAIL"); + part = gcr_certificate_get_subject_part (test->dhansak_cert, "EMAIL"); g_assert (part); g_assert_cmpstr (part, ==, "sysadmin@collabora.co.uk"); g_free (part); } -TESTING_TEST(subject_raw) +static void +test_subject_raw (Test *test, gconstpointer unused) { gpointer der; gsize n_der; - der = gcr_certificate_get_subject_raw (certificate, &n_der); + der = gcr_certificate_get_subject_raw (test->certificate, &n_der); g_assert (der); - g_assert_cmpsize (n_der, ==, 190); + egg_assert_cmpsize (n_der, ==, 190); g_free (der); - der = gcr_certificate_get_subject_raw (dhansak_cert, &n_der); + der = gcr_certificate_get_subject_raw (test->dhansak_cert, &n_der); g_assert (der); - g_assert_cmpsize (n_der, ==, 77); + egg_assert_cmpsize (n_der, ==, 77); g_free (der); } -TESTING_TEST(issued_date) +static void +test_issued_date (Test *test, gconstpointer unused) { - GDate *date = gcr_certificate_get_issued_date (certificate); + GDate *date = gcr_certificate_get_issued_date (test->certificate); g_assert (date); g_assert_cmpuint (g_date_get_year (date), ==, 1999); g_assert_cmpuint (g_date_get_month (date), ==, 6); @@ -146,9 +182,10 @@ TESTING_TEST(issued_date) g_date_free (date); } -TESTING_TEST(expiry_date) +static void +test_expiry_date (Test *test, gconstpointer unused) { - GDate *date = gcr_certificate_get_expiry_date (certificate); + GDate *date = gcr_certificate_get_expiry_date (test->certificate); g_assert (date); g_assert_cmpuint (g_date_get_year (date), ==, 2019); g_assert_cmpuint (g_date_get_month (date), ==, 6); @@ -156,56 +193,92 @@ TESTING_TEST(expiry_date) g_date_free (date); } -TESTING_TEST(serial_number) +static void +test_serial_number (Test *test, gconstpointer unused) { gsize n_serial; guchar *serial; gchar *hex; - serial = gcr_certificate_get_serial_number (certificate, &n_serial); + serial = gcr_certificate_get_serial_number (test->certificate, &n_serial); g_assert (serial); g_assert_cmpuint (n_serial, ==, 1); g_assert (memcmp (serial, "\1", n_serial) == 0); g_free (serial); - hex = gcr_certificate_get_serial_number_hex (certificate); + hex = gcr_certificate_get_serial_number_hex (test->certificate); g_assert (hex); g_assert_cmpstr (hex, ==, "01"); g_free (hex); } -TESTING_TEST(fingerprint) +static void +test_fingerprint (Test *test, gconstpointer unused) { gsize n_print; - guchar *print = gcr_certificate_get_fingerprint (certificate, G_CHECKSUM_MD5, &n_print); + guchar *print = gcr_certificate_get_fingerprint (test->certificate, G_CHECKSUM_MD5, &n_print); g_assert (print); g_assert_cmpuint (n_print, ==, g_checksum_type_get_length (G_CHECKSUM_MD5)); g_assert (memcmp (print, "\xa2\x6f\x53\xb7\xee\x40\xdb\x4a\x68\xe7\xfa\x18\xd9\x10\x4b\x72", n_print) == 0); g_free (print); } -TESTING_TEST(fingerprint_hex) +static void +test_fingerprint_hex (Test *test, gconstpointer unused) { - gchar *print = gcr_certificate_get_fingerprint_hex (certificate, G_CHECKSUM_MD5); + gchar *print = gcr_certificate_get_fingerprint_hex (test->certificate, G_CHECKSUM_MD5); g_assert (print); g_assert_cmpstr (print, ==, "A2 6F 53 B7 EE 40 DB 4A 68 E7 FA 18 D9 10 4B 72"); g_free (print); } -TESTING_TEST (certificate_key_size) +static void +test_certificate_key_size (Test *test, gconstpointer unused) { - guint key_size = gcr_certificate_get_key_size (certificate); + guint key_size = gcr_certificate_get_key_size (test->certificate); g_assert_cmpuint (key_size, ==, 1024); - key_size = gcr_certificate_get_key_size (dsa_cert); + key_size = gcr_certificate_get_key_size (test->dsa_cert); g_assert_cmpuint (key_size, ==, 1024); } -TESTING_TEST (certificate_is_issuer) +static void +test_certificate_is_issuer (Test *test, gconstpointer unused) { - gboolean ret = gcr_certificate_is_issuer (certificate, certificate); + gboolean ret = gcr_certificate_is_issuer (test->certificate, test->certificate); g_assert (ret == TRUE); - ret = gcr_certificate_is_issuer (certificate, dsa_cert); + ret = gcr_certificate_is_issuer (test->certificate, test->dsa_cert); g_assert (ret == FALSE); } + +int +main (int argc, char **argv) +{ + const gchar *srcdir; + + g_type_init (); + g_test_init (&argc, &argv, NULL); + + srcdir = g_getenv ("SRCDIR"); + if (srcdir && chdir (srcdir) < 0) + g_error ("couldn't change directory to: %s: %s", srcdir, g_strerror (errno)); + + g_test_add ("/gcr/certificate/issuer_cn", Test, NULL, setup, test_issuer_cn, teardown); + g_test_add ("/gcr/certificate/issuer_dn", Test, NULL, setup, test_issuer_dn, teardown); + g_test_add ("/gcr/certificate/issuer_part", Test, NULL, setup, test_issuer_part, teardown); + g_test_add ("/gcr/certificate/issuer_raw", Test, NULL, setup, test_issuer_raw, teardown); + g_test_add ("/gcr/certificate/subject_cn", Test, NULL, setup, test_subject_cn, teardown); + g_test_add ("/gcr/certificate/subject_dn", Test, NULL, setup, test_subject_dn, teardown); + g_test_add ("/gcr/certificate/subject_part", Test, NULL, setup, test_subject_part, teardown); + g_test_add ("/gcr/certificate/subject_raw", Test, NULL, setup, test_subject_raw, teardown); + g_test_add ("/gcr/certificate/issued_date", Test, NULL, setup, test_issued_date, teardown); + g_test_add ("/gcr/certificate/expiry_date", Test, NULL, setup, test_expiry_date, teardown); + g_test_add ("/gcr/certificate/serial_number", Test, NULL, setup, test_serial_number, teardown); + g_test_add ("/gcr/certificate/fingerprint", Test, NULL, setup, test_fingerprint, teardown); + g_test_add ("/gcr/certificate/fingerprint_hex", Test, NULL, setup, test_fingerprint_hex, teardown); + g_test_add ("/gcr/certificate/certificate_key_size", Test, NULL, setup, test_certificate_key_size, teardown); + g_test_add ("/gcr/certificate/certificate_is_issuer", Test, NULL, setup, test_certificate_is_issuer, teardown); + + return g_test_run (); +} diff --git a/gcr/tests/unit-test-parser.c b/gcr/tests/test-parser.c index b8bfd88b..ae2c466b 100644 --- a/gcr/tests/unit-test-parser.c +++ b/gcr/tests/test-parser.c @@ -23,8 +23,6 @@ #include "config.h" -#include "test-suite.h" - #include "egg/egg-error.h" #include "egg/egg-secure-memory.h" @@ -36,25 +34,28 @@ #include <glib.h> #include <gcrypt.h> +#include <errno.h> #include <stdlib.h> #include <stdio.h> #include <string.h> -/* +/* * Each test looks like (on one line): * void unit_test_xxxxx (CuTest* cu) - * + * * Each setup looks like (on one line): * void unit_setup_xxxxx (void); - * + * * Each teardown looks like (on one line): * void unit_teardown_xxxxx (void); - * + * * Tests be run in the order specified here. */ -static GcrParser *parser = NULL; -static const gchar* filedesc = NULL; +typedef struct { + GcrParser *parser; + gchar* filedesc; +} Test; static void parsed_item (GcrParser *par, gpointer user_data) @@ -62,59 +63,62 @@ parsed_item (GcrParser *par, gpointer user_data) GckAttributes *attrs; const gchar *description; const gchar *label; - + Test *test = user_data; + g_assert (GCR_IS_PARSER (par)); - g_assert (par == parser); - g_assert (par == user_data); - - attrs = gcr_parser_get_parsed_attributes (parser); - description = gcr_parser_get_parsed_description (parser); - label = gcr_parser_get_parsed_label (parser); - - g_print ("parsed %s '%s' at: %s\n", description, label, filedesc); + g_assert (par == test->parser); + + attrs = gcr_parser_get_parsed_attributes (test->parser); + description = gcr_parser_get_parsed_description (test->parser); + label = gcr_parser_get_parsed_label (test->parser); + + g_print ("parsed %s '%s' at: %s\n", description, label, test->filedesc); } static gboolean -authenticate (GcrParser *par, gint state, gpointer user_data) +authenticate (GcrParser *par, gint state, gpointer user_data) { + Test *test = user_data; + g_assert (GCR_IS_PARSER (par)); - g_assert (par == parser); - g_assert (par == user_data); + g_assert (par == test->parser); switch (state) { case 0: - gcr_parser_add_password (parser, "booo"); + gcr_parser_add_password (test->parser, "booo"); return TRUE; default: - g_printerr ("decryption didn't work for: %s", filedesc); - g_assert (FALSE); + g_printerr ("decryption didn't work for: %s", test->filedesc); + g_assert_not_reached (); return FALSE; }; -} +} -TESTING_SETUP(parser) +static void +setup (Test *test, gconstpointer unused) { - parser = gcr_parser_new (); - g_signal_connect (parser, "parsed", G_CALLBACK (parsed_item), parser); - g_signal_connect (parser, "authenticate", G_CALLBACK (authenticate), parser); + test->parser = gcr_parser_new (); + g_signal_connect (test->parser, "parsed", G_CALLBACK (parsed_item), test); + g_signal_connect (test->parser, "authenticate", G_CALLBACK (authenticate), test); } -TESTING_TEARDOWN(parser) +static void +teardown (Test *test, gconstpointer unused) { - g_object_unref (parser); - parser = NULL; + g_object_unref (test->parser); } -TESTING_TEST(parse_all) +static void +test_parse_all (Test *test, gconstpointer unused) { - guchar *contents; + gchar *contents; GError *err = NULL; gboolean result; const gchar *filename; gsize len; GDir *dir; - - dir = g_dir_open (testing_data_directory (), 0, NULL); + + dir = g_dir_open ("files", 0, NULL); g_assert (dir); for (;;) { @@ -123,20 +127,41 @@ TESTING_TEST(parse_all) break; if (filename[0] == '.') continue; - - filedesc = filename; - contents = testing_data_read (filename, &len); - - result = gcr_parser_parse_data (parser, contents, len, &err); + + test->filedesc = g_build_filename ("files", filename, NULL); + if (!g_file_get_contents (test->filedesc, &contents, &len, NULL)) + g_assert_not_reached (); + + result = gcr_parser_parse_data (test->parser, contents, len, &err); g_free (contents); - if (!result) { - g_warning ("couldn't parse file data: %s: %s", + if (!result) { + g_warning ("couldn't parse file data: %s: %s", filename, egg_error_message (err)); g_error_free (err); - g_assert (FALSE); + g_assert_not_reached (); } + + g_free (test->filedesc); + test->filedesc = NULL; } - + g_dir_close (dir); } + +int +main (int argc, char **argv) +{ + const gchar *srcdir; + + g_type_init (); + g_test_init (&argc, &argv, NULL); + + srcdir = g_getenv ("SRCDIR"); + if (srcdir && chdir (srcdir) < 0) + g_error ("couldn't change directory to: %s: %s", srcdir, g_strerror (errno)); + + g_test_add ("/gcr/parser/parse_all", Test, NULL, setup, test_parse_all, teardown); + + return g_test_run (); +} diff --git a/gcr/tests/test-pkcs11-certificate.c b/gcr/tests/test-pkcs11-certificate.c index beb0bd4f..52379aa5 100644 --- a/gcr/tests/test-pkcs11-certificate.c +++ b/gcr/tests/test-pkcs11-certificate.c @@ -22,14 +22,14 @@ #include "config.h" -#include "test-suite.h" - #include "egg/egg-asn1x.h" #include "egg/egg-asn1-defs.h" #include "gcr.h" #include "gcr/gcr-internal.h" +#include "egg/egg-testing.h" + #include "gck/gck-mock.h" #include "gck/gck-test.h" @@ -37,13 +37,18 @@ #include <glib.h> -static gpointer cert_data = NULL; -static gsize n_cert_data = 0; -static gpointer cert2_data = NULL; -static gsize n_cert2_data = 0; -static CK_FUNCTION_LIST funcs; +#include <errno.h> + +typedef struct { + gpointer cert_data; + gsize n_cert_data; + gpointer cert2_data; + gsize n_cert2_data; + CK_FUNCTION_LIST funcs; +} Test; -TESTING_SETUP (pkcs11_certificate) +static void +setup (Test *test, gconstpointer unused) { GList *modules = NULL; GckAttributes *attrs; @@ -54,34 +59,39 @@ TESTING_SETUP (pkcs11_certificate) GNode *asn, *node; CK_RV rv; - cert_data = testing_data_read ("der-certificate.crt", &n_cert_data); - g_assert (cert_data); + if (!g_file_get_contents ("files/der-certificate.crt", (gchar**)&test->cert_data, + &test->n_cert_data, NULL)) + g_assert_not_reached (); + g_assert (test->cert_data); - cert2_data = testing_data_read ("der-certificate-dsa.cer", &n_cert2_data); - g_assert (cert2_data); + if (!g_file_get_contents ("files/der-certificate-dsa.cer", (gchar**)&test->cert2_data, + &test->n_cert2_data, NULL)) + g_assert_not_reached (); + g_assert (test->cert2_data); rv = gck_mock_C_GetFunctionList (&f); gck_assert_cmprv (rv, ==, CKR_OK); - memcpy (&funcs, f, sizeof (funcs)); + memcpy (&test->funcs, f, sizeof (test->funcs)); /* Open a session */ - rv = (funcs.C_Initialize) (NULL); + rv = (test->funcs.C_Initialize) (NULL); gck_assert_cmprv (rv, ==, CKR_OK); g_assert (!modules); - module = gck_module_new (&funcs, 0); + module = gck_module_new (&test->funcs, 0); modules = g_list_prepend (modules, module); gcr_pkcs11_set_modules (modules); gck_list_unref_free (modules); - asn = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", cert_data, n_cert_data); + asn = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", + test->cert_data, test->n_cert_data); g_assert (asn); node = egg_asn1x_node (asn, "tbsCertificate", "subject", NULL); subject = egg_asn1x_get_raw_element (node, &n_subject); /* Add a certificate to the module */ attrs = gck_attributes_new (); - gck_attributes_add_data (attrs, CKA_VALUE, cert_data, n_cert_data); + gck_attributes_add_data (attrs, CKA_VALUE, test->cert_data, test->n_cert_data); gck_attributes_add_ulong (attrs, CKA_CLASS, CKO_CERTIFICATE); gck_attributes_add_ulong (attrs, CKA_CERTIFICATE_TYPE, CKC_X_509); gck_attributes_add_data (attrs, CKA_SUBJECT, subject, n_subject); @@ -90,23 +100,20 @@ TESTING_SETUP (pkcs11_certificate) egg_asn1x_destroy (asn); } -TESTING_TEARDOWN (pkcs11_certificate) +static void +teardown (Test *test, gconstpointer unused) { CK_RV rv; - g_free (cert_data); - cert_data = NULL; - n_cert_data = 0; + g_free (test->cert_data); + g_free (test->cert2_data); - g_free (cert2_data); - cert2_data = NULL; - n_cert2_data = 0; - - rv = (funcs.C_Finalize) (NULL); + rv = (test->funcs.C_Finalize) (NULL); gck_assert_cmprv (rv, ==, CKR_OK); } -TESTING_TEST (pkcs11_lookup_certificate_issuer) +static void +test_lookup_certificate_issuer (Test *test, gconstpointer unused) { GcrCertificate *cert, *issuer; GError *error = NULL; @@ -115,7 +122,7 @@ TESTING_TEST (pkcs11_lookup_certificate_issuer) gconstpointer der; gsize n_der; - cert = gcr_simple_certificate_new_static (cert_data, n_cert_data); + cert = gcr_simple_certificate_new_static (test->cert_data, test->n_cert_data); g_assert (cert); /* Should be self-signed, so should find itself (added in setup) */ @@ -125,16 +132,16 @@ TESTING_TEST (pkcs11_lookup_certificate_issuer) /* Should be the same certificate */ der = gcr_certificate_get_der_data (issuer, &n_der); - g_assert_cmpsize (n_der, ==, n_cert_data); - g_assert (memcmp (der, cert_data, n_cert_data) == 0); + egg_assert_cmpsize (n_der, ==, test->n_cert_data); + g_assert (memcmp (der, test->cert_data, test->n_cert_data) == 0); /* Should return the same certificate here too */ attrs = gcr_pkcs11_certificate_get_attributes (GCR_PKCS11_CERTIFICATE (issuer)); g_assert (attrs); attr = gck_attributes_find (attrs, CKA_VALUE); g_assert (attr); - g_assert_cmpsize (attr->length, ==, n_cert_data); - g_assert (memcmp (attr->value, cert_data, n_cert_data) == 0); + egg_assert_cmpsize (attr->length, ==, test->n_cert_data); + g_assert (memcmp (attr->value, test->cert_data, test->n_cert_data) == 0); /* Should return the same certificate here too */ attrs = NULL; @@ -142,20 +149,21 @@ TESTING_TEST (pkcs11_lookup_certificate_issuer) g_assert (attrs); attr = gck_attributes_find (attrs, CKA_VALUE); g_assert (attr); - g_assert_cmpsize (attr->length, ==, n_cert_data); - g_assert (memcmp (attr->value, cert_data, n_cert_data) == 0); + egg_assert_cmpsize (attr->length, ==, test->n_cert_data); + g_assert (memcmp (attr->value, test->cert_data, test->n_cert_data) == 0); gck_attributes_unref (attrs); g_object_unref (cert); g_object_unref (issuer); } -TESTING_TEST (pkcs11_lookup_certificate_issuer_not_found) +static void +test_lookup_certificate_issuer_not_found (Test *test, gconstpointer unused) { GcrCertificate *cert, *issuer; GError *error = NULL; - cert = gcr_simple_certificate_new_static (cert2_data, n_cert2_data); + cert = gcr_simple_certificate_new_static (test->cert2_data, test->n_cert2_data); g_assert (cert); /* Issuer shouldn't be found */ @@ -171,10 +179,11 @@ fetch_async_result (GObject *source, GAsyncResult *result, gpointer user_data) { *((GAsyncResult**)user_data) = result; g_object_ref (result); - testing_wait_stop (); + egg_test_wait_stop (); } -TESTING_TEST (pkcs11_lookup_certificate_issuer_async) +static void +test_lookup_certificate_issuer_async (Test *test, gconstpointer unused) { GAsyncResult *result = NULL; GcrCertificate *cert, *issuer; @@ -182,12 +191,12 @@ TESTING_TEST (pkcs11_lookup_certificate_issuer_async) gconstpointer der; gsize n_der; - cert = gcr_simple_certificate_new_static (cert_data, n_cert_data); + cert = gcr_simple_certificate_new_static (test->cert_data, test->n_cert_data); g_assert (cert); /* Should be self-signed, so should find itself (added in setup) */ gcr_pkcs11_certificate_lookup_issuer_async (cert, NULL, fetch_async_result, &result); - testing_wait_until (500); + egg_test_wait_until (500); g_assert (result); issuer = gcr_pkcs11_certificate_lookup_issuer_finish (result, &error); g_assert (GCR_IS_PKCS11_CERTIFICATE (issuer)); @@ -197,23 +206,24 @@ TESTING_TEST (pkcs11_lookup_certificate_issuer_async) /* Should be the same certificate */ der = gcr_certificate_get_der_data (issuer, &n_der); - g_assert_cmpsize (n_der, ==, n_cert_data); - g_assert (memcmp (der, cert_data, n_cert_data) == 0); + egg_assert_cmpsize (n_der, ==, test->n_cert_data); + g_assert (memcmp (der, test->cert_data, test->n_cert_data) == 0); g_object_unref (cert); g_object_unref (issuer); } -TESTING_TEST (pkcs11_lookup_certificate_issuer_failure) +static void +test_lookup_certificate_issuer_failure (Test *test, gconstpointer unused) { GcrCertificate *cert, *issuer; GError *error = NULL; - cert = gcr_simple_certificate_new_static (cert_data, n_cert_data); + cert = gcr_simple_certificate_new_static (test->cert_data, test->n_cert_data); g_assert (cert); /* Make the lookup fail */ - funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue; + test->funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue; issuer = gcr_pkcs11_certificate_lookup_issuer (cert, NULL, &error); g_assert (issuer == NULL); @@ -224,21 +234,22 @@ TESTING_TEST (pkcs11_lookup_certificate_issuer_failure) g_object_unref (cert); } -TESTING_TEST (pkcs11_lookup_certificate_issuer_fail_async) +static void +test_lookup_certificate_issuer_fail_async (Test *test, gconstpointer unused) { GAsyncResult *result = NULL; GcrCertificate *cert, *issuer; GError *error = NULL; - cert = gcr_simple_certificate_new_static (cert_data, n_cert_data); + cert = gcr_simple_certificate_new_static (test->cert_data, test->n_cert_data); g_assert (cert); /* Make the lookup fail */ - funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue; + test->funcs.C_GetAttributeValue = gck_mock_fail_C_GetAttributeValue; /* Should be self-signed, so should find itself (added in setup) */ gcr_pkcs11_certificate_lookup_issuer_async (cert, NULL, fetch_async_result, &result); - testing_wait_until (500); + egg_test_wait_until (500); g_assert (result); issuer = gcr_pkcs11_certificate_lookup_issuer_finish (result, &error); g_assert (issuer == NULL); @@ -250,3 +261,24 @@ TESTING_TEST (pkcs11_lookup_certificate_issuer_fail_async) g_object_unref (cert); } + +int +main (int argc, char **argv) +{ + const gchar *srcdir; + + g_type_init (); + g_test_init (&argc, &argv, NULL); + + srcdir = g_getenv ("SRCDIR"); + if (srcdir && chdir (srcdir) < 0) + g_error ("couldn't change directory to: %s: %s", srcdir, g_strerror (errno)); + + g_test_add ("/gcr/pkcs11-certificate/lookup_certificate_issuer", Test, NULL, setup, test_lookup_certificate_issuer, teardown); + g_test_add ("/gcr/pkcs11-certificate/lookup_certificate_issuer_not_found", Test, NULL, setup, test_lookup_certificate_issuer_not_found, teardown); + g_test_add ("/gcr/pkcs11-certificate/lookup_certificate_issuer_async", Test, NULL, setup, test_lookup_certificate_issuer_async, teardown); + g_test_add ("/gcr/pkcs11-certificate/lookup_certificate_issuer_failure", Test, NULL, setup, test_lookup_certificate_issuer_failure, teardown); + g_test_add ("/gcr/pkcs11-certificate/lookup_certificate_issuer_fail_async", Test, NULL, setup, test_lookup_certificate_issuer_fail_async, teardown); + + return egg_tests_run_in_thread_with_loop (); +} diff --git a/gcr/tests/test-simple-certificate.c b/gcr/tests/test-simple-certificate.c index 3bc18ddc..8b7d4169 100644 --- a/gcr/tests/test-simple-certificate.c +++ b/gcr/tests/test-simple-certificate.c @@ -22,8 +22,6 @@ #include "config.h" -#include "test-suite.h" - #include "gcr.h" #include "gcr/gcr-internal.h" @@ -31,54 +29,81 @@ #include "pkcs11/pkcs11n.h" +#include "egg/egg-testing.h" + #include <glib.h> -static gpointer cert_data; -static gsize n_cert_data; +#include <errno.h> + +typedef struct { + gpointer cert_data; + gsize n_cert_data; +} Test; -TESTING_SETUP (simple_certificate) +static void +setup (Test *test, gconstpointer unused) { - cert_data = testing_data_read ("der-certificate.crt", &n_cert_data); - g_assert (cert_data); + if (!g_file_get_contents ("files/der-certificate.crt", (gchar**)&test->cert_data, + &test->n_cert_data, NULL)) + g_assert_not_reached (); + g_assert (test->cert_data); } -TESTING_TEARDOWN (simple_certificate) +static void +teardown (Test *test, gconstpointer unused) { - g_free (cert_data); - cert_data = NULL; - n_cert_data = 0; + g_free (test->cert_data); } -TESTING_TEST (simple_certificate_new) +static void +test_new (Test *test, gconstpointer unused) { GcrCertificate *cert; gconstpointer der; gsize n_der; - cert = gcr_simple_certificate_new (cert_data, n_cert_data); + cert = gcr_simple_certificate_new (test->cert_data, test->n_cert_data); g_assert (GCR_IS_SIMPLE_CERTIFICATE (cert)); der = gcr_certificate_get_der_data (cert, &n_der); g_assert (der); - g_assert_cmpsize (n_der, ==, n_cert_data); - g_assert (memcmp (der, cert_data, n_der) == 0); + egg_assert_cmpmem (der, n_der, ==, test->cert_data, test->n_cert_data); g_object_unref (cert); } -TESTING_TEST (simple_certificate_new_static) +static void +test_new_static (Test *test, gconstpointer unused) { GcrCertificate *cert; gconstpointer der; gsize n_der; - cert = gcr_simple_certificate_new_static (cert_data, n_cert_data); + cert = gcr_simple_certificate_new_static (test->cert_data, test->n_cert_data); g_assert (GCR_IS_SIMPLE_CERTIFICATE (cert)); der = gcr_certificate_get_der_data (cert, &n_der); g_assert (der); - g_assert_cmpsize (n_der, ==, n_cert_data); - g_assert (der == cert_data); /* Must be same pointer */ + egg_assert_cmpsize (n_der, ==, test->n_cert_data); + g_assert (der == test->cert_data); /* Must be same pointer */ g_object_unref (cert); } + +int +main (int argc, char **argv) +{ + const gchar *srcdir; + + g_type_init (); + g_test_init (&argc, &argv, NULL); + + srcdir = g_getenv ("SRCDIR"); + if (srcdir && chdir (srcdir) < 0) + g_error ("couldn't change directory to: %s: %s", srcdir, g_strerror (errno)); + + g_test_add ("/gcr/simple-certificate/new", Test, NULL, setup, test_new, teardown); + g_test_add ("/gcr/simple-certificate/new_static", Test, NULL, setup, test_new_static, teardown); + + return g_test_run (); +} diff --git a/gcr/tests/test-trust.c b/gcr/tests/test-trust.c index 545fce02..f21f80df 100644 --- a/gcr/tests/test-trust.c +++ b/gcr/tests/test-trust.c @@ -22,8 +22,6 @@ #include "config.h" -#include "test-suite.h" - #include "gcr.h" #include "gcr/gcr-internal.h" @@ -34,37 +32,45 @@ #include "pkcs11/pkcs11n.h" #include "pkcs11/pkcs11x.h" +#include "egg/egg-testing.h" + #include <glib.h> -static CK_FUNCTION_LIST funcs; -static GcrCertificate *certificate = NULL; +#include <errno.h> + +typedef struct { + CK_FUNCTION_LIST funcs; + GcrCertificate *certificate; +} Test; -TESTING_SETUP (trust_setup) +static void +setup (Test *test, gconstpointer unused) { GList *modules = NULL; CK_FUNCTION_LIST_PTR f; GckModule *module; - guchar *contents; + gchar *contents; const gchar *uris[2]; gsize len; CK_RV rv; - contents = testing_data_read ("der-certificate.crt", &len); + if (!g_file_get_contents ("files/der-certificate.crt", &contents, &len, NULL)) + g_assert_not_reached (); g_assert (contents); - certificate = gcr_simple_certificate_new (contents, len); + test->certificate = gcr_simple_certificate_new (contents, len); g_free (contents); rv = gck_mock_C_GetFunctionList (&f); gck_assert_cmprv (rv, ==, CKR_OK); - memcpy (&funcs, f, sizeof (funcs)); + memcpy (&test->funcs, f, sizeof (test->funcs)); /* Open a session */ - rv = (funcs.C_Initialize) (NULL); + rv = (test->funcs.C_Initialize) (NULL); gck_assert_cmprv (rv, ==, CKR_OK); g_assert (!modules); - module = gck_module_new (&funcs, 0); + module = gck_module_new (&test->funcs, 0); modules = g_list_prepend (modules, module); gcr_pkcs11_set_modules (modules); gck_list_unref_free (modules); @@ -76,79 +82,83 @@ TESTING_SETUP (trust_setup) gcr_pkcs11_set_trust_lookup_uris (uris); } -TESTING_TEARDOWN (trust_setup) +static void +teardown (Test *test, gconstpointer unused) { CK_RV rv; - g_object_unref (certificate); - certificate = NULL; + g_object_unref (test->certificate); - rv = (funcs.C_Finalize) (NULL); + rv = (test->funcs.C_Finalize) (NULL); gck_assert_cmprv (rv, ==, CKR_OK); } -TESTING_TEST (trust_is_pinned_none) +static void +test_is_pinned_none (Test *test, gconstpointer unused) { GError *error = NULL; gboolean trust; - trust = gcr_trust_is_certificate_pinned (certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error); + trust = gcr_trust_is_certificate_pinned (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error); g_assert_cmpint (trust, ==, FALSE); g_assert (error == NULL); } -TESTING_TEST (trust_add_and_is_pinned) +static void +test_add_and_is_pinned (Test *test, gconstpointer unused) { GError *error = NULL; gboolean trust; gboolean ret; - trust = gcr_trust_is_certificate_pinned (certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error); + trust = gcr_trust_is_certificate_pinned (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error); g_assert_cmpint (trust, ==, FALSE); g_assert (error == NULL); - ret = gcr_trust_add_pinned_certificate (certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error); + ret = gcr_trust_add_pinned_certificate (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error); g_assert (ret == TRUE); g_assert (error == NULL); - trust = gcr_trust_is_certificate_pinned (certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error); + trust = gcr_trust_is_certificate_pinned (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error); g_assert_cmpint (trust, ==, TRUE); g_assert (error == NULL); } -TESTING_TEST (trust_add_certificate_pinned_fail) +static void +test_add_certificate_pinned_fail (Test *test, gconstpointer unused) { GError *error = NULL; gboolean ret; /* Make this function fail */ - funcs.C_CreateObject = gck_mock_fail_C_CreateObject; + test->funcs.C_CreateObject = gck_mock_fail_C_CreateObject; - ret = gcr_trust_add_pinned_certificate (certificate, GCR_PURPOSE_CLIENT_AUTH, "peer", NULL, &error); + ret = gcr_trust_add_pinned_certificate (test->certificate, GCR_PURPOSE_CLIENT_AUTH, "peer", NULL, &error); g_assert (ret == FALSE); g_assert_error (error, GCK_ERROR, CKR_FUNCTION_FAILED); g_clear_error (&error); } -TESTING_TEST (trust_add_and_remov_pinned) +static void +test_add_and_remov_pinned (Test *test, gconstpointer unused) { GError *error = NULL; gboolean trust; gboolean ret; - ret = gcr_trust_add_pinned_certificate (certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error); + ret = gcr_trust_add_pinned_certificate (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error); g_assert (ret == TRUE); g_assert (error == NULL); - trust = gcr_trust_is_certificate_pinned (certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error); + trust = gcr_trust_is_certificate_pinned (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error); g_assert_cmpint (trust, ==, TRUE); g_assert (error == NULL); - ret = gcr_trust_remove_pinned_certificate (certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error); + ret = gcr_trust_remove_pinned_certificate (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error); g_assert (ret == TRUE); g_assert (error == NULL); - trust = gcr_trust_is_certificate_pinned (certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error); + trust = gcr_trust_is_certificate_pinned (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, &error); g_assert_cmpint (trust, ==, FALSE); g_assert (error == NULL); } @@ -158,18 +168,19 @@ fetch_async_result (GObject *source, GAsyncResult *result, gpointer user_data) { *((GAsyncResult**)user_data) = result; g_object_ref (result); - testing_wait_stop (); + egg_test_wait_stop (); } -TESTING_TEST (trust_add_and_is_pinned_async) +static void +test_add_and_is_pinned_async (Test *test, gconstpointer unused) { GAsyncResult *result = NULL; GError *error = NULL; gboolean trust; gboolean ret; - gcr_trust_is_certificate_pinned_async (certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result); - testing_wait_until (500); + gcr_trust_is_certificate_pinned_async (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result); + egg_test_wait_until (500); g_assert (result); trust = gcr_trust_is_certificate_pinned_finish (result, &error); g_assert (trust == FALSE); @@ -177,9 +188,9 @@ TESTING_TEST (trust_add_and_is_pinned_async) g_object_unref (result); result = NULL; - gcr_trust_add_pinned_certificate_async (certificate, GCR_PURPOSE_EMAIL, "host", - NULL, fetch_async_result, &result); - testing_wait_until (500); + gcr_trust_add_pinned_certificate_async (test->certificate, GCR_PURPOSE_EMAIL, "host", + NULL, fetch_async_result, &result); + egg_test_wait_until (500); g_assert (result); ret = gcr_trust_add_pinned_certificate_finish (result, &error); g_assert (ret == TRUE); @@ -187,8 +198,8 @@ TESTING_TEST (trust_add_and_is_pinned_async) g_object_unref (result); result = NULL; - gcr_trust_is_certificate_pinned_async (certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result); - testing_wait_until (500); + gcr_trust_is_certificate_pinned_async (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result); + egg_test_wait_until (500); g_assert (result); trust = gcr_trust_is_certificate_pinned_finish (result, &error); g_assert (trust == TRUE); @@ -197,15 +208,16 @@ TESTING_TEST (trust_add_and_is_pinned_async) result = NULL; } -TESTING_TEST (trust_add_and_remov_pinned_async) +static void +test_add_and_remov_pinned_async (Test *test, gconstpointer unused) { GAsyncResult *result = NULL; GError *error = NULL; gboolean trust; gboolean ret; - gcr_trust_add_pinned_certificate_async (certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result); - testing_wait_until (500); + gcr_trust_add_pinned_certificate_async (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result); + egg_test_wait_until (500); g_assert (result); ret = gcr_trust_add_pinned_certificate_finish (result, &error); g_assert (ret == TRUE); @@ -213,8 +225,8 @@ TESTING_TEST (trust_add_and_remov_pinned_async) g_object_unref (result); result = NULL; - gcr_trust_is_certificate_pinned_async (certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result); - testing_wait_until (500); + gcr_trust_is_certificate_pinned_async (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result); + egg_test_wait_until (500); g_assert (result); trust = gcr_trust_is_certificate_pinned_finish (result, &error); g_assert (trust == TRUE); @@ -222,8 +234,8 @@ TESTING_TEST (trust_add_and_remov_pinned_async) g_object_unref (result); result = NULL; - gcr_trust_remove_pinned_certificate_async (certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result); - testing_wait_until (500); + gcr_trust_remove_pinned_certificate_async (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result); + egg_test_wait_until (500); g_assert (result); ret = gcr_trust_remove_pinned_certificate_finish (result, &error); g_assert (ret == TRUE); @@ -231,8 +243,8 @@ TESTING_TEST (trust_add_and_remov_pinned_async) g_object_unref (result); result = NULL; - gcr_trust_is_certificate_pinned_async (certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result); - testing_wait_until (500); + gcr_trust_is_certificate_pinned_async (test->certificate, GCR_PURPOSE_EMAIL, "host", NULL, fetch_async_result, &result); + egg_test_wait_until (500); g_assert (result); trust = gcr_trust_is_certificate_pinned_finish (result, &error); g_assert (trust == FALSE); @@ -241,17 +253,19 @@ TESTING_TEST (trust_add_and_remov_pinned_async) result = NULL; } -TESTING_TEST (trust_is_certificate_anchored_not) +static void +test_is_certificate_anchored_not (Test *test, gconstpointer unused) { GError *error = NULL; gboolean ret; - ret = gcr_trust_is_certificate_anchored (certificate, GCR_PURPOSE_CLIENT_AUTH, NULL, &error); + ret = gcr_trust_is_certificate_anchored (test->certificate, GCR_PURPOSE_CLIENT_AUTH, NULL, &error); g_assert (ret == FALSE); g_assert (error == NULL); } -TESTING_TEST (trust_is_certificate_anchored_yes) +static void +test_is_certificate_anchored_yes (Test *test, gconstpointer unused) { GError *error = NULL; GckAttributes *attrs; @@ -261,7 +275,7 @@ TESTING_TEST (trust_is_certificate_anchored_yes) /* Create a certificate root trust */ attrs = gck_attributes_new (); - der = gcr_certificate_get_der_data (certificate, &n_der); + der = gcr_certificate_get_der_data (test->certificate, &n_der); gck_attributes_add_data (attrs, CKA_X_CERTIFICATE_VALUE, der, n_der); gck_attributes_add_ulong (attrs, CKA_CLASS, CKO_X_TRUST_ASSERTION); gck_attributes_add_boolean (attrs, CKA_TOKEN, TRUE); @@ -269,19 +283,20 @@ TESTING_TEST (trust_is_certificate_anchored_yes) gck_attributes_add_ulong (attrs, CKA_X_ASSERTION_TYPE, CKT_X_ANCHORED_CERTIFICATE); gck_mock_module_take_object (attrs); - ret = gcr_trust_is_certificate_anchored (certificate, GCR_PURPOSE_CLIENT_AUTH, NULL, &error); + ret = gcr_trust_is_certificate_anchored (test->certificate, GCR_PURPOSE_CLIENT_AUTH, NULL, &error); g_assert (ret == TRUE); g_assert (error == NULL); } -TESTING_TEST (trust_is_certificate_anchored_async) +static void +test_is_certificate_anchored_async (Test *test, gconstpointer unused) { GAsyncResult *result = NULL; GError *error = NULL; gboolean ret; - gcr_trust_is_certificate_anchored_async (certificate, GCR_PURPOSE_CLIENT_AUTH, NULL, fetch_async_result, &result); - testing_wait_until (500); + gcr_trust_is_certificate_anchored_async (test->certificate, GCR_PURPOSE_CLIENT_AUTH, NULL, fetch_async_result, &result); + egg_test_wait_until (500); g_assert (result); ret = gcr_trust_is_certificate_anchored_finish (result, &error); @@ -290,3 +305,28 @@ TESTING_TEST (trust_is_certificate_anchored_async) g_object_unref (result); } + +int +main (int argc, char **argv) +{ + const gchar *srcdir; + + g_type_init (); + g_test_init (&argc, &argv, NULL); + + srcdir = g_getenv ("SRCDIR"); + if (srcdir && chdir (srcdir) < 0) + g_error ("couldn't change directory to: %s: %s", srcdir, g_strerror (errno)); + + g_test_add ("/gcr/trust/is_pinned_none", Test, NULL, setup, test_is_pinned_none, teardown); + g_test_add ("/gcr/trust/add_and_is_pinned", Test, NULL, setup, test_add_and_is_pinned, teardown); + g_test_add ("/gcr/trust/add_certificate_pinned_fail", Test, NULL, setup, test_add_certificate_pinned_fail, teardown); + g_test_add ("/gcr/trust/add_and_remov_pinned", Test, NULL, setup, test_add_and_remov_pinned, teardown); + g_test_add ("/gcr/trust/add_and_is_pinned_async", Test, NULL, setup, test_add_and_is_pinned_async, teardown); + g_test_add ("/gcr/trust/add_and_remov_pinned_async", Test, NULL, setup, test_add_and_remov_pinned_async, teardown); + g_test_add ("/gcr/trust/is_certificate_anchored_not", Test, NULL, setup, test_is_certificate_anchored_not, teardown); + g_test_add ("/gcr/trust/is_certificate_anchored_yes", Test, NULL, setup, test_is_certificate_anchored_yes, teardown); + g_test_add ("/gcr/trust/is_certificate_anchored_async", Test, NULL, setup, test_is_certificate_anchored_async, teardown); + + return egg_tests_run_in_thread_with_loop (); +} |