From dcabaf1d56d410ba7ddb3dfbab9011bbbea5e6bc Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Fri, 5 Apr 2013 23:52:39 +0200 Subject: Our own unit testing framework * Support the TAP protocol * Much cleaner without having to carry around state * First class support for setup/teardown * Port the common tests * Wait on porting other tests until we've merged outstanding code --- tools/tests/Makefile.am | 6 +- tools/tests/test-extract.c | 221 ++++++++++++------------------ tools/tests/test-openssl.c | 186 +++++++++++-------------- tools/tests/test-pem.c | 96 +++++-------- tools/tests/test-save.c | 329 +++++++++++++++++++-------------------------- tools/tests/test-tools.c | 216 +++++++++++++++++++++++++++++ tools/tests/test-tools.h | 260 +++++++++++++++++++++++++++++++++++ tools/tests/test-x509.c | 102 +++++--------- tools/tests/test.c | 209 ---------------------------- tools/tests/test.h | 260 ----------------------------------- 10 files changed, 843 insertions(+), 1042 deletions(-) create mode 100644 tools/tests/test-tools.c create mode 100644 tools/tests/test-tools.h delete mode 100644 tools/tests/test.c delete mode 100644 tools/tests/test.h (limited to 'tools') diff --git a/tools/tests/Makefile.am b/tools/tests/Makefile.am index f6609ec..667bf12 100644 --- a/tools/tests/Makefile.am +++ b/tools/tests/Makefile.am @@ -17,13 +17,13 @@ INCLUDES = \ -I$(COMMON) \ -DP11_KIT_FUTURE_UNSTABLE_API \ $(LIBTASN1_CFLAGS) \ - $(CUTEST_CFLAGS) \ + $(TEST_CFLAGS) \ $(NULL) LDADD = \ $(top_builddir)/p11-kit/libp11-kit.la \ $(top_builddir)/common/libp11-data.la \ - $(top_builddir)/common/libp11-mock.la \ + $(top_builddir)/common/libp11-test.la \ $(top_builddir)/common/libp11-common.la \ $(builddir)/libtestcommon.la \ $(LIBTASN1_LIBS) \ @@ -35,7 +35,7 @@ noinst_LTLIBRARIES = \ libtestcommon.la libtestcommon_la_SOURCES = \ - test.c test.h + test-tools.c test-tools.h CHECK_PROGS = \ test-save \ diff --git a/tools/tests/test-extract.c b/tools/tests/test-extract.c index a3db8d8..9712e81 100644 --- a/tools/tests/test-extract.c +++ b/tools/tests/test-extract.c @@ -35,7 +35,8 @@ #define P11_KIT_DISABLE_DEPRECATED #include "config.h" -#include "CuTest.h" +#include "test.h" +#include "test-tools.h" #include "attrs.h" #include "compat.h" @@ -47,13 +48,12 @@ #include "pkcs11.h" #include "pkcs11x.h" #include "oid.h" -#include "test.h" #include #include static void -test_file_name_for_label (CuTest *tc) +test_file_name_for_label (void) { CK_ATTRIBUTE label = { CKA_LABEL, "The Label!", 10 }; p11_extract_info ex; @@ -64,14 +64,14 @@ test_file_name_for_label (CuTest *tc) ex.attrs = p11_attrs_build (NULL, &label, NULL); name = p11_extract_info_filename (&ex); - CuAssertStrEquals (tc, "The_Label_", name); + assert_str_eq ("The_Label_", name); free (name); p11_extract_info_cleanup (&ex); } static void -test_file_name_for_class (CuTest *tc) +test_file_name_for_class (void) { p11_extract_info ex; char *name; @@ -81,20 +81,20 @@ test_file_name_for_class (CuTest *tc) ex.klass = CKO_CERTIFICATE; name = p11_extract_info_filename (&ex); - CuAssertStrEquals (tc, "certificate", name); + assert_str_eq ("certificate", name); free (name); ex.klass = CKO_DATA; name = p11_extract_info_filename (&ex); - CuAssertStrEquals (tc, "unknown", name); + assert_str_eq ("unknown", name); free (name); p11_extract_info_cleanup (&ex); } static void -test_comment_for_label (CuTest *tc) +test_comment_for_label (void) { CK_ATTRIBUTE label = { CKA_LABEL, "The Label!", 10 }; p11_extract_info ex; @@ -106,18 +106,18 @@ test_comment_for_label (CuTest *tc) ex.attrs = p11_attrs_build (NULL, &label, NULL); comment = p11_extract_info_comment (&ex, true); - CuAssertStrEquals (tc, "# The Label!\n", comment); + assert_str_eq ("# The Label!\n", comment); free (comment); comment = p11_extract_info_comment (&ex, false); - CuAssertStrEquals (tc, "\n# The Label!\n", comment); + assert_str_eq ("\n# The Label!\n", comment); free (comment); p11_extract_info_cleanup (&ex); } static void -test_comment_not_enabled (CuTest *tc) +test_comment_not_enabled (void) { CK_ATTRIBUTE label = { CKA_LABEL, "The Label!", 10 }; p11_extract_info ex; @@ -128,10 +128,10 @@ test_comment_not_enabled (CuTest *tc) ex.attrs = p11_attrs_build (NULL, &label, NULL); comment = p11_extract_info_comment (&ex, true); - CuAssertPtrEquals (tc, NULL, comment); + assert_ptr_eq (NULL, comment); comment = p11_extract_info_comment (&ex, false); - CuAssertPtrEquals (tc, NULL, comment); + assert_ptr_eq (NULL, comment); p11_extract_info_cleanup (&ex); } @@ -143,7 +143,7 @@ struct { } test; static void -setup (CuTest *tc) +setup (void *unused) { CK_RV rv; @@ -151,7 +151,7 @@ setup (CuTest *tc) memcpy (&test.module, &mock_module, sizeof (CK_FUNCTION_LIST)); rv = test.module.C_Initialize (NULL); - CuAssertIntEquals (tc, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); test.iter = p11_kit_iter_new (NULL); @@ -159,7 +159,7 @@ setup (CuTest *tc) } static void -teardown (CuTest *tc) +teardown (void *unused) { CK_RV rv; @@ -168,7 +168,7 @@ teardown (CuTest *tc) p11_kit_iter_free (test.iter); rv = test.module.C_Finalize (NULL); - CuAssertIntEquals (tc, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); } static CK_OBJECT_CLASS certificate_class = CKO_CERTIFICATE; @@ -219,15 +219,13 @@ static CK_ATTRIBUTE extension_eku_invalid[] = { }; static void -test_info_simple_certificate (CuTest *tc) +test_info_simple_certificate (void) { void *value; size_t length; CK_RV rv; - setup (tc); - - CuAssertPtrNotNull (tc, test.ex.asn1_defs); + assert_ptr_not_null (test.ex.asn1_defs); mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted); mock_module_add_object (MOCK_SLOT_ONE_ID, extension_eku_server_client); @@ -237,55 +235,47 @@ test_info_simple_certificate (CuTest *tc) p11_kit_iter_begin_with (test.iter, &test.module, 0, 0); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); - CuAssertIntEquals (tc, CKO_CERTIFICATE, test.ex.klass); - CuAssertPtrNotNull (tc, test.ex.attrs); + assert_num_eq (CKO_CERTIFICATE, test.ex.klass); + assert_ptr_not_null (test.ex.attrs); value = p11_attrs_find_value (test.ex.attrs, CKA_VALUE, &length); - CuAssertPtrNotNull (tc, value); - CuAssertTrue (tc, memcmp (value, test_cacert3_ca_der, length) == 0); - CuAssertPtrNotNull (tc, test.ex.cert_der); - CuAssertTrue (tc, memcmp (test.ex.cert_der, test_cacert3_ca_der, test.ex.cert_len) == 0); - CuAssertPtrNotNull (tc, test.ex.cert_asn); + assert_ptr_not_null (value); + assert (memcmp (value, test_cacert3_ca_der, length) == 0); + assert_ptr_not_null (test.ex.cert_der); + assert (memcmp (test.ex.cert_der, test_cacert3_ca_der, test.ex.cert_len) == 0); + assert_ptr_not_null (test.ex.cert_asn); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_CANCEL, rv); - - teardown (tc); + assert_num_eq (CKR_CANCEL, rv); } static void -test_info_limit_purposes (CuTest *tc) +test_info_limit_purposes (void) { CK_RV rv; - setup (tc); - mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted); mock_module_add_object (MOCK_SLOT_ONE_ID, extension_eku_server_client); /* This should not match the above, with the stapled certificat ext */ - CuAssertPtrEquals (tc, NULL, test.ex.limit_to_purposes); + assert_ptr_eq (NULL, test.ex.limit_to_purposes); p11_extract_info_limit_purpose (&test.ex, "1.1.1"); - CuAssertPtrNotNull (tc, test.ex.limit_to_purposes); + assert_ptr_not_null (test.ex.limit_to_purposes); p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL); p11_kit_iter_add_filter (test.iter, certificate_filter, 1); p11_kit_iter_begin_with (test.iter, &test.module, 0, 0); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_CANCEL, rv); - - teardown (tc); + assert_num_eq (CKR_CANCEL, rv); } static void -test_info_invalid_purposes (CuTest *tc) +test_info_invalid_purposes (void) { CK_RV rv; - setup (tc); - mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted); mock_module_add_object (MOCK_SLOT_ONE_ID, extension_eku_invalid); @@ -297,20 +287,16 @@ test_info_invalid_purposes (CuTest *tc) /* No results due to invalid purpose on certificate */ rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_CANCEL, rv); + assert_num_eq (CKR_CANCEL, rv); p11_kit_be_loud (); - - teardown (tc); } static void -test_info_skip_non_certificate (CuTest *tc) +test_info_skip_non_certificate (void) { CK_RV rv; - setup (tc); - mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted); p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL); @@ -319,25 +305,21 @@ test_info_skip_non_certificate (CuTest *tc) p11_message_quiet (); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); - CuAssertIntEquals (tc, CKO_CERTIFICATE, test.ex.klass); + assert_num_eq (CKO_CERTIFICATE, test.ex.klass); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_CANCEL, rv); + assert_num_eq (CKR_CANCEL, rv); p11_message_loud (); - - teardown (tc); } static void -test_limit_to_purpose_match (CuTest *tc) +test_limit_to_purpose_match (void) { CK_RV rv; - setup (tc); - mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted); mock_module_add_object (MOCK_SLOT_ONE_ID, extension_eku_server_client); @@ -348,20 +330,16 @@ test_limit_to_purpose_match (CuTest *tc) p11_message_quiet (); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); p11_message_loud (); - - teardown (tc); } static void -test_limit_to_purpose_no_match (CuTest *tc) +test_limit_to_purpose_no_match (void) { CK_RV rv; - setup (tc); - mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted); mock_module_add_object (MOCK_SLOT_ONE_ID, extension_eku_server_client); @@ -372,21 +350,17 @@ test_limit_to_purpose_no_match (CuTest *tc) p11_message_quiet (); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_CANCEL, rv); + assert_num_eq (CKR_CANCEL, rv); p11_message_loud (); - - teardown (tc); } static void -test_duplicate_extract (CuTest *tc) +test_duplicate_extract (void) { CK_ATTRIBUTE certificate = { CKA_CLASS, &certificate_class, sizeof (certificate_class) }; CK_RV rv; - setup (tc); - mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted); mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_distrusted); @@ -395,25 +369,21 @@ test_duplicate_extract (CuTest *tc) p11_kit_iter_begin_with (test.iter, &test.module, 0, 0); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_CANCEL, rv); - - teardown (tc); + assert_num_eq (CKR_CANCEL, rv); } static void -test_duplicate_collapse (CuTest *tc) +test_duplicate_collapse (void) { CK_ATTRIBUTE certificate = { CKA_CLASS, &certificate_class, sizeof (certificate_class) }; CK_RV rv; - setup (tc); - mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted); mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_distrusted); @@ -423,23 +393,19 @@ test_duplicate_collapse (CuTest *tc) p11_kit_iter_begin_with (test.iter, &test.module, 0, 0); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_CANCEL, rv); - - teardown (tc); + assert_num_eq (CKR_CANCEL, rv); } static void -test_trusted_match (CuTest *tc) +test_trusted_match (void) { CK_ATTRIBUTE certificate = { CKA_CLASS, &certificate_class, sizeof (certificate_class) }; CK_BBOOL boolv; CK_RV rv; - setup (tc); - mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted); mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_distrusted); @@ -449,27 +415,23 @@ test_trusted_match (CuTest *tc) p11_kit_iter_begin_with (test.iter, &test.module, 0, 0); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); if (!p11_attrs_find_bool (test.ex.attrs, CKA_TRUSTED, &boolv)) boolv = CK_FALSE; - CuAssertIntEquals (tc, CK_TRUE, boolv); + assert_num_eq (CK_TRUE, boolv); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_CANCEL, rv); - - teardown (tc); + assert_num_eq (CKR_CANCEL, rv); } static void -test_distrust_match (CuTest *tc) +test_distrust_match (void) { CK_ATTRIBUTE certificate = { CKA_CLASS, &certificate_class, sizeof (certificate_class) }; CK_BBOOL boolv; CK_RV rv; - setup (tc); - mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted); mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_distrusted); @@ -479,26 +441,22 @@ test_distrust_match (CuTest *tc) p11_kit_iter_begin_with (test.iter, &test.module, 0, 0); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); if (!p11_attrs_find_bool (test.ex.attrs, CKA_X_DISTRUSTED, &boolv)) boolv = CK_FALSE; - CuAssertIntEquals (tc, CK_TRUE, boolv); + assert_num_eq (CK_TRUE, boolv); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_CANCEL, rv); - - teardown (tc); + assert_num_eq (CKR_CANCEL, rv); } static void -test_anytrust_match (CuTest *tc) +test_anytrust_match (void) { CK_ATTRIBUTE certificate = { CKA_CLASS, &certificate_class, sizeof (certificate_class) }; CK_RV rv; - setup (tc); - mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_trusted); mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_distrusted); @@ -508,51 +466,38 @@ test_anytrust_match (CuTest *tc) p11_kit_iter_begin_with (test.iter, &test.module, 0, 0); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); rv = p11_kit_iter_next (test.iter); - CuAssertIntEquals (tc, CKR_CANCEL, rv); - - teardown (tc); + assert_num_eq (CKR_CANCEL, rv); } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - putenv ("P11_KIT_STRICT=1"); mock_module_init (); - p11_debug_init (); - - SUITE_ADD_TEST (suite, test_file_name_for_label); - SUITE_ADD_TEST (suite, test_file_name_for_class); - SUITE_ADD_TEST (suite, test_comment_for_label); - SUITE_ADD_TEST (suite, test_comment_not_enabled); - SUITE_ADD_TEST (suite, test_info_simple_certificate); - SUITE_ADD_TEST (suite, test_info_limit_purposes); - SUITE_ADD_TEST (suite, test_info_invalid_purposes); - SUITE_ADD_TEST (suite, test_info_skip_non_certificate); - SUITE_ADD_TEST (suite, test_limit_to_purpose_match); - SUITE_ADD_TEST (suite, test_limit_to_purpose_no_match); - SUITE_ADD_TEST (suite, test_duplicate_extract); - SUITE_ADD_TEST (suite, test_duplicate_collapse); - SUITE_ADD_TEST (suite, test_trusted_match); - SUITE_ADD_TEST (suite, test_distrust_match); - SUITE_ADD_TEST (suite, test_anytrust_match); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + + p11_test (test_file_name_for_label, "/extract/test_file_name_for_label"); + p11_test (test_file_name_for_class, "/extract/test_file_name_for_class"); + p11_test (test_comment_for_label, "/extract/test_comment_for_label"); + p11_test (test_comment_not_enabled, "/extract/test_comment_not_enabled"); + + p11_fixture (setup, teardown); + p11_test (test_info_simple_certificate, "/extract/test_info_simple_certificate"); + p11_test (test_info_limit_purposes, "/extract/test_info_limit_purposes"); + p11_test (test_info_invalid_purposes, "/extract/test_info_invalid_purposes"); + p11_test (test_info_skip_non_certificate, "/extract/test_info_skip_non_certificate"); + p11_test (test_limit_to_purpose_match, "/extract/test_limit_to_purpose_match"); + p11_test (test_limit_to_purpose_no_match, "/extract/test_limit_to_purpose_no_match"); + p11_test (test_duplicate_extract, "/extract/test_duplicate_extract"); + p11_test (test_duplicate_collapse, "/extract/test_duplicate_collapse"); + p11_test (test_trusted_match, "/extract/test_trusted_match"); + p11_test (test_distrust_match, "/extract/test_distrust_match"); + p11_test (test_anytrust_match, "/extract/test_anytrust_match"); + + return p11_test_run (argc, argv); } diff --git a/tools/tests/test-openssl.c b/tools/tests/test-openssl.c index c778aa7..d393072 100644 --- a/tools/tests/test-openssl.c +++ b/tools/tests/test-openssl.c @@ -35,7 +35,8 @@ #define P11_KIT_DISABLE_DEPRECATED #include "config.h" -#include "CuTest.h" +#include "test.h" +#include "test-tools.h" #include "attrs.h" #include "buffer.h" @@ -49,9 +50,9 @@ #include "pkcs11.h" #include "pkcs11x.h" #include "oid.h" -#include "test.h" #include +#include #include #include #include @@ -67,14 +68,14 @@ struct { } test; static void -setup (CuTest *tc) +setup (void *unused) { CK_RV rv; mock_module_reset (); memcpy (&test.module, &mock_module, sizeof (CK_FUNCTION_LIST)); rv = test.module.C_Initialize (NULL); - CuAssertIntEquals (tc, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); test.iter = p11_kit_iter_new (NULL); @@ -86,7 +87,7 @@ setup (CuTest *tc) } static void -teardown (CuTest *tc) +teardown (void *unused) { CK_RV rv; @@ -98,7 +99,7 @@ teardown (CuTest *tc) p11_kit_iter_free (test.iter); rv = test.module.C_Finalize (NULL); - CuAssertIntEquals (tc, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); } static CK_OBJECT_CLASS certificate_class = CKO_CERTIFICATE; @@ -162,12 +163,10 @@ setup_objects (const CK_ATTRIBUTE *attrs, } static void -test_file (CuTest *tc) +test_file (void) { bool ret; - setup (tc); - setup_objects (cacert3_authority_attrs, extension_eku_server, extension_reject_email, @@ -181,21 +180,19 @@ test_file (CuTest *tc) assert_not_reached (); ret = p11_extract_openssl_bundle (test.iter, &test.ex); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - test_check_file (tc, test.directory, "extract.pem", + test_check_file (test.directory, "extract.pem", SRCDIR "/files/cacert3-trusted-server-alias.pem"); free (test.ex.destination); - teardown (tc); } static void -test_plain (CuTest *tc) +test_plain (void) { bool ret; - setup (tc); setup_objects (cacert3_authority_attrs, NULL); p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL); @@ -206,17 +203,16 @@ test_plain (CuTest *tc) assert_not_reached (); ret = p11_extract_openssl_bundle (test.iter, &test.ex); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - test_check_file (tc, test.directory, "extract.pem", + test_check_file (test.directory, "extract.pem", SRCDIR "/files/cacert3-trusted-alias.pem"); free (test.ex.destination); - teardown (tc); } static void -test_keyid (CuTest *tc) +test_keyid (void) { bool ret; @@ -238,7 +234,6 @@ test_keyid (CuTest *tc) { CKA_INVALID }, }; - setup (tc); setup_objects (cacert3_plain, extension_subject_key_identifier, NULL); p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL); @@ -249,17 +244,16 @@ test_keyid (CuTest *tc) assert_not_reached (); ret = p11_extract_openssl_bundle (test.iter, &test.ex); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - test_check_file (tc, test.directory, "extract.pem", + test_check_file (test.directory, "extract.pem", SRCDIR "/files/cacert3-trusted-keyid.pem"); free (test.ex.destination); - teardown (tc); } static void -test_not_authority (CuTest *tc) +test_not_authority (void) { bool ret; @@ -271,7 +265,6 @@ test_not_authority (CuTest *tc) { CKA_INVALID }, }; - setup (tc); setup_objects (cacert3_not_trusted, NULL); p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL); @@ -282,17 +275,16 @@ test_not_authority (CuTest *tc) assert_not_reached (); ret = p11_extract_openssl_bundle (test.iter, &test.ex); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - test_check_file (tc, test.directory, "extract.pem", + test_check_file (test.directory, "extract.pem", SRCDIR "/files/cacert3-not-trusted.pem"); free (test.ex.destination); - teardown (tc); } static void -test_distrust_all (CuTest *tc) +test_distrust_all (void) { bool ret; @@ -305,8 +297,6 @@ test_distrust_all (CuTest *tc) { CKA_INVALID }, }; - setup (tc); - setup_objects (cacert3_blacklist, NULL); p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL); @@ -317,22 +307,19 @@ test_distrust_all (CuTest *tc) assert_not_reached (); ret = p11_extract_openssl_bundle (test.iter, &test.ex); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - test_check_file (tc, test.directory, "extract.pem", + test_check_file (test.directory, "extract.pem", SRCDIR "/files/cacert3-distrust-all.pem"); free (test.ex.destination); - teardown (tc); } static void -test_file_multiple (CuTest *tc) +test_file_multiple (void) { bool ret; - setup (tc); - setup_objects (cacert3_authority_attrs, extension_eku_server, extension_reject_email, @@ -349,22 +336,19 @@ test_file_multiple (CuTest *tc) assert_not_reached (); ret = p11_extract_openssl_bundle (test.iter, &test.ex); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - test_check_file (tc, test.directory, "extract.pem", + test_check_file (test.directory, "extract.pem", SRCDIR "/files/cacert3-trusted-multiple.pem"); free (test.ex.destination); - teardown (tc); } static void -test_file_without (CuTest *tc) +test_file_without (void) { bool ret; - setup (tc); - p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL); p11_kit_iter_add_filter (test.iter, certificate_filter, 1); p11_kit_iter_begin_with (test.iter, &test.module, 0, 0); @@ -373,19 +357,18 @@ test_file_without (CuTest *tc) assert_not_reached (); ret = p11_extract_openssl_bundle (test.iter, &test.ex); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - test_check_data (tc, test.directory, "extract.pem", "", 0); + test_check_data (test.directory, "extract.pem", "", 0); free (test.ex.destination); - teardown (tc); } /* From extract-openssl.c */ void p11_openssl_canon_string (char *str, size_t *len); static void -test_canon_string (CuTest *tc) +test_canon_string (void) { struct { char *input; @@ -418,8 +401,8 @@ test_canon_string (CuTest *tc) out = strlen (fixtures[i].output); else out = fixtures[i].output_len; - CuAssertIntEquals (tc, out, len); - CuAssertStrEquals (tc, fixtures[i].output, str); + assert_num_eq (out, len); + assert_str_eq (fixtures[i].output, str); free (str); } @@ -428,7 +411,7 @@ test_canon_string (CuTest *tc) bool p11_openssl_canon_string_der (p11_buffer *der); static void -test_canon_string_der (CuTest *tc) +test_canon_string_der (void) { struct { unsigned char input[100]; @@ -487,10 +470,10 @@ test_canon_string_der (CuTest *tc) fixtures[i].input_len, 0, realloc, free); ret = p11_openssl_canon_string_der (&buf); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - CuAssertIntEquals (tc, fixtures[i].output_len, buf.len); - CuAssertTrue (tc, memcmp (buf.data, fixtures[i].output, buf.len) == 0); + assert_num_eq (fixtures[i].output_len, buf.len); + assert (memcmp (buf.data, fixtures[i].output, buf.len) == 0); p11_buffer_uninit (&buf); } @@ -500,7 +483,7 @@ bool p11_openssl_canon_name_der (p11_dict *asn1_defs, p11_buffer *der); static void -test_canon_name_der (CuTest *tc) +test_canon_name_der (void) { struct { unsigned char input[100]; @@ -542,10 +525,10 @@ test_canon_name_der (CuTest *tc) fixtures[i].input_len, 0, realloc, free); ret = p11_openssl_canon_name_der (asn1_defs, &buf); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - CuAssertIntEquals (tc, fixtures[i].output_len, buf.len); - CuAssertTrue (tc, memcmp (buf.data, fixtures[i].output, buf.len) == 0); + assert_num_eq (fixtures[i].output_len, buf.len); + assert (memcmp (buf.data, fixtures[i].output, buf.len) == 0); p11_buffer_uninit (&buf); } @@ -554,7 +537,7 @@ test_canon_name_der (CuTest *tc) } static void -test_canon_string_der_fail (CuTest *tc) +test_canon_string_der_fail (void) { struct { unsigned char input[100]; @@ -574,19 +557,17 @@ test_canon_string_der_fail (CuTest *tc) fixtures[i].input_len, 0, realloc, free); ret = p11_openssl_canon_string_der (&buf); - CuAssertIntEquals (tc, false, ret); + assert_num_eq (false, ret); p11_buffer_uninit (&buf); } } static void -test_directory (CuTest *tc) +test_directory (void) { bool ret; - setup (tc); - setup_objects (cacert3_authority_attrs, extension_eku_server, extension_reject_email, @@ -605,33 +586,30 @@ test_directory (CuTest *tc) test.ex.destination = test.directory; ret = p11_extract_openssl_directory (test.iter, &test.ex); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - test_check_directory (tc, test.directory, ("Custom_Label.pem", "Custom_Label.1.pem", + test_check_directory (test.directory, ("Custom_Label.pem", "Custom_Label.1.pem", #ifdef OS_UNIX "e5662767.1", "e5662767.0", "590d426f.1", "590d426f.0", #endif NULL)); - test_check_file (tc, test.directory, "Custom_Label.pem", + test_check_file (test.directory, "Custom_Label.pem", SRCDIR "/files/cacert3-trusted-server-alias.pem"); - test_check_file (tc, test.directory, "Custom_Label.1.pem", + test_check_file (test.directory, "Custom_Label.1.pem", SRCDIR "/files/cacert3-trusted-alias.pem"); #ifdef OS_UNIX - test_check_symlink (tc, test.directory, "e5662767.0", "Custom_Label.pem"); - test_check_symlink (tc, test.directory, "e5662767.1", "Custom_Label.1.pem"); - test_check_symlink (tc, test.directory, "590d426f.0", "Custom_Label.pem"); - test_check_symlink (tc, test.directory, "590d426f.1", "Custom_Label.1.pem"); + test_check_symlink (test.directory, "e5662767.0", "Custom_Label.pem"); + test_check_symlink (test.directory, "e5662767.1", "Custom_Label.1.pem"); + test_check_symlink (test.directory, "590d426f.0", "Custom_Label.pem"); + test_check_symlink (test.directory, "590d426f.1", "Custom_Label.1.pem"); #endif - teardown (tc); } static void -test_directory_empty (CuTest *tc) +test_directory_empty (void) { bool ret; - setup (tc); - p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL); p11_kit_iter_add_filter (test.iter, certificate_filter, 1); p11_kit_iter_begin_with (test.iter, &test.module, 0, 0); @@ -642,47 +620,35 @@ test_directory_empty (CuTest *tc) test.ex.destination = test.directory; ret = p11_extract_openssl_directory (test.iter, &test.ex); - CuAssertIntEquals (tc, true, ret); - - test_check_directory (tc, test.directory, (NULL, NULL)); + assert_num_eq (true, ret); - teardown (tc); + test_check_directory (test.directory, (NULL, NULL)); } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - putenv ("P11_KIT_STRICT=1"); mock_module_init (); - p11_debug_init (); - - SUITE_ADD_TEST (suite, test_file); - SUITE_ADD_TEST (suite, test_plain); - SUITE_ADD_TEST (suite, test_keyid); - SUITE_ADD_TEST (suite, test_not_authority); - SUITE_ADD_TEST (suite, test_distrust_all); - SUITE_ADD_TEST (suite, test_file_multiple); - SUITE_ADD_TEST (suite, test_file_without); - - SUITE_ADD_TEST (suite, test_canon_string); - SUITE_ADD_TEST (suite, test_canon_string_der); - SUITE_ADD_TEST (suite, test_canon_string_der_fail); - SUITE_ADD_TEST (suite, test_canon_name_der); - - SUITE_ADD_TEST (suite, test_directory); - SUITE_ADD_TEST (suite, test_directory_empty); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + + p11_fixture (setup, teardown); + p11_test (test_file, "/openssl/test_file"); + p11_test (test_plain, "/openssl/test_plain"); + p11_test (test_keyid, "/openssl/test_keyid"); + p11_test (test_not_authority, "/openssl/test_not_authority"); + p11_test (test_distrust_all, "/openssl/test_distrust_all"); + p11_test (test_file_multiple, "/openssl/test_file_multiple"); + p11_test (test_file_without, "/openssl/test_file_without"); + + p11_fixture (NULL, NULL); + p11_test (test_canon_string, "/openssl/test_canon_string"); + p11_test (test_canon_string_der, "/openssl/test_canon_string_der"); + p11_test (test_canon_string_der_fail, "/openssl/test_canon_string_der_fail"); + p11_test (test_canon_name_der, "/openssl/test_canon_name_der"); + + p11_fixture (setup, teardown); + p11_test (test_directory, "/openssl/test_directory"); + p11_test (test_directory_empty, "/openssl/test_directory_empty"); + + return p11_test_run (argc, argv); } diff --git a/tools/tests/test-pem.c b/tools/tests/test-pem.c index 4024bac..c74d0df 100644 --- a/tools/tests/test-pem.c +++ b/tools/tests/test-pem.c @@ -35,7 +35,8 @@ #define P11_KIT_DISABLE_DEPRECATED #include "config.h" -#include "CuTest.h" +#include "test.h" +#include "test-tools.h" #include "attrs.h" #include "compat.h" @@ -48,7 +49,6 @@ #include "pkcs11.h" #include "pkcs11x.h" #include "oid.h" -#include "test.h" #include #include @@ -64,14 +64,14 @@ struct { } test; static void -setup (CuTest *tc) +setup (void *unused) { CK_RV rv; mock_module_reset (); memcpy (&test.module, &mock_module, sizeof (CK_FUNCTION_LIST)); rv = test.module.C_Initialize (NULL); - CuAssertIntEquals (tc, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); test.iter = p11_kit_iter_new (NULL); @@ -83,7 +83,7 @@ setup (CuTest *tc) } static void -teardown (CuTest *tc) +teardown (void *unused) { CK_RV rv; @@ -95,7 +95,7 @@ teardown (CuTest *tc) p11_kit_iter_free (test.iter); rv = test.module.C_Finalize (NULL); - CuAssertIntEquals (tc, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); } static CK_OBJECT_CLASS certificate_class = CKO_CERTIFICATE; @@ -117,12 +117,10 @@ static CK_ATTRIBUTE certificate_filter[] = { }; static void -test_file (CuTest *tc) +test_file (void) { bool ret; - setup (tc); - mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_authority_attrs); p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL); @@ -133,21 +131,18 @@ test_file (CuTest *tc) assert_not_reached (); ret = p11_extract_pem_bundle (test.iter, &test.ex); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - test_check_file (tc, test.directory, "extract.pem", SRCDIR "/files/cacert3.pem"); + test_check_file (test.directory, "extract.pem", SRCDIR "/files/cacert3.pem"); free (test.ex.destination); - teardown (tc); } static void -test_file_multiple (CuTest *tc) +test_file_multiple (void) { bool ret; - setup (tc); - mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_authority_attrs); mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_authority_attrs); @@ -159,21 +154,18 @@ test_file_multiple (CuTest *tc) assert_not_reached (); ret = p11_extract_pem_bundle (test.iter, &test.ex); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - test_check_file (tc, test.directory, "extract.pem", SRCDIR "/files/cacert3-twice.pem"); + test_check_file (test.directory, "extract.pem", SRCDIR "/files/cacert3-twice.pem"); free (test.ex.destination); - teardown (tc); } static void -test_file_without (CuTest *tc) +test_file_without (void) { bool ret; - setup (tc); - p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL); p11_kit_iter_add_filter (test.iter, certificate_filter, 1); p11_kit_iter_begin_with (test.iter, &test.module, 0, 0); @@ -182,21 +174,18 @@ test_file_without (CuTest *tc) assert_not_reached (); ret = p11_extract_pem_bundle (test.iter, &test.ex); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - test_check_data (tc, test.directory, "extract.pem", "", 0); + test_check_data (test.directory, "extract.pem", "", 0); free (test.ex.destination); - teardown (tc); } static void -test_directory (CuTest *tc) +test_directory (void) { bool ret; - setup (tc); - mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_authority_attrs); mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_authority_attrs); @@ -210,22 +199,18 @@ test_directory (CuTest *tc) test.ex.destination = test.directory; ret = p11_extract_pem_directory (test.iter, &test.ex); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - test_check_directory (tc, test.directory, ("Cacert3_Here.pem", "Cacert3_Here.1.pem", NULL)); - test_check_file (tc, test.directory, "Cacert3_Here.pem", SRCDIR "/files/cacert3.pem"); - test_check_file (tc, test.directory, "Cacert3_Here.1.pem", SRCDIR "/files/cacert3.pem"); - - teardown (tc); + test_check_directory (test.directory, ("Cacert3_Here.pem", "Cacert3_Here.1.pem", NULL)); + test_check_file (test.directory, "Cacert3_Here.pem", SRCDIR "/files/cacert3.pem"); + test_check_file (test.directory, "Cacert3_Here.1.pem", SRCDIR "/files/cacert3.pem"); } static void -test_directory_empty (CuTest *tc) +test_directory_empty (void) { bool ret; - setup (tc); - p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL); p11_kit_iter_add_filter (test.iter, certificate_filter, 1); p11_kit_iter_begin_with (test.iter, &test.module, 0, 0); @@ -236,37 +221,22 @@ test_directory_empty (CuTest *tc) test.ex.destination = test.directory; ret = p11_extract_pem_directory (test.iter, &test.ex); - CuAssertIntEquals (tc, true, ret); - - test_check_directory (tc, test.directory, (NULL, NULL)); + assert_num_eq (true, ret); - teardown (tc); + test_check_directory (test.directory, (NULL, NULL)); } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - putenv ("P11_KIT_STRICT=1"); mock_module_init (); - p11_debug_init (); - - SUITE_ADD_TEST (suite, test_file); - SUITE_ADD_TEST (suite, test_file_multiple); - SUITE_ADD_TEST (suite, test_file_without); - SUITE_ADD_TEST (suite, test_directory); - SUITE_ADD_TEST (suite, test_directory_empty); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + + p11_fixture (setup, teardown); + p11_test (test_file, "/pem/test_file"); + p11_test (test_file_multiple, "/pem/test_file_multiple"); + p11_test (test_file_without, "/pem/test_file_without"); + p11_test (test_directory, "/pem/test_directory"); + p11_test (test_directory_empty, "/pem/test_directory_empty"); + return p11_test_run (argc, argv); } diff --git a/tools/tests/test-save.c b/tools/tests/test-save.c index b739c21..93af4f9 100644 --- a/tools/tests/test-save.c +++ b/tools/tests/test-save.c @@ -33,7 +33,8 @@ */ #include "config.h" -#include "CuTest.h" +#include "test.h" +#include "test-tools.h" #include "attrs.h" #include "compat.h" @@ -42,7 +43,6 @@ #include "message.h" #include "path.h" #include "save.h" -#include "test.h" #include #include @@ -61,24 +61,23 @@ struct { } test; static void -setup (CuTest *tc) +setup (void *unused) { test.directory = p11_path_expand ("$TEMP/test-extract.XXXXXX"); if (!mkdtemp (test.directory)) - CuFail (tc, "mkdtemp() failed"); + assert_fail ("mkdtemp() failed", strerror (errno)); } static void -teardown (CuTest *tc) +teardown (void *unused) { if (rmdir (test.directory) < 0) - CuFail (tc, strerror (errno)); + assert_fail ("rmdir() failed", strerror (errno)); free (test.directory); } static void -write_zero_file (CuTest *tc, - const char *directory, +write_zero_file (const char *directory, const char *name) { char *filename; @@ -86,409 +85,365 @@ write_zero_file (CuTest *tc, int fd; if (asprintf (&filename, "%s/%s", directory, name) < 0) - CuFail (tc, "asprintf() failed"); + assert_not_reached (); fd = open (filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); - CuAssertTrue (tc, fd != -1); + assert (fd != -1); res = close (fd); - CuAssertTrue (tc, res >= 0); + assert (res >= 0); free (filename); } static void -test_file_write (CuTest *tc) +test_file_write (void) { p11_save_file *file; char *filename; bool ret; - setup (tc); - if (asprintf (&filename, "%s/%s", test.directory, "extract-file") < 0) - CuFail (tc, "asprintf() failed"); + assert_not_reached (); file = p11_save_open_file (filename, 0); - CuAssertPtrNotNull (tc, file); + assert_ptr_not_null (file); ret = p11_save_write_and_finish (file, test_cacert3_ca_der, sizeof (test_cacert3_ca_der)); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); free (filename); - test_check_file (tc, test.directory, "extract-file", SRCDIR "/files/cacert3.der"); - - teardown (tc); + test_check_file (test.directory, "extract-file", SRCDIR "/files/cacert3.der"); } static void -test_file_exists (CuTest *tc) +test_file_exists (void) { p11_save_file *file; char *filename; - setup (tc); - if (asprintf (&filename, "%s/%s", test.directory, "extract-file") < 0) - CuFail (tc, "asprintf() failed"); + assert_not_reached (); - write_zero_file (tc, test.directory, "extract-file"); + write_zero_file (test.directory, "extract-file"); p11_message_quiet (); file = p11_save_open_file (filename, 0); - CuAssertTrue (tc, file == NULL); + assert (file == NULL); p11_message_loud (); unlink (filename); free (filename); - teardown (tc); } static void -test_file_bad_directory (CuTest *tc) +test_file_bad_directory (void) { p11_save_file *file; char *filename; - setup (tc); - if (asprintf (&filename, "/non-existent/%s/%s", test.directory, "extract-file") < 0) - CuFail (tc, "asprintf() failed"); + assert_not_reached (); p11_message_quiet (); file = p11_save_open_file (filename, 0); - CuAssertTrue (tc, file == NULL); + assert (file == NULL); p11_message_loud (); free (filename); - teardown (tc); } static void -test_file_overwrite (CuTest *tc) +test_file_overwrite (void) { p11_save_file *file; char *filename; bool ret; - setup (tc); - if (asprintf (&filename, "%s/%s", test.directory, "extract-file") < 0) - CuFail (tc, "asprintf() failed"); + assert_not_reached (); - write_zero_file (tc, test.directory, "extract-file"); + write_zero_file (test.directory, "extract-file"); file = p11_save_open_file (filename, P11_SAVE_OVERWRITE); - CuAssertPtrNotNull (tc, file); + assert_ptr_not_null (file); ret = p11_save_write_and_finish (file, test_cacert3_ca_der, sizeof (test_cacert3_ca_der)); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); free (filename); - test_check_file (tc, test.directory, "extract-file", SRCDIR "/files/cacert3.der"); - - teardown (tc); + test_check_file (test.directory, "extract-file", SRCDIR "/files/cacert3.der"); } static void -test_file_auto_empty (CuTest *tc) +test_file_auto_empty (void) { p11_save_file *file; char *filename; bool ret; - setup (tc); - if (asprintf (&filename, "%s/%s", test.directory, "extract-file") < 0) - CuFail (tc, "asprintf() failed"); + assert_not_reached (); file = p11_save_open_file (filename, 0); - CuAssertPtrNotNull (tc, file); + assert_ptr_not_null (file); ret = p11_save_write_and_finish (file, NULL, -1); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); free (filename); - test_check_file (tc, test.directory, "extract-file", SRCDIR "/files/empty-file"); - - teardown (tc); + test_check_file (test.directory, "extract-file", SRCDIR "/files/empty-file"); } static void -test_file_auto_length (CuTest *tc) +test_file_auto_length (void) { p11_save_file *file; char *filename; bool ret; - setup (tc); - if (asprintf (&filename, "%s/%s", test.directory, "extract-file") < 0) - CuFail (tc, "asprintf() failed"); + assert_not_reached (); file = p11_save_open_file (filename, 0); - CuAssertPtrNotNull (tc, file); + assert_ptr_not_null (file); ret = p11_save_write_and_finish (file, "The simple string is hairy", -1); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); free (filename); - test_check_file (tc, test.directory, "extract-file", SRCDIR "/files/simple-string"); - - teardown (tc); + test_check_file (test.directory, "extract-file", SRCDIR "/files/simple-string"); } static void -test_write_with_null (CuTest *tc) +test_write_with_null (void) { bool ret; ret = p11_save_write (NULL, "test", 4); - CuAssertIntEquals (tc, false, ret); + assert_num_eq (false, ret); } static void -test_write_and_finish_with_null (CuTest *tc) +test_write_and_finish_with_null (void) { bool ret; ret = p11_save_write_and_finish (NULL, "test", 4); - CuAssertIntEquals (tc, false, ret); + assert_num_eq (false, ret); } static void -test_file_abort (CuTest *tc) +test_file_abort (void) { struct stat st; p11_save_file *file; char *filename; bool ret; - setup (tc); - if (asprintf (&filename, "%s/%s", test.directory, "extract-file") < 0) - CuFail (tc, "asprintf() failed"); + assert_not_reached (); file = p11_save_open_file (filename, 0); - CuAssertPtrNotNull (tc, file); + assert_ptr_not_null (file); ret = p11_save_finish_file (file, false); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); if (stat (filename, &st) >= 0 || errno != ENOENT) - CuFail (tc, "file should not exist"); + assert_fail ("file should not exist", filename); free (filename); - - teardown (tc); } static void -test_directory_empty (CuTest *tc) +test_directory_empty (void) { p11_save_dir *dir; char *subdir; bool ret; - setup (tc); - if (asprintf (&subdir, "%s/%s", test.directory, "extract-dir") < 0) - CuFail (tc, "asprintf() failed"); + assert_not_reached (); dir = p11_save_open_directory (subdir, 0); - CuAssertPtrNotNull (tc, dir); + assert_ptr_not_null (dir); ret = p11_save_finish_directory (dir, true); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - test_check_directory (tc, subdir, (NULL, NULL)); + test_check_directory (subdir, (NULL, NULL)); - CuAssertTrue (tc, rmdir (subdir) >= 0); + assert (rmdir (subdir) >= 0); free (subdir); - - teardown (tc); } static void -test_directory_files (CuTest *tc) +test_directory_files (void) { const char *filename; p11_save_dir *dir; char *subdir; bool ret; - setup (tc); - if (asprintf (&subdir, "%s/%s", test.directory, "extract-dir") < 0) - CuFail (tc, "asprintf() failed"); + assert_not_reached (); dir = p11_save_open_directory (subdir, 0); - CuAssertPtrNotNull (tc, dir); + assert_ptr_not_null (dir); ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "blah", ".cer", &filename), test_cacert3_ca_der, sizeof (test_cacert3_ca_der)); - CuAssertIntEquals (tc, true, ret); - CuAssertStrEquals (tc, "blah.cer", filename); + assert_num_eq (true, ret); + assert_str_eq ("blah.cer", filename); ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "file", ".txt", &filename), test_text, strlen (test_text)); - CuAssertIntEquals (tc, true, ret); - CuAssertStrEquals (tc, "file.txt", filename); + assert_num_eq (true, ret); + assert_str_eq ("file.txt", filename); #ifdef OS_UNIX ret = p11_save_symlink_in (dir, "link", ".ext", "/the/destination"); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); #endif ret = p11_save_finish_directory (dir, true); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - test_check_directory (tc, subdir, ("blah.cer", "file.txt", + test_check_directory (subdir, ("blah.cer", "file.txt", #ifdef OS_UNIX "link.ext", #endif NULL)); - test_check_file (tc, subdir, "blah.cer", SRCDIR "/files/cacert3.der"); - test_check_data (tc, subdir, "file.txt", test_text, strlen (test_text)); + test_check_file (subdir, "blah.cer", SRCDIR "/files/cacert3.der"); + test_check_data (subdir, "file.txt", test_text, strlen (test_text)); #ifdef OS_UNIX - test_check_symlink (tc, subdir, "link.ext", "/the/destination"); + test_check_symlink (subdir, "link.ext", "/the/destination"); #endif - CuAssertTrue (tc, rmdir (subdir) >= 0); + assert (rmdir (subdir) >= 0); free (subdir); - - teardown (tc); } static void -test_directory_dups (CuTest *tc) +test_directory_dups (void) { const char *filename; p11_save_dir *dir; char *subdir; bool ret; - setup (tc); - if (asprintf (&subdir, "%s/%s", test.directory, "extract-dir") < 0) - CuFail (tc, "asprintf() failed"); + assert_not_reached (); dir = p11_save_open_directory (subdir, 0); - CuAssertPtrNotNull (tc, dir); + assert_ptr_not_null (dir); ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "file", ".txt", &filename), test_text, 5); - CuAssertIntEquals (tc, true, ret); - CuAssertStrEquals (tc, "file.txt", filename); + assert_num_eq (true, ret); + assert_str_eq ("file.txt", filename); ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "file", ".txt", &filename), test_text, 10); - CuAssertIntEquals (tc, true, ret); - CuAssertStrEquals (tc, "file.1.txt", filename); + assert_num_eq (true, ret); + assert_str_eq ("file.1.txt", filename); ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "file", ".txt", NULL), test_text, 15); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "no-ext", NULL, NULL), test_text, 8); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "no-ext", NULL, NULL), test_text, 16); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "with-num", ".0", NULL), test_text, 14); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "with-num", ".0", NULL), test_text, 15); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); #ifdef OS_UNIX ret = p11_save_symlink_in (dir, "link", ".0", "/destination1"); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); ret = p11_save_symlink_in (dir, "link", ".0", "/destination2"); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); #endif ret = p11_save_finish_directory (dir, true); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - test_check_directory (tc, subdir, ("file.txt", "file.1.txt", "file.2.txt", + test_check_directory (subdir, ("file.txt", "file.1.txt", "file.2.txt", "no-ext", "no-ext.1", "with-num.0", "with-num.1", #ifdef OS_UNIX "link.0", "link.1", #endif NULL)); - test_check_data (tc, subdir, "file.txt", test_text, 5); - test_check_data (tc, subdir, "file.1.txt", test_text, 10); - test_check_data (tc, subdir, "file.2.txt", test_text, 15); - test_check_data (tc, subdir, "no-ext", test_text, 8); - test_check_data (tc, subdir, "no-ext.1", test_text, 16); - test_check_data (tc, subdir, "with-num.0", test_text, 14); - test_check_data (tc, subdir, "with-num.1", test_text, 15); + test_check_data (subdir, "file.txt", test_text, 5); + test_check_data (subdir, "file.1.txt", test_text, 10); + test_check_data (subdir, "file.2.txt", test_text, 15); + test_check_data (subdir, "no-ext", test_text, 8); + test_check_data (subdir, "no-ext.1", test_text, 16); + test_check_data (subdir, "with-num.0", test_text, 14); + test_check_data (subdir, "with-num.1", test_text, 15); #ifdef OS_UNIX - test_check_symlink (tc, subdir, "link.0", "/destination1"); - test_check_symlink (tc, subdir, "link.1", "/destination2"); + test_check_symlink (subdir, "link.0", "/destination1"); + test_check_symlink (subdir, "link.1", "/destination2"); #endif - CuAssertTrue (tc, rmdir (subdir) >= 0); + assert (rmdir (subdir) >= 0); free (subdir); - - teardown (tc); } static void -test_directory_exists (CuTest *tc) +test_directory_exists (void) { p11_save_dir *dir; char *subdir; - setup (tc); - if (asprintf (&subdir, "%s/%s", test.directory, "extract-dir") < 0) - CuFail (tc, "asprintf() failed"); + assert_not_reached (); #ifdef OS_UNIX if (mkdir (subdir, S_IRWXU) < 0) #else if (mkdir (subdir) < 0) #endif - CuFail (tc, "mkdir() failed"); + assert_fail ("mkdir() failed", subdir); p11_message_quiet (); dir = p11_save_open_directory (subdir, 0); - CuAssertPtrEquals (tc, NULL, dir); + assert_ptr_eq (NULL, dir); p11_message_loud (); rmdir (subdir); free (subdir); - - teardown (tc); } static void -test_directory_overwrite (CuTest *tc) +test_directory_overwrite (void) { const char *filename; p11_save_dir *dir; char *subdir; bool ret; - setup (tc); - if (asprintf (&subdir, "%s/%s", test.directory, "extract-dir") < 0) - CuFail (tc, "asprintf() failed"); + assert_not_reached (); /* Some initial files into this directory, which get overwritten */ dir = p11_save_open_directory (subdir, 0); @@ -496,74 +451,62 @@ test_directory_overwrite (CuTest *tc) p11_save_write_and_finish (p11_save_open_file_in (dir, "another-file", NULL, NULL), "", 0) && p11_save_write_and_finish (p11_save_open_file_in (dir, "third-file", NULL, NULL), "", 0) && p11_save_finish_directory (dir, true); - CuAssertTrue (tc, ret && dir); + assert (ret && dir); /* Now the actual test, using the same directory */ dir = p11_save_open_directory (subdir, P11_SAVE_OVERWRITE); - CuAssertPtrNotNull (tc, dir); + assert_ptr_not_null (dir); ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "blah", ".cer", &filename), test_cacert3_ca_der, sizeof (test_cacert3_ca_der)); - CuAssertIntEquals (tc, true, ret); - CuAssertStrEquals (tc, "blah.cer", filename); + assert_num_eq (true, ret); + assert_str_eq ("blah.cer", filename); ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "file", ".txt", &filename), test_text, strlen (test_text)); - CuAssertIntEquals (tc, true, ret); - CuAssertStrEquals (tc, "file.txt", filename); + assert_num_eq (true, ret); + assert_str_eq ("file.txt", filename); ret = p11_save_write_and_finish (p11_save_open_file_in (dir, "file", ".txt", &filename), test_text, 10); - CuAssertIntEquals (tc, true, ret); - CuAssertStrEquals (tc, "file.1.txt", filename); + assert_num_eq (true, ret); + assert_str_eq ("file.1.txt", filename); ret = p11_save_finish_directory (dir, true); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - test_check_directory (tc, subdir, ("blah.cer", "file.txt", "file.1.txt", NULL)); - test_check_data (tc, subdir, "blah.cer", test_cacert3_ca_der, sizeof (test_cacert3_ca_der)); - test_check_data (tc, subdir, "file.txt", test_text, strlen (test_text)); - test_check_data (tc, subdir, "file.1.txt", test_text, 10); + test_check_directory (subdir, ("blah.cer", "file.txt", "file.1.txt", NULL)); + test_check_data (subdir, "blah.cer", test_cacert3_ca_der, sizeof (test_cacert3_ca_der)); + test_check_data (subdir, "file.txt", test_text, strlen (test_text)); + test_check_data (subdir, "file.1.txt", test_text, 10); - CuAssertTrue (tc, rmdir (subdir) >= 0); + assert (rmdir (subdir) >= 0); free (subdir); - - teardown (tc); } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - putenv ("P11_KIT_STRICT=1"); - p11_debug_init (); - - SUITE_ADD_TEST (suite, test_file_write); - SUITE_ADD_TEST (suite, test_file_exists); - SUITE_ADD_TEST (suite, test_file_bad_directory); - SUITE_ADD_TEST (suite, test_file_overwrite); - SUITE_ADD_TEST (suite, test_file_auto_empty); - SUITE_ADD_TEST (suite, test_file_auto_length); - SUITE_ADD_TEST (suite, test_write_with_null); - SUITE_ADD_TEST (suite, test_write_and_finish_with_null); - SUITE_ADD_TEST (suite, test_file_abort); - - SUITE_ADD_TEST (suite, test_directory_empty); - SUITE_ADD_TEST (suite, test_directory_files); - SUITE_ADD_TEST (suite, test_directory_dups); - SUITE_ADD_TEST (suite, test_directory_exists); - SUITE_ADD_TEST (suite, test_directory_overwrite); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + p11_fixture (setup, teardown); + p11_test (test_file_write, "/save/test_file_write"); + p11_test (test_file_exists, "/save/test_file_exists"); + p11_test (test_file_bad_directory, "/save/test_file_bad_directory"); + p11_test (test_file_overwrite, "/save/test_file_overwrite"); + p11_test (test_file_auto_empty, "/save/test_file_auto_empty"); + p11_test (test_file_auto_length, "/save/test_file_auto_length"); + + p11_fixture (NULL, NULL); + p11_test (test_write_with_null, "/save/test_write_with_null"); + p11_test (test_write_and_finish_with_null, "/save/test_write_and_finish_with_null"); + + p11_fixture (setup, teardown); + p11_test (test_file_abort, "/save/test_file_abort"); + + p11_test (test_directory_empty, "/save/test_directory_empty"); + p11_test (test_directory_files, "/save/test_directory_files"); + p11_test (test_directory_dups, "/save/test_directory_dups"); + p11_test (test_directory_exists, "/save/test_directory_exists"); + p11_test (test_directory_overwrite, "/save/test_directory_overwrite"); + return p11_test_run (argc, argv); } diff --git a/tools/tests/test-tools.c b/tools/tests/test-tools.c new file mode 100644 index 0000000..0c8b624 --- /dev/null +++ b/tools/tests/test-tools.c @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2013, Red Hat Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * * The names of contributors to this software may not be + * used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * Author: Stef Walter + */ + +#include "config.h" +#include "test.h" + +#include "debug.h" +#include "test-tools.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static char * +read_file (const char *file, + int line, + const char *function, + const char *filename, + long *len) +{ + struct stat sb; + FILE *f = NULL; + char *data; + + f = fopen (filename, "rb"); + if (f == NULL) + p11_test_fail (file, line, function, "Couldn't open file: %s", filename); + + /* Figure out size */ + if (stat (filename, &sb) < 0) + p11_test_fail (file, line, function, "Couldn't stat file: %s", filename); + + *len = sb.st_size; + data = malloc (*len ? *len : 1); + assert (data != NULL); + + /* And read in one block */ + if (fread (data, 1, *len, f) != *len) + p11_test_fail (file, line, function, "Couldn't read file: %s", filename); + + fclose (f); + + return data; +} + +void +test_check_file_msg (const char *file, + int line, + const char *function, + const char *directory, + const char *name, + const char *reference) +{ + char *refdata; + long reflen; + + refdata = read_file (file, line, function, reference, &reflen); + test_check_data_msg (file, line, function, directory, name, refdata, reflen); + free (refdata); +} + +void +test_check_data_msg (const char *file, + int line, + const char *function, + const char *directory, + const char *name, + const void *refdata, + long reflen) +{ + char *filedata; + char *filename; + long filelen; + + if (asprintf (&filename, "%s/%s", directory, name) < 0) + assert_not_reached (); + + filedata = read_file (file, line, function, filename, &filelen); + + if (filelen != reflen || memcmp (filedata, refdata, reflen) != 0) + p11_test_fail (file, line, function, "File contents not as expected: %s", filename); + + if (unlink (filename) < 0) + p11_test_fail (file, line, function, "Couldn't remove file: %s", filename); + free (filename); + free (filedata); +} + +#ifdef OS_UNIX + +void +test_check_symlink_msg (const char *file, + int line, + const char *function, + const char *directory, + const char *name, + const char *destination) +{ + char buf[1024] = { 0, }; + char *filename; + + if (asprintf (&filename, "%s/%s", directory, name) < 0) + assert_not_reached (); + + if (readlink (filename, buf, sizeof (buf)) < 0) + p11_test_fail (file, line, function, "Couldn't read symlink: %s", filename); + + if (strcmp (destination, buf) != 0) + p11_test_fail (file, line, function, "Symlink contents wrong: %s != %s", destination, buf); + + if (unlink (filename) < 0) + p11_test_fail (file, line, function, "Couldn't remove symlink: %s", filename); + free (filename); +} + +#endif /* OS_UNIX */ + +p11_dict * +test_check_directory_files (const char *file, + ...) +{ + p11_dict *files; + va_list va; + + files = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, NULL, NULL); + + va_start (va, file); + + while (file != NULL) { + if (!p11_dict_set (files, (void *)file, (void *)file)) + return_val_if_reached (NULL); + file = va_arg (va, const char *); + } + + va_end (va); + + return files; +} + +void +test_check_directory_msg (const char *file, + int line, + const char *function, + const char *directory, + p11_dict *files) +{ + p11_dictiter iter; + struct dirent *dp; + const char *name; + DIR *dir; + + dir = opendir (directory); + if (dir == NULL) + p11_test_fail (file ,line, function, "Couldn't open directory: %s", directory); + + while ((dp = readdir (dir)) != NULL) { + if (strcmp (dp->d_name, ".") == 0 || + strcmp (dp->d_name, "..") == 0) + continue; + + if (!p11_dict_remove (files, dp->d_name)) + p11_test_fail (file, line, function, "Unexpected file in directory: %s", dp->d_name); + } + + closedir (dir); + +#ifdef OS_UNIX + if (chmod (directory, S_IRWXU) < 0) + p11_test_fail (file, line, function, "couldn't chown directory: %s: %s", directory, strerror (errno)); +#endif + + p11_dict_iterate (files, &iter); + while (p11_dict_next (&iter, (void **)&name, NULL)) + p11_test_fail (file, line, function, "Couldn't find file in directory: %s", name); + + p11_dict_free (files); +} diff --git a/tools/tests/test-tools.h b/tools/tests/test-tools.h new file mode 100644 index 0000000..8e66c54 --- /dev/null +++ b/tools/tests/test-tools.h @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2013, Red Hat Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * * The names of contributors to this software may not be + * used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * Author: Stef Walter + */ + +#ifndef TEST_COMMON_H_ +#define TEST_COMMON_H_ + +#include "test.h" + +#include "dict.h" + +#include + +static const char test_text[] = "This is the file text"; + +static const unsigned char test_cacert3_ca_der[] = { + 0x30, 0x82, 0x07, 0x59, 0x30, 0x82, 0x05, 0x41, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x03, 0x0a, + 0x41, 0x8a, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, + 0x00, 0x30, 0x79, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x07, 0x52, 0x6f, + 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x15, + 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x63, 0x61, 0x63, 0x65, 0x72, + 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x31, 0x22, 0x30, 0x20, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x19, + 0x43, 0x41, 0x20, 0x43, 0x65, 0x72, 0x74, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x69, 0x6e, 0x67, 0x20, + 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x12, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, + 0x74, 0x40, 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x30, 0x1e, 0x17, 0x0d, + 0x31, 0x31, 0x30, 0x35, 0x32, 0x33, 0x31, 0x37, 0x34, 0x38, 0x30, 0x32, 0x5a, 0x17, 0x0d, 0x32, + 0x31, 0x30, 0x35, 0x32, 0x30, 0x31, 0x37, 0x34, 0x38, 0x30, 0x32, 0x5a, 0x30, 0x54, 0x31, 0x14, + 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0b, 0x43, 0x41, 0x63, 0x65, 0x72, 0x74, 0x20, + 0x49, 0x6e, 0x63, 0x2e, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x15, 0x68, + 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x43, 0x41, 0x63, 0x65, 0x72, 0x74, + 0x2e, 0x6f, 0x72, 0x67, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x13, 0x43, + 0x41, 0x63, 0x65, 0x72, 0x74, 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x33, 0x20, 0x52, 0x6f, + 0x6f, 0x74, 0x30, 0x82, 0x02, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, + 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x02, 0x0f, 0x00, 0x30, 0x82, 0x02, 0x0a, 0x02, 0x82, + 0x02, 0x01, 0x00, 0xab, 0x49, 0x35, 0x11, 0x48, 0x7c, 0xd2, 0x26, 0x7e, 0x53, 0x94, 0xcf, 0x43, + 0xa9, 0xdd, 0x28, 0xd7, 0x42, 0x2a, 0x8b, 0xf3, 0x87, 0x78, 0x19, 0x58, 0x7c, 0x0f, 0x9e, 0xda, + 0x89, 0x7d, 0xe1, 0xfb, 0xeb, 0x72, 0x90, 0x0d, 0x74, 0xa1, 0x96, 0x64, 0xab, 0x9f, 0xa0, 0x24, + 0x99, 0x73, 0xda, 0xe2, 0x55, 0x76, 0xc7, 0x17, 0x7b, 0xf5, 0x04, 0xac, 0x46, 0xb8, 0xc3, 0xbe, + 0x7f, 0x64, 0x8d, 0x10, 0x6c, 0x24, 0xf3, 0x61, 0x9c, 0xc0, 0xf2, 0x90, 0xfa, 0x51, 0xe6, 0xf5, + 0x69, 0x01, 0x63, 0xc3, 0x0f, 0x56, 0xe2, 0x4a, 0x42, 0xcf, 0xe2, 0x44,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74, 0x11, 0xe0, 0x6d, 0xb1, 0x2c, 0x3f, + 0x2c, 0x86, 0x91, 0x99, 0x71, 0x9a, 0xa6, 0x77, 0x8b, 0x34, 0x60, 0xd1, 0x14, 0xb4, 0x2c, 0xac, + 0x9d, 0xaf, 0x8c, 0x10, 0xd3, 0x9f, 0xc4, 0x6a, 0xf8, 0x6f, 0x13, 0xfc, 0x73, 0x59, 0xf7, 0x66, + 0x42, 0x74, 0x1e, 0x8a, 0xe3, 0xf8, 0xdc, 0xd2, 0x6f, 0x98, 0x9c, 0xcb, 0x47, 0x98, 0x95, 0x40, + 0x05, 0xfb, 0xe9, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, 0x02, 0x0d, 0x30, 0x82, 0x02, 0x09, + 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x75, 0xa8, 0x71, 0x60, 0x4c, + 0x88, 0x13, 0xf0, 0x78, 0xd9, 0x89, 0x77, 0xb5, 0x6d, 0xc5, 0x89, 0xdf, 0xbc, 0xb1, 0x7a, 0x30, + 0x81, 0xa3, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x81, 0x9b, 0x30, 0x81, 0x98, 0x80, 0x14, 0x16, + 0xb5, 0x32, 0x1b, 0xd4, 0xc7, 0xf3, 0xe0, 0xe6, 0x8e, 0xf3, 0xbd, 0xd2, 0xb0, 0x3a, 0xee, 0xb2, + 0x39, 0x18, 0xd1, 0xa1, 0x7d, 0xa4, 0x7b, 0x30, 0x79, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, + 0x04, 0x0a, 0x13, 0x07, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1e, 0x30, 0x1c, 0x06, + 0x03, 0x55, 0x04, 0x0b, 0x13, 0x15, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, + 0x2e, 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x31, 0x22, 0x30, 0x20, 0x06, + 0x03, 0x55, 0x04, 0x03, 0x13, 0x19, 0x43, 0x41, 0x20, 0x43, 0x65, 0x72, 0x74, 0x20, 0x53, 0x69, + 0x67, 0x6e, 0x69, 0x6e, 0x67, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x31, + 0x21, 0x30, 0x1f, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x12, + 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x40, 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, + 0x72, 0x67, 0x82, 0x01, 0x00, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, + 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x5d, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, + 0x01, 0x01, 0x04, 0x51, 0x30, 0x4f, 0x30, 0x23, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, + 0x30, 0x01, 0x86, 0x17, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6f, 0x63, 0x73, 0x70, 0x2e, + 0x43, 0x41, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x30, 0x28, 0x06, 0x08, 0x2b, + 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x02, 0x86, 0x1c, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, + 0x77, 0x77, 0x77, 0x2e, 0x43, 0x41, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x63, + 0x61, 0x2e, 0x63, 0x72, 0x74, 0x30, 0x4a, 0x06, 0x03, 0x55, 0x1d, 0x20, 0x04, 0x43, 0x30, 0x41, + 0x30, 0x3f, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x81, 0x90, 0x4a, 0x30, 0x33, 0x30, 0x31, + 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x02, 0x01, 0x16, 0x25, 0x68, 0x74, 0x74, 0x70, + 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x43, 0x41, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, + 0x67, 0x2f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x70, 0x68, 0x70, 0x3f, 0x69, 0x64, 0x3d, 0x31, + 0x30, 0x30, 0x34, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x86, 0xf8, 0x42, 0x01, 0x08, 0x04, 0x27, + 0x16, 0x25, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x43, 0x41, 0x63, + 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x70, 0x68, + 0x70, 0x3f, 0x69, 0x64, 0x3d, 0x31, 0x30, 0x30, 0x50, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x86, + 0xf8, 0x42, 0x01, 0x0d, 0x04, 0x43, 0x16, 0x41, 0x54, 0x6f, 0x20, 0x67, 0x65, 0x74, 0x20, 0x79, + 0x6f, 0x75, 0x72, 0x20, 0x6f, 0x77, 0x6e, 0x20, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, + 0x61, 0x74, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x46, 0x52, 0x45, 0x45, 0x2c, 0x20, 0x67, 0x6f, + 0x20, 0x74, 0x6f, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x43, + 0x41, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, + 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x02, 0x01, 0x00, 0x29, 0x28, 0x85, + 0xae, 0x44, 0xa9, 0xb9, 0xaf, 0xa4, 0x79, 0x13, 0xf0, 0xa8, 0xa3, 0x2b, 0x97, 0x60, 0xf3, 0x5c, + 0xee, 0xe3, 0x2f, 0xc1, 0xf6, 0xe2, 0x66, 0xa0, 0x11, 0xae, 0x36, 0x37, 0x3a, 0x76, 0x15, 0x04, + 0x53, 0xea, 0x42, 0xf5, 0xf9, 0xea, 0xc0, 0x15, 0xd8, 0xa6, 0x82, 0xd9, 0xe4, 0x61, 0xae, 0x72, + 0x0b, 0x29, 0x5c, 0x90, 0x43, 0xe8, 0x41, 0xb2, 0xe1, 0x77, 0xdb, 0x02, 0x13, 0x44, 0x78, 0x47, + 0x55, 0xaf, 0x58, 0xfc, 0xcc, 0x98, 0xf6, 0x45, 0xb9, 0xd1, 0x20, 0xf8, 0xd8, 0x21, 0x07, 0xfe, + 0x6d, 0xaa, 0x73, 0xd4, 0xb3, 0xc6, 0x07, 0xe9, 0x09, 0x85, 0xcc, 0x3b, 0xf2, 0xb6, 0xbe, 0x2c, + 0x1c, 0x25, 0xd5, 0x71, 0x8c, 0x39, 0xb5, 0x2e, 0xea, 0xbe, 0x18, 0x81, 0xba, 0xb0, 0x93, 0xb8, + 0x0f, 0xe3, 0xe6, 0xd7, 0x26, 0x8c, 0x31, 0x5a, 0x72, 0x03, 0x84, 0x52, 0xe6, 0xa6, 0xf5, 0x33, + 0x22, 0x45, 0x0a, 0xc8, 0x0b, 0x0d, 0x8a, 0xb8, 0x36, 0x6f, 0x90, 0x09, 0xa1, 0xab, 0xbd, 0xd7, + 0xd5, 0x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0xb7, 0x8a, +}; + +static const char test_cacert3_ca_subject[] = { + 0x30, 0x54, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0b, 0x43, 0x41, 0x63, + 0x65, 0x72, 0x74, 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04, + 0x0b, 0x13, 0x15, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x43, 0x41, + 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, + 0x03, 0x13, 0x13, 0x43, 0x41, 0x63, 0x65, 0x72, 0x74, 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x20, + 0x33, 0x20, 0x52, 0x6f, 0x6f, 0x74, +}; + +static const char test_cacert3_ca_issuer[] = { + 0x30, 0x79, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x07, 0x52, 0x6f, 0x6f, + 0x74, 0x20, 0x43, 0x41, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x15, 0x68, + 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, + 0x2e, 0x6f, 0x72, 0x67, 0x31, 0x22, 0x30, 0x20, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x19, 0x43, + 0x41, 0x20, 0x43, 0x65, 0x72, 0x74, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x69, 0x6e, 0x67, 0x20, 0x41, + 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x09, 0x2a, 0x86, + 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x12, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, + 0x40, 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, +}; + +static const char test_cacert3_ca_serial[] = { + 0x02, 0x01, 0x00, +}; + +static const char test_eku_server_and_client[] = { + 0x30, 0x14, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2b, 0x06, + 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, +}; + +static const char test_eku_server[] = { + 0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, +}; + +static const char test_eku_email[] = { + 0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x04 +}; + +static const char test_eku_none[] = { + 0x30, 0x00, +}; + +void test_check_file_msg (const char *file, + int line, + const char *function, + const char *directory, + const char *filename, + const char *reference); + +void test_check_data_msg (const char *file, + int line, + const char *function, + const char *directory, + const char *filename, + const void *refdata, + long reflen); + +#ifdef OS_UNIX + +void test_check_symlink_msg (const char *file, + int line, + const char *function, + const char *directory, + const char *name, + const char *destination); + +#endif /* OS_UNIX */ + +p11_dict * test_check_directory_files (const char *file, + ...) GNUC_NULL_TERMINATED; + +void test_check_directory_msg (const char *file, + int line, + const char *function, + const char *directory, + p11_dict *files); + +#define test_check_file(directory, name, reference) \ + (test_check_file_msg (__FILE__, __LINE__, __FUNCTION__, directory, name, reference)) + +#define test_check_data(directory, name, data, length) \ + (test_check_data_msg (__FILE__, __LINE__, __FUNCTION__, directory, name, data, length)) + +#ifdef OS_UNIX + +#define test_check_symlink(directory, name, destination) \ + (test_check_symlink_msg (__FILE__, __LINE__, __FUNCTION__, directory, name, destination)) + +#endif /* OS_UNIX */ + +#define test_check_directory(directory, files) \ + (test_check_directory_msg (__FILE__, __LINE__, __FUNCTION__, directory, \ + test_check_directory_files files)) + +#endif /* TEST_COMMON_H_ */ diff --git a/tools/tests/test-x509.c b/tools/tests/test-x509.c index 5093743..693aaa0 100644 --- a/tools/tests/test-x509.c +++ b/tools/tests/test-x509.c @@ -35,7 +35,8 @@ #define P11_KIT_DISABLE_DEPRECATED #include "config.h" -#include "CuTest.h" +#include "test.h" +#include "test-tools.h" #include "attrs.h" #include "compat.h" @@ -48,7 +49,6 @@ #include "pkcs11.h" #include "pkcs11x.h" #include "oid.h" -#include "test.h" #include #include @@ -64,14 +64,14 @@ struct { } test; static void -setup (CuTest *tc) +setup (void *unused) { CK_RV rv; mock_module_reset (); memcpy (&test.module, &mock_module, sizeof (CK_FUNCTION_LIST)); rv = test.module.C_Initialize (NULL); - CuAssertIntEquals (tc, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); test.iter = p11_kit_iter_new (NULL); @@ -79,23 +79,23 @@ setup (CuTest *tc) test.directory = p11_path_expand ("$TEMP/test-extract.XXXXXX"); if (!mkdtemp (test.directory)) - CuFail (tc, "mkdtemp() failed"); + assert_fail ("mkdtemp() failed", test.directory); } static void -teardown (CuTest *tc) +teardown (void *unused) { CK_RV rv; if (rmdir (test.directory) < 0) - CuFail (tc, "rmdir() failed"); + assert_fail ("rmdir() failed", test.directory); free (test.directory); p11_extract_info_cleanup (&test.ex); p11_kit_iter_free (test.iter); rv = test.module.C_Finalize (NULL); - CuAssertIntEquals (tc, CKR_OK, rv); + assert_num_eq (CKR_OK, rv); } static CK_OBJECT_CLASS certificate_class = CKO_CERTIFICATE; @@ -117,12 +117,10 @@ static CK_ATTRIBUTE certificate_filter[] = { }; static void -test_file (CuTest *tc) +test_file (void) { bool ret; - setup (tc); - mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_authority_attrs); p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL); @@ -133,21 +131,18 @@ test_file (CuTest *tc) assert_not_reached (); ret = p11_extract_x509_file (test.iter, &test.ex); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - test_check_file (tc, test.directory, "extract.cer", SRCDIR "/files/cacert3.der"); + test_check_file (test.directory, "extract.cer", SRCDIR "/files/cacert3.der"); free (test.ex.destination); - teardown (tc); } static void -test_file_multiple (CuTest *tc) +test_file_multiple (void) { bool ret; - setup (tc); - mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_authority_attrs); mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_authority_attrs); @@ -161,25 +156,22 @@ test_file_multiple (CuTest *tc) p11_message_quiet (); ret = p11_extract_x509_file (test.iter, &test.ex); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - CuAssertTrue (tc, strstr (p11_message_last (), "multiple certificates") != NULL); + assert (strstr (p11_message_last (), "multiple certificates") != NULL); p11_message_loud (); - test_check_file (tc, test.directory, "extract.cer", SRCDIR "/files/cacert3.der"); + test_check_file (test.directory, "extract.cer", SRCDIR "/files/cacert3.der"); free (test.ex.destination); - teardown (tc); } static void -test_file_without (CuTest *tc) +test_file_without (void) { bool ret; - setup (tc); - p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL); p11_kit_iter_add_filter (test.iter, certificate_filter, 1); p11_kit_iter_begin_with (test.iter, &test.module, 0, 0); @@ -190,23 +182,20 @@ test_file_without (CuTest *tc) p11_message_quiet (); ret = p11_extract_x509_file (test.iter, &test.ex); - CuAssertIntEquals (tc, false, ret); + assert_num_eq (false, ret); - CuAssertTrue (tc, strstr (p11_message_last (), "no certificate") != NULL); + assert (strstr (p11_message_last (), "no certificate") != NULL); p11_message_loud (); free (test.ex.destination); - teardown (tc); } static void -test_directory (CuTest *tc) +test_directory (void) { bool ret; - setup (tc); - mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_authority_attrs); mock_module_add_object (MOCK_SLOT_ONE_ID, cacert3_authority_attrs); @@ -220,22 +209,18 @@ test_directory (CuTest *tc) test.ex.destination = test.directory; ret = p11_extract_x509_directory (test.iter, &test.ex); - CuAssertIntEquals (tc, true, ret); + assert_num_eq (true, ret); - test_check_directory (tc, test.directory, ("Cacert3_Here.cer", "Cacert3_Here.1.cer", NULL)); - test_check_file (tc, test.directory, "Cacert3_Here.cer", SRCDIR "/files/cacert3.der"); - test_check_file (tc, test.directory, "Cacert3_Here.1.cer", SRCDIR "/files/cacert3.der"); - - teardown (tc); + test_check_directory (test.directory, ("Cacert3_Here.cer", "Cacert3_Here.1.cer", NULL)); + test_check_file (test.directory, "Cacert3_Here.cer", SRCDIR "/files/cacert3.der"); + test_check_file (test.directory, "Cacert3_Here.1.cer", SRCDIR "/files/cacert3.der"); } static void -test_directory_empty (CuTest *tc) +test_directory_empty (void) { bool ret; - setup (tc); - p11_kit_iter_add_callback (test.iter, p11_extract_info_load_filter, &test.ex, NULL); p11_kit_iter_add_filter (test.iter, certificate_filter, 1); p11_kit_iter_begin_with (test.iter, &test.module, 0, 0); @@ -246,37 +231,22 @@ test_directory_empty (CuTest *tc) test.ex.destination = test.directory; ret = p11_extract_x509_directory (test.iter, &test.ex); - CuAssertIntEquals (tc, true, ret); - - test_check_directory (tc, test.directory, (NULL, NULL)); + assert_num_eq (true, ret); - teardown (tc); + test_check_directory (test.directory, (NULL, NULL)); } int -main (void) +main (int argc, + char *argv[]) { - CuString *output = CuStringNew (); - CuSuite* suite = CuSuiteNew (); - int ret; - - putenv ("P11_KIT_STRICT=1"); mock_module_init (); - p11_debug_init (); - - SUITE_ADD_TEST (suite, test_file); - SUITE_ADD_TEST (suite, test_file_multiple); - SUITE_ADD_TEST (suite, test_file_without); - SUITE_ADD_TEST (suite, test_directory); - SUITE_ADD_TEST (suite, test_directory_empty); - - CuSuiteRun (suite); - CuSuiteSummary (suite, output); - CuSuiteDetails (suite, output); - printf ("%s\n", output->buffer); - ret = suite->failCount; - CuSuiteDelete (suite); - CuStringDelete (output); - - return ret; + + p11_fixture (setup, teardown); + p11_test (test_file, "/x509/test_file"); + p11_test (test_file_multiple, "/x509/test_file_multiple"); + p11_test (test_file_without, "/x509/test_file_without"); + p11_test (test_directory, "/x509/test_directory"); + p11_test (test_directory_empty, "/x509/test_directory_empty"); + return p11_test_run (argc, argv); } diff --git a/tools/tests/test.c b/tools/tests/test.c deleted file mode 100644 index 4ba2162..0000000 --- a/tools/tests/test.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (c) 2013, Red Hat Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the - * above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * * The names of contributors to this software may not be - * used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * Author: Stef Walter - */ - -#include "config.h" -#include "CuTest.h" - -#include "debug.h" -#include "test.h" - -#include - -#include -#include -#include -#include -#include -#include - -static char * -read_file (CuTest *tc, - const char *file, - int line, - const char *filename, - long *len) -{ - struct stat sb; - FILE *f = NULL; - char *data; - - f = fopen (filename, "rb"); - if (f == NULL) - CuFail_Line (tc, file, line, "Couldn't open file", filename); - - /* Figure out size */ - if (stat (filename, &sb) < 0) - CuFail_Line (tc, file, line, "Couldn't stat file", filename); - - *len = sb.st_size; - data = malloc (*len ? *len : 1); - assert (data != NULL); - - /* And read in one block */ - if (fread (data, 1, *len, f) != *len) - CuFail_Line (tc, file, line, "Couldn't read file", filename); - - fclose (f); - - return data; -} - -void -test_check_file_msg (CuTest *tc, - const char *file, - int line, - const char *directory, - const char *name, - const char *reference) -{ - char *refdata; - long reflen; - - refdata = read_file (tc, file, line, reference, &reflen); - test_check_data_msg (tc, file, line, directory, name, refdata, reflen); - free (refdata); -} - -void -test_check_data_msg (CuTest *tc, - const char *file, - int line, - const char *directory, - const char *name, - const void *refdata, - long reflen) -{ - char *filedata; - char *filename; - long filelen; - - if (asprintf (&filename, "%s/%s", directory, name) < 0) - CuFail_Line (tc, file, line, "asprintf() failed", NULL); - - filedata = read_file (tc, file, line, filename, &filelen); - - if (filelen != reflen || memcmp (filedata, refdata, reflen) != 0) - CuFail_Line (tc, file, line, "File contents not as expected", filename); - - CuAssert_Line (tc, file, line, "couldn't remove file", unlink (filename) >= 0); - free (filename); - free (filedata); -} - -#ifdef OS_UNIX - -void -test_check_symlink_msg (CuTest *tc, - const char *file, - int line, - const char *directory, - const char *name, - const char *destination) -{ - char buf[1024] = { 0, }; - char *filename; - - if (asprintf (&filename, "%s/%s", directory, name) < 0) - CuFail_Line (tc, file, line, "asprintf() failed", NULL); - - if (readlink (filename, buf, sizeof (buf)) < 0) - CuFail_Line (tc, file, line, "Couldn't read symlink", filename); - - CuAssertStrEquals_LineMsg (tc, file, line, "symlink contents wrong", destination, buf); - - CuAssert_Line (tc, file, line, "couldn't remove symlink", unlink (filename) >= 0); - free (filename); -} - -#endif /* OS_UNIX */ - -p11_dict * -test_check_directory_files (const char *file, - ...) -{ - p11_dict *files; - va_list va; - - files = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, NULL, NULL); - - va_start (va, file); - - while (file != NULL) { - if (!p11_dict_set (files, (void *)file, (void *)file)) - return_val_if_reached (NULL); - file = va_arg (va, const char *); - } - - va_end (va); - - return files; -} - -void -test_check_directory_msg (CuTest *tc, - const char *file, - int line, - const char *directory, - p11_dict *files) -{ - p11_dictiter iter; - struct dirent *dp; - const char *name; - DIR *dir; - - dir = opendir (directory); - if (dir == NULL) - CuFail_Line (tc, file ,line, "Couldn't open directory", directory); - - while ((dp = readdir (dir)) != NULL) { - if (strcmp (dp->d_name, ".") == 0 || - strcmp (dp->d_name, "..") == 0) - continue; - - if (!p11_dict_remove (files, dp->d_name)) - CuFail_Line (tc, file, line, "Unexpected file in directory", dp->d_name); - } - - closedir (dir); - -#ifdef OS_UNIX - CuAssert_Line (tc, file, line, "couldn't chown directory", chmod (directory, S_IRWXU) >= 0); -#endif - - p11_dict_iterate (files, &iter); - while (p11_dict_next (&iter, (void **)&name, NULL)) - CuFail_Line (tc, file, line, "Couldn't find file in directory", name); - - p11_dict_free (files); -} diff --git a/tools/tests/test.h b/tools/tests/test.h deleted file mode 100644 index de2bdc1..0000000 --- a/tools/tests/test.h +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (c) 2013, Red Hat Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the - * above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * * The names of contributors to this software may not be - * used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * Author: Stef Walter - */ - -#ifndef TEST_COMMON_H_ -#define TEST_COMMON_H_ - -#include "CuTest.h" - -#include "dict.h" - -#include - -static const char test_text[] = "This is the file text"; - -static const unsigned char test_cacert3_ca_der[] = { - 0x30, 0x82, 0x07, 0x59, 0x30, 0x82, 0x05, 0x41, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x03, 0x0a, - 0x41, 0x8a, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, - 0x00, 0x30, 0x79, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x07, 0x52, 0x6f, - 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x15, - 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x63, 0x61, 0x63, 0x65, 0x72, - 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x31, 0x22, 0x30, 0x20, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x19, - 0x43, 0x41, 0x20, 0x43, 0x65, 0x72, 0x74, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x69, 0x6e, 0x67, 0x20, - 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x09, 0x2a, - 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x12, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, - 0x74, 0x40, 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x30, 0x1e, 0x17, 0x0d, - 0x31, 0x31, 0x30, 0x35, 0x32, 0x33, 0x31, 0x37, 0x34, 0x38, 0x30, 0x32, 0x5a, 0x17, 0x0d, 0x32, - 0x31, 0x30, 0x35, 0x32, 0x30, 0x31, 0x37, 0x34, 0x38, 0x30, 0x32, 0x5a, 0x30, 0x54, 0x31, 0x14, - 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0b, 0x43, 0x41, 0x63, 0x65, 0x72, 0x74, 0x20, - 0x49, 0x6e, 0x63, 0x2e, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x15, 0x68, - 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x43, 0x41, 0x63, 0x65, 0x72, 0x74, - 0x2e, 0x6f, 0x72, 0x67, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x13, 0x43, - 0x41, 0x63, 0x65, 0x72, 0x74, 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x33, 0x20, 0x52, 0x6f, - 0x6f, 0x74, 0x30, 0x82, 0x02, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, - 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x02, 0x0f, 0x00, 0x30, 0x82, 0x02, 0x0a, 0x02, 0x82, - 0x02, 0x01, 0x00, 0xab, 0x49, 0x35, 0x11, 0x48, 0x7c, 0xd2, 0x26, 0x7e, 0x53, 0x94, 0xcf, 0x43, - 0xa9, 0xdd, 0x28, 0xd7, 0x42, 0x2a, 0x8b, 0xf3, 0x87, 0x78, 0x19, 0x58, 0x7c, 0x0f, 0x9e, 0xda, - 0x89, 0x7d, 0xe1, 0xfb, 0xeb, 0x72, 0x90, 0x0d, 0x74, 0xa1, 0x96, 0x64, 0xab, 0x9f, 0xa0, 0x24, - 0x99, 0x73, 0xda, 0xe2, 0x55, 0x76, 0xc7, 0x17, 0x7b, 0xf5, 0x04, 0xac, 0x46, 0xb8, 0xc3, 0xbe, - 0x7f, 0x64, 0x8d, 0x10, 0x6c, 0x24, 0xf3, 0x61, 0x9c, 0xc0, 0xf2, 0x90, 0xfa, 0x51, 0xe6, 0xf5, - 0x69, 0x01, 0x63, 0xc3, 0x0f, 0x56, 0xe2, 0x4a, 0x42, 0xcf, 0xe2, 0x44, 0x8c, 0x25, 0x28, 0xa8, - 0xc5, 0x79, 0x09, 0x7d, 0x46, 0xb9, 0x8a, 0xf3, 0xe9, 0xf3, 0x34, 0x29, 0x08, 0x45, 0xe4, 0x1c, - 0x9f, 0xcb, 0x94, 0x04, 0x1c, 0x81, 0xa8, 0x14, 0xb3, 0x98, 0x65, 0xc4, 0x43, 0xec, 0x4e, 0x82, - 0x8d, 0x09, 0xd1, 0xbd, 0xaa, 0x5b, 0x8d, 0x92, 0xd0, 0xec, 0xde, 0x90, 0xc5, 0x7f, 0x0a, 0xc2, - 0xe3, 0xeb, 0xe6, 0x31, 0x5a, 0x5e, 0x74, 0x3e, 0x97, 0x33, 0x59, 0xe8, 0xc3, 0x03, 0x3d, 0x60, - 0x33, 0xbf, 0xf7, 0xd1,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8a, 0xe4, 0x34, 0x7b, 0xc0, 0xd8, - 0x6c, 0x5f, 0xe9, 0x0a, 0xc2, 0xc3, 0xa7, 0x20, 0x9a, 0x5a, 0xdf, 0x2c, 0x5d, 0x52, 0x5c, 0xba, - 0x47, 0xd5, 0x9b, 0xef, 0x24, 0x28, 0x70, 0x38, 0x20, 0x2f, 0xd5, 0x7f, 0x29, 0xc0, 0xb2, 0x41, - 0x03, 0x68, 0x92, 0xcc, 0xe0, 0x9c, 0xcc, 0x97, 0x4b, 0x45, 0xef, 0x3a, 0x10, 0x0a, 0xab, 0x70, - 0x3a, 0x98, 0x95, 0x70, 0xad, 0x35, 0xb1, 0xea, 0x85, 0x2b, 0xa4, 0x1c, 0x80, 0x21, 0x31, 0xa9, - 0xae, 0x60, 0x7a, 0x80, 0x26, 0x48, 0x00, 0xb8, 0x01, 0xc0, 0x93, 0x63, 0x55, 0x22, 0x91, 0x3c, - 0x56, 0xe7, 0xaf, 0xdb, 0x3a, 0x25, 0xf3, 0x8f, 0x31, 0x54, 0xea, 0x26, 0x8b, 0x81, 0x59, 0xf9, - 0xa1, 0xd1, 0x53, 0x11, 0xc5, 0x7b, 0x9d, 0x03, 0xf6, 0x74, 0x11, 0xe0, 0x6d, 0xb1, 0x2c, 0x3f, - 0x2c, 0x86, 0x91, 0x99, 0x71, 0x9a, 0xa6, 0x77, 0x8b, 0x34, 0x60, 0xd1, 0x14, 0xb4, 0x2c, 0xac, - 0x9d, 0xaf, 0x8c, 0x10, 0xd3, 0x9f, 0xc4, 0x6a, 0xf8, 0x6f, 0x13, 0xfc, 0x73, 0x59, 0xf7, 0x66, - 0x42, 0x74, 0x1e, 0x8a, 0xe3, 0xf8, 0xdc, 0xd2, 0x6f, 0x98, 0x9c, 0xcb, 0x47, 0x98, 0x95, 0x40, - 0x05, 0xfb, 0xe9, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, 0x02, 0x0d, 0x30, 0x82, 0x02, 0x09, - 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x75, 0xa8, 0x71, 0x60, 0x4c, - 0x88, 0x13, 0xf0, 0x78, 0xd9, 0x89, 0x77, 0xb5, 0x6d, 0xc5, 0x89, 0xdf, 0xbc, 0xb1, 0x7a, 0x30, - 0x81, 0xa3, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x81, 0x9b, 0x30, 0x81, 0x98, 0x80, 0x14, 0x16, - 0xb5, 0x32, 0x1b, 0xd4, 0xc7, 0xf3, 0xe0, 0xe6, 0x8e, 0xf3, 0xbd, 0xd2, 0xb0, 0x3a, 0xee, 0xb2, - 0x39, 0x18, 0xd1, 0xa1, 0x7d, 0xa4, 0x7b, 0x30, 0x79, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, - 0x04, 0x0a, 0x13, 0x07, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1e, 0x30, 0x1c, 0x06, - 0x03, 0x55, 0x04, 0x0b, 0x13, 0x15, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, - 0x2e, 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x31, 0x22, 0x30, 0x20, 0x06, - 0x03, 0x55, 0x04, 0x03, 0x13, 0x19, 0x43, 0x41, 0x20, 0x43, 0x65, 0x72, 0x74, 0x20, 0x53, 0x69, - 0x67, 0x6e, 0x69, 0x6e, 0x67, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x31, - 0x21, 0x30, 0x1f, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x12, - 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x40, 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, - 0x72, 0x67, 0x82, 0x01, 0x00, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, - 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x5d, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, - 0x01, 0x01, 0x04, 0x51, 0x30, 0x4f, 0x30, 0x23, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, - 0x30, 0x01, 0x86, 0x17, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6f, 0x63, 0x73, 0x70, 0x2e, - 0x43, 0x41, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x30, 0x28, 0x06, 0x08, 0x2b, - 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x02, 0x86, 0x1c, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, - 0x77, 0x77, 0x77, 0x2e, 0x43, 0x41, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x63, - 0x61, 0x2e, 0x63, 0x72, 0x74, 0x30, 0x4a, 0x06, 0x03, 0x55, 0x1d, 0x20, 0x04, 0x43, 0x30, 0x41, - 0x30, 0x3f, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x81, 0x90, 0x4a, 0x30, 0x33, 0x30, 0x31, - 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x02, 0x01, 0x16, 0x25, 0x68, 0x74, 0x74, 0x70, - 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x43, 0x41, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, - 0x67, 0x2f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x70, 0x68, 0x70, 0x3f, 0x69, 0x64, 0x3d, 0x31, - 0x30, 0x30, 0x34, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x86, 0xf8, 0x42, 0x01, 0x08, 0x04, 0x27, - 0x16, 0x25, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x43, 0x41, 0x63, - 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x70, 0x68, - 0x70, 0x3f, 0x69, 0x64, 0x3d, 0x31, 0x30, 0x30, 0x50, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x86, - 0xf8, 0x42, 0x01, 0x0d, 0x04, 0x43, 0x16, 0x41, 0x54, 0x6f, 0x20, 0x67, 0x65, 0x74, 0x20, 0x79, - 0x6f, 0x75, 0x72, 0x20, 0x6f, 0x77, 0x6e, 0x20, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, - 0x61, 0x74, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x46, 0x52, 0x45, 0x45, 0x2c, 0x20, 0x67, 0x6f, - 0x20, 0x74, 0x6f, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x43, - 0x41, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, - 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x02, 0x01, 0x00, 0x29, 0x28, 0x85, - 0xae, 0x44, 0xa9, 0xb9, 0xaf, 0xa4, 0x79, 0x13, 0xf0, 0xa8, 0xa3, 0x2b, 0x97, 0x60, 0xf3, 0x5c, - 0xee, 0xe3, 0x2f, 0xc1, 0xf6, 0xe2, 0x66, 0xa0, 0x11, 0xae, 0x36, 0x37, 0x3a, 0x76, 0x15, 0x04, - 0x53, 0xea, 0x42, 0xf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3, 0xa7, - 0x79, 0xb2, 0x52, 0xa0, 0xc6, 0xf1, 0x85, 0xb4, 0x25, 0x8c, 0xf2, 0x3f, 0x96, 0xb3, 0x10, 0xd9, - 0x8d, 0x6c, 0x57, 0x3b, 0x9f, 0x6f, 0x86, 0x3a, 0x18, 0x82, 0x22, 0x36, 0xc8, 0xb0, 0x91, 0x38, - 0xdb, 0x2a, 0xa1, 0x93, 0xaa, 0x84, 0x3f, 0xf5, 0x27, 0x65, 0xae, 0x73, 0xd5, 0xc8, 0xd5, 0xd3, - 0x77, 0xea, 0x4b, 0x9d, 0xc7, 0x41, 0xbb, 0xc7, 0xc0, 0xe3, 0xa0, 0x3f, 0xe4, 0x7d, 0xa4, 0x8d, - 0x73, 0xe6, 0x12, 0x4b, 0xdf, 0xa1, 0x73, 0x73, 0x73, 0x3a, 0x80, 0xe8, 0xd5, 0xcb, 0x8e, 0x2f, - 0xcb, 0xea, 0x13, 0xa7, 0xd6, 0x41, 0x8b, 0xac, 0xfa, 0x3c, 0x89, 0xd7, 0x24, 0xf5, 0x4e, 0xb4, - 0xe0, 0x61, 0x92, 0xb7, 0xf3, 0x37, 0x98, 0xc4, 0xbe, 0x96, 0xa3, 0xb7, 0x8a, -}; - -static const char test_cacert3_ca_subject[] = { - 0x30, 0x54, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0b, 0x43, 0x41, 0x63, - 0x65, 0x72, 0x74, 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04, - 0x0b, 0x13, 0x15, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x43, 0x41, - 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, - 0x03, 0x13, 0x13, 0x43, 0x41, 0x63, 0x65, 0x72, 0x74, 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x20, - 0x33, 0x20, 0x52, 0x6f, 0x6f, 0x74, -}; - -static const char test_cacert3_ca_issuer[] = { - 0x30, 0x79, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x07, 0x52, 0x6f, 0x6f, - 0x74, 0x20, 0x43, 0x41, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x15, 0x68, - 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, - 0x2e, 0x6f, 0x72, 0x67, 0x31, 0x22, 0x30, 0x20, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x19, 0x43, - 0x41, 0x20, 0x43, 0x65, 0x72, 0x74, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x69, 0x6e, 0x67, 0x20, 0x41, - 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x09, 0x2a, 0x86, - 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x12, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, - 0x40, 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, -}; - -static const char test_cacert3_ca_serial[] = { - 0x02, 0x01, 0x00, -}; - -static const char test_eku_server_and_client[] = { - 0x30, 0x14, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2b, 0x06, - 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, -}; - -static const char test_eku_server[] = { - 0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, -}; - -static const char test_eku_email[] = { - 0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x04 -}; - -static const char test_eku_none[] = { - 0x30, 0x00, -}; - -void test_check_file_msg (CuTest *tc, - const char *file, - int line, - const char *directory, - const char *filename, - const char *reference); - -void test_check_data_msg (CuTest *tc, - const char *file, - int line, - const char *directory, - const char *filename, - const void *refdata, - long reflen); - -#ifdef OS_UNIX - -void test_check_symlink_msg (CuTest *tc, - const char *file, - int line, - const char *directory, - const char *name, - const char *destination); - -#endif /* OS_UNIX */ - -p11_dict * test_check_directory_files (const char *file, - ...) GNUC_NULL_TERMINATED; - -void test_check_directory_msg (CuTest *tc, - const char *file, - int line, - const char *directory, - p11_dict *files); - -#define test_check_file(tc, directory, name, reference) \ - (test_check_file_msg (tc, __FILE__, __LINE__, directory, name, reference)) - -#define test_check_data(tc, directory, name, data, length) \ - (test_check_data_msg (tc, __FILE__, __LINE__, directory, name, data, length)) - -#ifdef OS_UNIX - -#define test_check_symlink(tc, directory, name, destination) \ - (test_check_symlink_msg (tc, __FILE__, __LINE__, directory, name, destination)) - -#endif /* OS_UNIX */ - -#define test_check_directory(tc, directory, files) \ - (test_check_directory_msg (tc, __FILE__, __LINE__, directory, \ - test_check_directory_files files)) - -#endif /* TEST_COMMON_H_ */ -- cgit v1.1