diff options
author | Ingela Anderton Andin <[email protected]> | 2012-12-18 13:49:14 +0100 |
---|---|---|
committer | Ingela Anderton Andin <[email protected]> | 2013-01-11 15:05:34 +0100 |
commit | 8c1fbae6c118d366aaccd50a1795190bad97d7f3 (patch) | |
tree | bbbd57002345b528a79a2e0e965fef59aaaacd80 /lib | |
parent | 1c6aa8a70fb2041d1df3c1f4203d5fbb8a41e4fb (diff) | |
download | otp-8c1fbae6c118d366aaccd50a1795190bad97d7f3.tar.gz otp-8c1fbae6c118d366aaccd50a1795190bad97d7f3.tar.bz2 otp-8c1fbae6c118d366aaccd50a1795190bad97d7f3.zip |
public_key: CTify test suites
Diffstat (limited to 'lib')
-rw-r--r-- | lib/public_key/test/pbe_SUITE.erl | 105 | ||||
-rw-r--r-- | lib/public_key/test/pkits_SUITE.erl | 472 | ||||
-rw-r--r-- | lib/public_key/test/public_key_SUITE.erl | 276 |
3 files changed, 303 insertions, 550 deletions
diff --git a/lib/public_key/test/pbe_SUITE.erl b/lib/public_key/test/pbe_SUITE.erl index 380a67db7b..8fba1e8cd3 100644 --- a/lib/public_key/test/pbe_SUITE.erl +++ b/lib/public_key/test/pbe_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2011-2011. All Rights Reserved. +%% Copyright Ericsson AB 2011-2012. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -19,72 +19,16 @@ -module(pbe_SUITE). --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -include_lib("public_key/include/public_key.hrl"). %% Note: This directive should only be used in test suites. -compile(export_all). -%% Test server callback functions -%%-------------------------------------------------------------------- -%% Function: init_per_suite(Config) -> Config -%% Config - [tuple()] -%% A list of key/value pairs, holding the test case configuration. -%% Description: Initialization before the whole suite -%% -%% Note: This function is free to add any key/value pairs to the Config -%% variable, but should NOT alter/remove any existing entries. -%%-------------------------------------------------------------------- -init_per_suite(Config) -> - try crypto:start() of - ok -> - Config - catch _:_ -> - {skip, "Crypto did not start"} - end. -%%-------------------------------------------------------------------- -%% Function: end_per_suite(Config) -> _ -%% Config - [tuple()] -%% A list of key/value pairs, holding the test case configuration. -%% Description: Cleanup after the whole suite -%%-------------------------------------------------------------------- -end_per_suite(_Config) -> - application:stop(crypto). - -%%-------------------------------------------------------------------- -%% Function: init_per_testcase(TestCase, Config) -> Config -%% Case - atom() -%% Name of the test case that is about to be run. -%% Config - [tuple()] -%% A list of key/value pairs, holding the test case configuration. -%% -%% Description: Initialization before each test case -%% -%% Note: This function is free to add any key/value pairs to the Config -%% variable, but should NOT alter/remove any existing entries. -%% Description: Initialization before each test case -%%-------------------------------------------------------------------- -init_per_testcase(_TestCase, Config) -> - Config. %%-------------------------------------------------------------------- -%% Function: end_per_testcase(TestCase, Config) -> _ -%% Case - atom() -%% Name of the test case that is about to be run. -%% Config - [tuple()] -%% A list of key/value pairs, holding the test case configuration. -%% Description: Cleanup after each test case +%% Common Test interface functions ----------------------------------- %%-------------------------------------------------------------------- -end_per_testcase(_TestCase, _Config) -> - ok. -%%-------------------------------------------------------------------- -%% Function: all(Clause) -> TestCases -%% Clause - atom() - suite | doc -%% TestCases - [Case] -%% Case - atom() -%% Name of a test case. -%% Description: Returns a list of all test cases in this test suite -%%-------------------------------------------------------------------- suite() -> [{ct_hooks,[ts_install_cth]}]. all() -> @@ -96,17 +40,40 @@ all() -> groups() -> []. +%%-------------------------------------------------------------------- +init_per_suite(Config) -> + try crypto:start() of + ok -> + Config + catch _:_ -> + {skip, "Crypto did not start"} + end. + +end_per_suite(_Config) -> + application:stop(crypto). + +%%-------------------------------------------------------------------- + init_per_group(_GroupName, Config) -> Config. end_per_group(_GroupName, Config) -> Config. +%%-------------------------------------------------------------------- +init_per_testcase(_TestCase, Config) -> + Config. + + +end_per_testcase(_TestCase, _Config) -> + ok. -%% Test cases starts here. %%-------------------------------------------------------------------- -pbdkdf1(doc) -> - ["Test with PKCS #5 PBKDF1 Test Vectors"]; +%% Test Cases -------------------------------------------------------- +%%-------------------------------------------------------------------- + +pbdkdf1() -> + [{doc,"Test with PKCS #5 PBKDF1 Test Vectors"}]. pbdkdf1(Config) when is_list(Config) -> %%Password = "password" %% = (0x)70617373776F7264 @@ -126,8 +93,8 @@ pbdkdf1(Config) when is_list(Config) -> 16#4A, 16#3D, 16#2A, 16#20, _/binary>> = pubkey_pbe:pbdkdf1(Password, Salt, Count, sha). -pbdkdf2(doc) -> - ["Test with PKCS #5 PBKDF2 Test Vectors"]; +pbdkdf2() -> + [{doc,"Test with PKCS #5 PBKDF2 Test Vectors"}]. pbdkdf2(Config) when is_list(Config) -> %% Input: %% P = "password" (8 octets) @@ -225,28 +192,28 @@ pbdkdf2(Config) when is_list(Config) -> = pubkey_pbe:pbdkdf2("pass\0word", "sa\0lt", 4096, 16, fun crypto:sha_mac/3, 20). -encrypted_private_key_info(doc) -> - ["Tests reading a EncryptedPrivateKeyInfo file encrypted with different ciphers"]; +encrypted_private_key_info() -> + [{doc,"Tests reading a EncryptedPrivateKeyInfo file encrypted with different ciphers"}]. encrypted_private_key_info(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), {ok, PemDes} = file:read_file(filename:join(Datadir, "des_cbc_enc_key.pem")), PemDesEntry = public_key:pem_decode(PemDes), - test_server:format("Pem entry: ~p" , [PemDesEntry]), + ct:print("Pem entry: ~p" , [PemDesEntry]), [{'PrivateKeyInfo', _, {"DES-CBC",_}} = PubEntry0] = PemDesEntry, KeyInfo = public_key:pem_entry_decode(PubEntry0, "password"), {ok, Pem3Des} = file:read_file(filename:join(Datadir, "des_ede3_cbc_enc_key.pem")), Pem3DesEntry = public_key:pem_decode(Pem3Des), - test_server:format("Pem entry: ~p" , [Pem3DesEntry]), + ct:print("Pem entry: ~p" , [Pem3DesEntry]), [{'PrivateKeyInfo', _, {"DES-EDE3-CBC",_}} = PubEntry1] = Pem3DesEntry, KeyInfo = public_key:pem_entry_decode(PubEntry1, "password"), {ok, PemRc2} = file:read_file(filename:join(Datadir, "rc2_cbc_enc_key.pem")), PemRc2Entry = public_key:pem_decode(PemRc2), - test_server:format("Pem entry: ~p" , [PemRc2Entry]), + ct:print("Pem entry: ~p" , [PemRc2Entry]), [{'PrivateKeyInfo', _, {"RC2-CBC",_}} = PubEntry2] = PemRc2Entry, KeyInfo = public_key:pem_entry_decode(PubEntry2, "password"), diff --git a/lib/public_key/test/pkits_SUITE.erl b/lib/public_key/test/pkits_SUITE.erl index 2b67460197..d901adaadd 100644 --- a/lib/public_key/test/pkits_SUITE.erl +++ b/lib/public_key/test/pkits_SUITE.erl @@ -23,11 +23,11 @@ -module(pkits_SUITE). +-include_lib("public_key/include/public_key.hrl"). + %% Note: This directive should only be used in test suites. -compile(export_all). --include_lib("public_key/include/public_key.hrl"). - -define(error(Format,Args), error(Format,Args,?FILE,?LINE)). -define(warning(Format,Args), warning(Format,Args,?FILE,?LINE)). @@ -47,6 +47,9 @@ crls, crl_paths, revoke_state}). +%%-------------------------------------------------------------------- +%% Common Test interface functions ----------------------------------- +%%-------------------------------------------------------------------- suite() -> [{ct_hooks,[ts_install_cth]}]. @@ -64,17 +67,6 @@ all() -> {group, name_constraints}, {group, private_certificate_extensions}]. -init_per_suite(Config) -> - try crypto:start() of - ok -> - crypto_support_check(Config) - catch _:_ -> - {skip, "Crypto did not start"} - end. - -end_per_suite(_Config) -> - application:stop(crypto). - groups() -> [{signature_verification, [], [valid_rsa_signature, invalid_rsa_signature, valid_dsa_signature, @@ -117,12 +109,25 @@ groups() -> [unknown_critical_extension, unknown_not_critical_extension]} ]. +%%-------------------------------------------------------------------- +init_per_suite(Config) -> + try crypto:start() of + ok -> + crypto_support_check(Config) + catch _:_ -> + {skip, "Crypto did not start"} + end. + +end_per_suite(_Config) -> + application:stop(crypto). + +%%-------------------------------------------------------------------- init_per_group(_GroupName, Config) -> Config. end_per_group(_GroupName, Config) -> Config. - +%%-------------------------------------------------------------------- init_per_testcase(_Func, Config) -> Datadir = proplists:get_value(data_dir, Config), put(datadir, Datadir), @@ -131,134 +136,105 @@ init_per_testcase(_Func, Config) -> end_per_testcase(_Func, Config) -> Config. +%%-------------------------------------------------------------------- +%% Test Cases -------------------------------------------------------- +%%-------------------------------------------------------------------- %%--------------------------- signature_verification-------------------------------------------------- -valid_rsa_signature(doc) -> - ["Test rsa signatur verification"]; -valid_rsa_signature(suite) -> - []; +valid_rsa_signature() -> + [{doc, "Test rsa signatur verification"}]. valid_rsa_signature(Config) when is_list(Config) -> run([{ "4.1.1", "Valid Certificate Path Test1 EE", ok}]). -invalid_rsa_signature(doc) -> - ["Test rsa signatur verification"]; -invalid_rsa_signature(suite) -> - []; +invalid_rsa_signature() -> + [{doc,"Test rsa signatur verification"}]. invalid_rsa_signature(Config) when is_list(Config) -> run([{ "4.1.2", "Invalid CA Signature Test2 EE", {bad_cert,invalid_signature}}, { "4.1.3", "Invalid EE Signature Test3 EE", {bad_cert,invalid_signature}}]). -valid_dsa_signature(doc) -> - ["Test dsa signatur verification"]; -valid_dsa_signature(suite) -> - []; +valid_dsa_signature() -> + [{doc,"Test dsa signatur verification"}]. valid_dsa_signature(Config) when is_list(Config) -> run([{ "4.1.4", "Valid DSA Signatures Test4 EE", ok}, { "4.1.5", "Valid DSA Parameter Inheritance Test5 EE", ok}]). -invalid_dsa_signature(doc) -> - ["Test dsa signatur verification"]; -invalid_dsa_signature(suite) -> - []; +invalid_dsa_signature() -> + [{doc,"Test dsa signatur verification"}]. invalid_dsa_signature(Config) when is_list(Config) -> run([{ "4.1.6", "Invalid DSA Signature Test6 EE",{bad_cert,invalid_signature}}]). %%-----------------------------validity_periods------------------------------------------------ -not_before_invalid(doc) -> - ["Test valid periods"]; -not_before_invalid(suite) -> - []; +not_before_invalid() -> + [{doc,"Test valid periods"}]. not_before_invalid(Config) when is_list(Config) -> run([{ "4.2.1", "Invalid CA notBefore Date Test1 EE",{bad_cert, cert_expired}}, { "4.2.2", "Invalid EE notBefore Date Test2 EE",{bad_cert, cert_expired}}]). -not_before_valid(doc) -> - ["Test valid periods"]; -not_before_valid(suite) -> - []; +not_before_valid() -> + [{doc,"Test valid periods"}]. not_before_valid(Config) when is_list(Config) -> run([{ "4.2.3", "Valid pre2000 UTC notBefore Date Test3 EE", ok}, { "4.2.4", "Valid GeneralizedTime notBefore Date Test4 EE", ok}]). -not_after_invalid(doc) -> - ["Test valid periods"]; -not_after_invalid(suite) -> - []; +not_after_invalid() -> + [{doc,"Test valid periods"}]. not_after_invalid(Config) when is_list(Config) -> run([{ "4.2.5", "Invalid CA notAfter Date Test5 EE", {bad_cert, cert_expired}}, { "4.2.6", "Invalid EE notAfter Date Test6 EE", {bad_cert, cert_expired}}, { "4.2.7", "Invalid pre2000 UTC EE notAfter Date Test7 EE",{bad_cert, cert_expired}}]). -not_after_valid(doc) -> - ["Test valid periods"]; -not_after_valid(suite) -> - []; +not_after_valid() -> + [{doc,"Test valid periods"}]. not_after_valid(Config) when is_list(Config) -> run([{ "4.2.8", "Valid GeneralizedTime notAfter Date Test8 EE", ok}]). %%----------------------------verifying_name_chaining------------------------------------------------- -invalid_name_chain(doc) -> - ["Test name chaining"]; -invalid_name_chain(suite) -> - []; +invalid_name_chain() -> + [{doc,"Test name chaining"}]. invalid_name_chain(Config) when is_list(Config) -> run([{ "4.3.1", "Invalid Name Chaining Test1 EE", {bad_cert, invalid_issuer}}, { "4.3.2", "Invalid Name Chaining Order Test2 EE", {bad_cert, invalid_issuer}}]). -whitespace_name_chain(doc) -> - ["Test name chaining"]; -whitespace_name_chain(suite) -> - []; +whitespace_name_chain() -> + [{doc,"Test name chaining"}]. whitespace_name_chain(Config) when is_list(Config) -> run([{ "4.3.3", "Valid Name Chaining Whitespace Test3 EE", ok}, { "4.3.4", "Valid Name Chaining Whitespace Test4 EE", ok}]). -capitalization_name_chain(doc) -> - ["Test name chaining"]; -capitalization_name_chain(suite) -> - []; +capitalization_name_chain() -> + [{doc,"Test name chaining"}]. capitalization_name_chain(Config) when is_list(Config) -> run([{ "4.3.5", "Valid Name Chaining Capitalization Test5 EE",ok}]). -uid_name_chain(doc) -> - ["Test name chaining"]; -uid_name_chain(suite) -> - []; +uid_name_chain() -> + [{doc,"Test name chaining"}]. uid_name_chain(Config) when is_list(Config) -> run([{ "4.3.6", "Valid Name UIDs Test6 EE",ok}]). -attrib_name_chain(doc) -> - ["Test name chaining"]; -attrib_name_chain(suite) -> - []; +attrib_name_chain() -> + [{doc,"Test name chaining"}]. attrib_name_chain(Config) when is_list(Config) -> run([{ "4.3.7", "Valid RFC3280 Mandatory Attribute Types Test7 EE", ok}, { "4.3.8", "Valid RFC3280 Optional Attribute Types Test8 EE", ok}]). -string_name_chain(doc) -> - ["Test name chaining"]; -string_name_chain(suite) -> - []; +string_name_chain() -> + [{doc,"Test name chaining"}]. string_name_chain(Config) when is_list(Config) -> run([{ "4.3.9", "Valid UTF8String Encoded Names Test9 EE", ok}, %%{ "4.3.10", "Valid Rollover from PrintableString to UTF8String Test10 EE", ok}, { "4.3.11", "Valid UTF8String Case Insensitive Match Test11 EE", ok}]). %%----------------------------verifying_paths_with_self_issued_certificates------------------------------------------------- -basic_valid(doc) -> - ["Test self issued certificates"]; -basic_valid(suite) -> - []; +basic_valid() -> + [{doc,"Test self issued certificates"}]. basic_valid(Config) when is_list(Config) -> run([{ "4.5.1", "Valid Basic Self-Issued Old With New Test1 EE", ok}, { "4.5.3", "Valid Basic Self-Issued New With Old Test3 EE", ok}, { "4.5.4", "Valid Basic Self-Issued New With Old Test4 EE", ok} ]). -basic_invalid(doc) -> - ["Test self issued certificates"]; -basic_invalid(suite) -> - []; +basic_invalid() -> + [{doc,"Test self issued certificates"}]. basic_invalid(Config) when is_list(Config) -> run([{"4.5.2", "Invalid Basic Self-Issued Old With New Test2 EE", {bad_cert, {revoked, keyCompromise}}}, @@ -266,17 +242,13 @@ basic_invalid(Config) when is_list(Config) -> {bad_cert, {revoked, keyCompromise}}} ]). -crl_signing_valid(doc) -> - ["Test self issued certificates"]; -crl_signing_valid(suite) -> - []; +crl_signing_valid() -> + [{doc,"Test self issued certificates"}]. crl_signing_valid(Config) when is_list(Config) -> run([{ "4.5.6", "Valid Basic Self-Issued CRL Signing Key Test6 EE", ok}]). -crl_signing_invalid(doc) -> - ["Test self issued certificates"]; -crl_signing_invalid(suite) -> - []; +crl_signing_invalid() -> + [{doc,"Test self issued certificates"}]. crl_signing_invalid(Config) when is_list(Config) -> run([{ "4.5.7", "Invalid Basic Self-Issued CRL Signing Key Test7 EE", {bad_cert, {revoked, keyCompromise}}}, @@ -285,64 +257,48 @@ crl_signing_invalid(Config) when is_list(Config) -> ]). %%-----------------------------basic_certificate_revocation_tests------------------------------------------------ -missing_CRL(doc) -> - ["Test basic CRL handling"]; -missing_CRL(suite) -> - []; +missing_CRL() -> + [{doc,"Test basic CRL handling"}]. missing_CRL(Config) when is_list(Config) -> run([{ "4.4.1", "Invalid Missing CRL Test1 EE",{bad_cert, revocation_status_undetermined}}]). -revoked_CA(doc) -> - ["Test basic CRL handling"]; -revoked_CA(suite) -> - []; +revoked_CA() -> + [{doc,"Test basic CRL handling"}]. revoked_CA(Config) when is_list(Config) -> run([{ "4.4.2", "Invalid Revoked CA Test2 EE", {bad_cert, {revoked, keyCompromise}}}]). -revoked_peer(doc) -> - ["Test basic CRL handling"]; -revoked_peer(suite) -> - []; +revoked_peer() -> + [{doc,"Test basic CRL handling"}]. revoked_peer(Config) when is_list(Config) -> run([{ "4.4.3", "Invalid Revoked EE Test3 EE", {bad_cert, {revoked, keyCompromise}}}]). -invalid_CRL_signature(doc) -> - ["Test basic CRL handling"]; -invalid_CRL_signature(suite) -> - []; +invalid_CRL_signature() -> + [{doc,"Test basic CRL handling"}]. invalid_CRL_signature(Config) when is_list(Config) -> run([{ "4.4.4", "Invalid Bad CRL Signature Test4 EE", {bad_cert, revocation_status_undetermined}}]). -invalid_CRL_issuer(doc) -> - ["Test basic CRL handling"]; -invalid_CRL_issuer(suite) -> - []; +invalid_CRL_issuer() -> + [{doc,"Test basic CRL handling"}]. invalid_CRL_issuer(Config) when is_list(Config) -> run({ "4.4.5", "Invalid Bad CRL Issuer Name Test5 EE", {bad_cert, revocation_status_undetermined}}). -invalid_CRL(doc) -> - ["Test basic CRL handling"]; -invalid_CRL(suite) -> - []; +invalid_CRL() -> + [{doc,"Test basic CRL handling"}]. invalid_CRL(Config) when is_list(Config) -> run([{ "4.4.6", "Invalid Wrong CRL Test6 EE", {bad_cert, revocation_status_undetermined}}]). -valid_CRL(doc) -> - ["Test basic CRL handling"]; -valid_CRL(suite) -> - []; +valid_CRL() -> + [{doc,"Test basic CRL handling"}]. valid_CRL(Config) when is_list(Config) -> run([{ "4.4.7", "Valid Two CRLs Test7 EE", ok}]). -unknown_CRL_extension(doc) -> - ["Test basic CRL handling"]; -unknown_CRL_extension(suite) -> - []; +unknown_CRL_extension() -> + [{doc,"Test basic CRL handling"}]. unknown_CRL_extension(Config) when is_list(Config) -> run([{ "4.4.8", "Invalid Unknown CRL Entry Extension Test8 EE", {bad_cert, {revoked, keyCompromise}}}, @@ -351,27 +307,21 @@ unknown_CRL_extension(Config) when is_list(Config) -> { "4.4.10", "Invalid Unknown CRL Extension Test10 EE", {bad_cert, revocation_status_undetermined}}]). -old_CRL(doc) -> - ["Test basic CRL handling"]; -old_CRL(suite) -> - []; +old_CRL() -> + [{doc,"Test basic CRL handling"}]. old_CRL(Config) when is_list(Config) -> run([{ "4.4.11", "Invalid Old CRL nextUpdate Test11 EE", {bad_cert, revocation_status_undetermined}}, { "4.4.12", "Invalid pre2000 CRL nextUpdate Test12 EE", {bad_cert, revocation_status_undetermined}}]). -fresh_CRL(doc) -> - ["Test basic CRL handling"]; -fresh_CRL(suite) -> - []; +fresh_CRL() -> + [{doc,"Test basic CRL handling"}]. fresh_CRL(Config) when is_list(Config) -> run([{ "4.4.13", "Valid GeneralizedTime CRL nextUpdate Test13 EE", ok}]). -valid_serial(doc) -> - ["Test basic CRL handling"]; -valid_serial(suite) -> - []; +valid_serial() -> + [{doc,"Test basic CRL handling"}]. valid_serial(Config) when is_list(Config) -> run([ { "4.4.14", "Valid Negative Serial Number Test14 EE",ok}, @@ -379,27 +329,21 @@ valid_serial(Config) when is_list(Config) -> { "4.4.17", "Valid Long Serial Number Test17 EE", ok} ]). -invalid_serial(doc) -> - ["Test basic CRL handling"]; -invalid_serial(suite) -> - []; +invalid_serial() -> + [{doc,"Test basic CRL handling"}]. invalid_serial(Config) when is_list(Config) -> run([{ "4.4.15", "Invalid Negative Serial Number Test15 EE", {bad_cert, {revoked, keyCompromise}}}, { "4.4.18", "Invalid Long Serial Number Test18 EE", {bad_cert, {revoked, keyCompromise}}}]). -valid_seperate_keys(doc) -> - ["Test basic CRL handling"]; -valid_seperate_keys(suite) -> - []; +valid_seperate_keys() -> + [{doc,"Test basic CRL handling"}]. valid_seperate_keys(Config) when is_list(Config) -> run([{ "4.4.19", "Valid Separate Certificate and CRL Keys Test19 EE", ok}]). -invalid_separate_keys(doc) -> - ["Test basic CRL handling"]; -invalid_separate_keys(suite) -> - []; +invalid_separate_keys() -> + [{doc,"Test basic CRL handling"}]. invalid_separate_keys(Config) when is_list(Config) -> run([{ "4.4.20", "Invalid Separate Certificate and CRL Keys Test20 EE", {bad_cert, {revoked, keyCompromise}}}, @@ -407,10 +351,8 @@ invalid_separate_keys(Config) when is_list(Config) -> {bad_cert, revocation_status_undetermined}} ]). %%----------------------------verifying_basic_constraints------------------------------------------------- -missing_basic_constraints(doc) -> - ["Basic constraint tests"]; -missing_basic_constraints(suite) -> - []; +missing_basic_constraints() -> + [{doc,"Basic constraint tests"}]. missing_basic_constraints(Config) when is_list(Config) -> run([{ "4.6.1", "Invalid Missing basicConstraints Test1 EE", {bad_cert, missing_basic_constraint}}, @@ -419,17 +361,13 @@ missing_basic_constraints(Config) when is_list(Config) -> { "4.6.3", "Invalid cA False Test3 EE", {bad_cert, missing_basic_constraint}}]). -valid_basic_constraint(doc) -> - ["Basic constraint tests"]; -valid_basic_constraint(suite) -> - []; +valid_basic_constraint() -> + [{doc,"Basic constraint tests"}]. valid_basic_constraint(Config) when is_list(Config) -> run([{"4.6.4", "Valid basicConstraints Not Critical Test4 EE", ok}]). -invalid_path_constraints(doc) -> - ["Basic constraint tests"]; -invalid_path_constraints(suite) -> - []; +invalid_path_constraints() -> + [{doc,"Basic constraint tests"}]. invalid_path_constraints(Config) when is_list(Config) -> run([{ "4.6.5", "Invalid pathLenConstraint Test5 EE", {bad_cert, max_path_length_reached}}, { "4.6.6", "Invalid pathLenConstraint Test6 EE", {bad_cert, max_path_length_reached}}, @@ -440,10 +378,8 @@ invalid_path_constraints(Config) when is_list(Config) -> { "4.6.16", "Invalid Self-Issued pathLenConstraint Test16 EE", {bad_cert, max_path_length_reached}}]). -valid_path_constraints(doc) -> - ["Basic constraint tests"]; -valid_path_constraints(suite) -> - []; +valid_path_constraints() -> + [{doc,"Basic constraint tests"}]. valid_path_constraints(Config) when is_list(Config) -> run([{ "4.6.7", "Valid pathLenConstraint Test7 EE", ok}, { "4.6.8", "Valid pathLenConstraint Test8 EE", ok}, @@ -453,10 +389,8 @@ valid_path_constraints(Config) when is_list(Config) -> { "4.6.17", "Valid Self-Issued pathLenConstraint Test17 EE", ok}]). %%-----------------------------key_usage------------------------------------------------ -invalid_key_usage(doc) -> - ["Key usage tests"]; -invalid_key_usage(suite) -> - []; +invalid_key_usage() -> + [{doc,"Key usage tests"}]. invalid_key_usage(Config) when is_list(Config) -> run([{ "4.7.1", "Invalid keyUsage Critical keyCertSign False Test1 EE", {bad_cert,invalid_key_usage} }, @@ -468,44 +402,40 @@ invalid_key_usage(Config) when is_list(Config) -> {bad_cert, invalid_key_usage}} ]). -valid_key_usage(doc) -> - ["Key usage tests"]; -valid_key_usage(suite) -> - []; +valid_key_usage() -> + [{doc,"Key usage tests"}]. valid_key_usage(Config) when is_list(Config) -> run([{ "4.7.3", "Valid keyUsage Not Critical Test3 EE", ok}]). %%----------------------------------------------------------------------------- -certificate_policies(doc) -> ["Not supported yet"]; -certificate_policies(suite) -> []; +certificate_policies() -> + [{doc,"Not supported yet"}]. certificate_policies(Config) when is_list(Config) -> - run(certificate_policies()). + run(certificate_policies_tests()). %%----------------------------------------------------------------------------- -require_explicit_policy(doc) -> ["Not supported yet"]; -require_explicit_policy(suite) -> []; +require_explicit_policy() -> + [{doc,"Not supported yet"}]. require_explicit_policy(Config) when is_list(Config) -> - run(require_explicit_policy()). + run(require_explicit_policy_tests()). %%----------------------------------------------------------------------------- -policy_mappings(doc) -> ["Not supported yet"]; -policy_mappings(suite) -> []; +policy_mappings() -> + [{doc,"Not supported yet"}]. policy_mappings(Config) when is_list(Config) -> - run(policy_mappings()). + run(policy_mappings_tests()). %%----------------------------------------------------------------------------- -inhibit_policy_mapping(doc) -> ["Not supported yet"]; -inhibit_policy_mapping(suite) -> []; +inhibit_policy_mapping() -> + [{doc,"Not supported yet"}]. inhibit_policy_mapping(Config) when is_list(Config) -> - run(inhibit_policy_mapping()). + run(inhibit_policy_mapping_tests()). %%----------------------------------------------------------------------------- -inhibit_any_policy(doc) -> ["Not supported yet"]; -inhibit_any_policy(suite) -> []; +inhibit_any_policy() -> + [{doc,"Not supported yet"}]. inhibit_any_policy(Config) when is_list(Config) -> - run(inhibit_any_policy()). + run(inhibit_any_policy_tests()). %%-------------------------------name_constraints---------------------------------------------- -valid_DN_name_constraints(doc) -> - ["Name constraints tests"]; -valid_DN_name_constraints(suite) -> - []; +valid_DN_name_constraints() -> + [{doc, "Name constraints tests"}]. valid_DN_name_constraints(Config) when is_list(Config) -> run([{ "4.13.1", "Valid DN nameConstraints Test1 EE", ok}, { "4.13.4", "Valid DN nameConstraints Test4 EE", ok}, @@ -516,10 +446,8 @@ valid_DN_name_constraints(Config) when is_list(Config) -> { "4.13.18", "Valid DN nameConstraints Test18 EE", ok}, { "4.13.19", "Valid DN nameConstraints Test19 EE", ok}]). -invalid_DN_name_constraints(doc) -> - ["Name constraints tests"]; -invalid_DN_name_constraints(suite) -> - []; +invalid_DN_name_constraints() -> + [{doc,"Name constraints tests"}]. invalid_DN_name_constraints(Config) when is_list(Config) -> run([{ "4.13.2", "Invalid DN nameConstraints Test2 EE", {bad_cert, name_not_permitted}}, { "4.13.3", "Invalid DN nameConstraints Test3 EE", {bad_cert, name_not_permitted}}, @@ -535,19 +463,15 @@ invalid_DN_name_constraints(Config) when is_list(Config) -> { "4.13.20", "Invalid DN nameConstraints Test20 EE", {bad_cert, name_not_permitted}}]). -valid_rfc822_name_constraints(doc) -> - ["Name constraints tests"]; -valid_rfc822_name_constraints(suite) -> - []; +valid_rfc822_name_constraints() -> + [{doc,"Name constraints tests"}]. valid_rfc822_name_constraints(Config) when is_list(Config) -> run([{ "4.13.21", "Valid RFC822 nameConstraints Test21 EE", ok}, { "4.13.23", "Valid RFC822 nameConstraints Test23 EE", ok}, { "4.13.25", "Valid RFC822 nameConstraints Test25 EE", ok}]). -invalid_rfc822_name_constraints(doc) -> - ["Name constraints tests"]; -invalid_rfc822_name_constraints(suite) -> - []; +invalid_rfc822_name_constraints() -> + [{doc,"Name constraints tests"}]. invalid_rfc822_name_constraints(Config) when is_list(Config) -> run([{ "4.13.22", "Invalid RFC822 nameConstraints Test22 EE", {bad_cert, name_not_permitted}}, @@ -556,70 +480,54 @@ invalid_rfc822_name_constraints(Config) when is_list(Config) -> { "4.13.26", "Invalid RFC822 nameConstraints Test26 EE", {bad_cert, name_not_permitted}}]). -valid_DN_and_rfc822_name_constraints(doc) -> - ["Name constraints tests"]; -valid_DN_and_rfc822_name_constraints(suite) -> - []; +valid_DN_and_rfc822_name_constraints() -> + [{doc,"Name constraints tests"}]. valid_DN_and_rfc822_name_constraints(Config) when is_list(Config) -> run([{ "4.13.27", "Valid DN and RFC822 nameConstraints Test27 EE", ok}]). -invalid_DN_and_rfc822_name_constraints(doc) -> - ["Name constraints tests"]; -invalid_DN_and_rfc822_name_constraints(suite) -> - []; +invalid_DN_and_rfc822_name_constraints() -> + [{doc,"Name constraints tests"}]. invalid_DN_and_rfc822_name_constraints(Config) when is_list(Config) -> run([{ "4.13.28", "Invalid DN and RFC822 nameConstraints Test28 EE", {bad_cert, name_not_permitted}}, { "4.13.29", "Invalid DN and RFC822 nameConstraints Test29 EE", {bad_cert, name_not_permitted}}]). -valid_dns_name_constraints(doc) -> - ["Name constraints tests"]; -valid_dns_name_constraints(suite) -> - []; +valid_dns_name_constraints() -> + [{doc,"Name constraints tests"}]. valid_dns_name_constraints(Config) when is_list(Config) -> run([{ "4.13.30", "Valid DNS nameConstraints Test30 EE", ok}, { "4.13.32", "Valid DNS nameConstraints Test32 EE", ok}]). -invalid_dns_name_constraints(doc) -> - ["Name constraints tests"]; -invalid_dns_name_constraints(suite) -> - []; +invalid_dns_name_constraints() -> + [{doc,"Name constraints tests"}]. invalid_dns_name_constraints(Config) when is_list(Config) -> run([{ "4.13.31", "Invalid DNS nameConstraints Test31 EE", {bad_cert, name_not_permitted}}, { "4.13.33", "Invalid DNS nameConstraints Test33 EE", {bad_cert, name_not_permitted}}, { "4.13.38", "Invalid DNS nameConstraints Test38 EE", {bad_cert, name_not_permitted}}]). -valid_uri_name_constraints(doc) -> - ["Name constraints tests"]; -valid_uri_name_constraints(suite) -> - []; +valid_uri_name_constraints() -> + [{doc,"Name constraints tests"}]. valid_uri_name_constraints(Config) when is_list(Config) -> run([{ "4.13.34", "Valid URI nameConstraints Test34 EE", ok}, { "4.13.36", "Valid URI nameConstraints Test36 EE", ok}]). -invalid_uri_name_constraints(doc) -> - ["Name constraints tests"]; -invalid_uri_name_constraints(suite) -> - []; +invalid_uri_name_constraints() -> + [{doc,"Name constraints tests"}]. invalid_uri_name_constraints(Config) when is_list(Config) -> run([{ "4.13.35", "Invalid URI nameConstraints Test35 EE",{bad_cert, name_not_permitted}}, { "4.13.37", "Invalid URI nameConstraints Test37 EE",{bad_cert, name_not_permitted}}]). %%------------------------------delta_crls----------------------------------------------- -delta_without_crl(doc) -> - ["Delta CRL tests"]; -delta_without_crl(suite) -> - []; +delta_without_crl() -> + [{doc,"Delta CRL tests"}]. delta_without_crl(Config) when is_list(Config) -> run([{ "4.15.1", "Invalid deltaCRLIndicator No Base Test1 EE",{bad_cert, revocation_status_undetermined}}, {"4.15.10", "Invalid delta-CRL Test10 EE", {bad_cert, revocation_status_undetermined}}]). -valid_delta_crls(doc) -> - ["Delta CRL tests"]; -valid_delta_crls(suite) -> - []; +valid_delta_crls() -> + [{doc,"Delta CRL tests"}]. valid_delta_crls(Config) when is_list(Config) -> run([{ "4.15.2", "Valid delta-CRL Test2 EE", ok}, { "4.15.5", "Valid delta-CRL Test5 EE", ok}, @@ -627,10 +535,8 @@ valid_delta_crls(Config) when is_list(Config) -> { "4.15.8", "Valid delta-CRL Test8 EE", ok} ]). -invalid_delta_crls(doc) -> - ["Delta CRL tests"]; -invalid_delta_crls(suite) -> - []; +invalid_delta_crls() -> + [{doc,"Delta CRL tests"}]. invalid_delta_crls(Config) when is_list(Config) -> run([{ "4.15.3", "Invalid delta-CRL Test3 EE", {bad_cert,{revoked, keyCompromise}}}, { "4.15.4", "Invalid delta-CRL Test4 EE", {bad_cert,{revoked, keyCompromise}}}, @@ -638,10 +544,8 @@ invalid_delta_crls(Config) when is_list(Config) -> { "4.15.9", "Invalid delta-CRL Test9 EE", {bad_cert,{revoked, keyCompromise}}}]). %%---------------------------distribution_points-------------------------------------------------- -valid_distribution_points(doc) -> - ["CRL Distribution Point tests"]; -valid_distribution_points(suite) -> - []; +valid_distribution_points() -> + [{doc,"CRL Distribution Point tests"}]. valid_distribution_points(Config) when is_list(Config) -> run([{ "4.14.1", "Valid distributionPoint Test1 EE", ok}, { "4.14.4", "Valid distributionPoint Test4 EE", ok}, @@ -649,18 +553,14 @@ valid_distribution_points(Config) when is_list(Config) -> { "4.14.7", "Valid distributionPoint Test7 EE", ok} ]). -valid_distribution_points_no_issuing_distribution_point(doc) -> - ["CRL Distribution Point tests"]; -valid_distribution_points_no_issuing_distribution_point(suite) -> - []; +valid_distribution_points_no_issuing_distribution_point() -> + [{doc,"CRL Distribution Point tests"}]. valid_distribution_points_no_issuing_distribution_point(Config) when is_list(Config) -> run([{ "4.14.10", "Valid No issuingDistributionPoint Test10 EE", ok} ]). -invalid_distribution_points(doc) -> - ["CRL Distribution Point tests"]; -invalid_distribution_points(suite) -> - []; +invalid_distribution_points() -> + [{doc,"CRL Distribution Point tests"}]. invalid_distribution_points(Config) when is_list(Config) -> run([{ "4.14.2", "Invalid distributionPoint Test2 EE", {bad_cert,{revoked, keyCompromise}}}, { "4.14.3", "Invalid distributionPoint Test3 EE", {bad_cert, @@ -672,17 +572,13 @@ invalid_distribution_points(Config) when is_list(Config) -> revocation_status_undetermined}} ]). -valid_only_contains(doc) -> - ["CRL Distribution Point tests"]; -valid_only_contains(suite) -> - []; +valid_only_contains() -> + [{doc,"CRL Distribution Point tests"}]. valid_only_contains(Config) when is_list(Config) -> run([{ "4.14.13", "Valid only Contains CA Certs Test13 EE", ok}]). -invalid_only_contains(doc) -> - ["CRL Distribution Point tests"]; -invalid_only_contains(suite) -> - []; +invalid_only_contains() -> + [{doc,"CRL Distribution Point tests"}]. invalid_only_contains(Config) when is_list(Config) -> run([{ "4.14.11", "Invalid onlyContainsUserCerts Test11 EE", {bad_cert, revocation_status_undetermined}}, @@ -692,19 +588,15 @@ invalid_only_contains(Config) when is_list(Config) -> {bad_cert, revocation_status_undetermined}} ]). -valid_only_some_reasons(doc) -> - ["CRL Distribution Point tests"]; -valid_only_some_reasons(suite) -> - []; +valid_only_some_reasons() -> + [{doc,"CRL Distribution Point tests"}]. valid_only_some_reasons(Config) when is_list(Config) -> run([{ "4.14.18", "Valid onlySomeReasons Test18 EE", ok}, { "4.14.19", "Valid onlySomeReasons Test19 EE", ok} ]). -invalid_only_some_reasons(doc) -> - ["CRL Distribution Point tests"]; -invalid_only_some_reasons(suite) -> - []; +invalid_only_some_reasons() -> + [{doc,"CRL Distribution Point tests"}]. invalid_only_some_reasons(Config) when is_list(Config) -> run([{ "4.14.15", "Invalid onlySomeReasons Test15 EE", {bad_cert,{revoked, keyCompromise}}}, @@ -718,20 +610,16 @@ invalid_only_some_reasons(Config) when is_list(Config) -> {bad_cert,{revoked, affiliationChanged}}} ]). -valid_indirect_crl(doc) -> - ["CRL Distribution Point tests"]; -valid_indirect_crl(suite) -> - []; +valid_indirect_crl() -> + [{doc,"CRL Distribution Point tests"}]. valid_indirect_crl(Config) when is_list(Config) -> run([{ "4.14.22", "Valid IDP with indirectCRL Test22 EE", ok}, { "4.14.24", "Valid IDP with indirectCRL Test24 EE", ok}, { "4.14.25", "Valid IDP with indirectCRL Test25 EE", ok} ]). -invalid_indirect_crl(doc) -> - ["CRL Distribution Point tests"]; -invalid_indirect_crl(suite) -> - []; +invalid_indirect_crl() -> + [{doc,"CRL Distribution Point tests"}]. invalid_indirect_crl(Config) when is_list(Config) -> run([{ "4.14.23", "Invalid IDP with indirectCRL Test23 EE", {bad_cert,{revoked, keyCompromise}}}, @@ -739,20 +627,16 @@ invalid_indirect_crl(Config) when is_list(Config) -> {bad_cert, revocation_status_undetermined}} ]). -valid_crl_issuer(doc) -> - ["CRL Distribution Point tests"]; -valid_crl_issuer(suite) -> - []; +valid_crl_issuer() -> + [{doc,"CRL Distribution Point tests"}]. valid_crl_issuer(Config) when is_list(Config) -> run([{ "4.14.28", "Valid cRLIssuer Test28 EE", ok}, { "4.14.29", "Valid cRLIssuer Test29 EE", ok}, { "4.14.33", "Valid cRLIssuer Test33 EE", ok} ]). -invalid_crl_issuer(doc) -> - ["CRL Distribution Point tests"]; -invalid_crl_issuer(suite) -> - []; +invalid_crl_issuer() -> + [{doc,"CRL Distribution Point tests"}]. invalid_crl_issuer(Config) when is_list(Config) -> run([ { "4.14.27", "Invalid cRLIssuer Test27 EE", {bad_cert, revocation_status_undetermined}}, @@ -771,25 +655,21 @@ invalid_crl_issuer(Config) when is_list(Config) -> %%-------------------------------private_certificate_extensions---------------------------------------------- -unknown_critical_extension(doc) -> - ["Test that a cert with an unknown critical extension is recjected"]; -unknown_critical_extension(suite) -> - []; +unknown_critical_extension() -> + [{doc,"Test that a cert with an unknown critical extension is recjected"}]. unknown_critical_extension(Config) when is_list(Config) -> run([{ "4.16.2", "Invalid Unknown Critical Certificate Extension Test2 EE", {bad_cert,unknown_critical_extension}}]). -unknown_not_critical_extension(doc) -> - ["Test that a not critical unknown extension is ignored"]; -unknown_not_critical_extension(suite) -> - []; +unknown_not_critical_extension() -> + [{doc,"Test that a not critical unknown extension is ignored"}]. unknown_not_critical_extension(Config) when is_list(Config) -> run([{ "4.16.1", "Valid Unknown Not Critical Certificate Extension Test1 EE", ok}]). -%%----------------------------------------------------------------------------- -%% Internal functions -%%----------------------------------------------------------------------------- -%% +%%-------------------------------------------------------------------- +%% Internal functions ------------------------------------------------ +%%-------------------------------------------------------------------- + run(Tests) -> [TA] = read_certs("Trust Anchor Root Certificate"), run(Tests, TA). @@ -906,7 +786,7 @@ crl_options(_TA, Chap, _Test) -> CRLs = crls(CRLNames), Paths = lists:map(fun(CRLName) -> crl_path(CRLName) end, CRLNames), - test_server:format("Paths ~p ~n Names ~p ~n", [Paths, CRLNames]), + ct:print("Paths ~p ~n Names ~p ~n", [Paths, CRLNames]), Fun = fun(_,{bad_cert, _} = Reason, _) -> {fail, Reason}; @@ -955,7 +835,7 @@ crl_path_db([{_, CRL} |CRLs], [Path | Paths], Acc) -> CertPath = lists:flatten(lists:map(fun([]) -> []; (CertFile) -> - test_server:format("Certfile ~p", [CertFile]), + ct:print("Certfile ~p", [CertFile]), read_certs(CertFile) end, Path)), crl_path_db(CRLs, Paths, [{CRL, CertPath}| Acc]). @@ -1620,7 +1500,7 @@ crls(CRLS) -> %% Certificate policy tests need special handling. They can have several %% sub tests and we need to check the outputs are correct. -certificate_policies() -> +certificate_policies_tests() -> %%{ "4.8", "Certificate Policies" }, [{"4.8.1.1", "All Certificates Same Policy Test1", "-policy anyPolicy -explicit_policy", "True", ?NIST1, ?NIST1, 0}, {"4.8.1.2", "All Certificates Same Policy Test1", "-policy ?NIST1BasicSelfIssuedCRLSigningKeyCACert.pem -explicit_policy", "True", ?NIST1, ?NIST1, 0}, @@ -1657,7 +1537,7 @@ certificate_policies() -> {"4.8.18.2", "User Notice Qualifier Test18", "-policy ?NIST2", "True", "?NIST1:?NIST2", "?NIST2", 0}, {"4.8.19", "User Notice Qualifier Test19", "-policy anyPolicy", "False", "?NIST1", "?NIST1", 0}, {"4.8.20", "CPS Pointer Qualifier Test20", "-policy anyPolicy -explicit_policy", "True", "?NIST1", "?NIST1", 0}]. -require_explicit_policy() -> +require_explicit_policy_tests() -> %%{ "4.9", "Require Explicit Policy" }, [{"4.9.1", "Valid RequireExplicitPolicy Test1", "-policy anyPolicy", "False", "<empty>", "<empty>", 0}, {"4.9.2", "Valid RequireExplicitPolicy Test2", "-policy anyPolicy", "False", "<empty>", "<empty>", 0}, @@ -1667,7 +1547,7 @@ require_explicit_policy() -> {"4.9.6", "Valid Self-Issued requireExplicitPolicy Test6", "-policy anyPolicy", "False", "<empty>", "<empty>", 0}, {"4.9.7", "Invalid Self-Issued requireExplicitPolicy Test7", "-policy anyPolicy", "True", "<empty>", "<empty>", 43}, {"4.9.8", "Invalid Self-Issued requireExplicitPolicy Test8", "-policy anyPolicy", "True", "<empty>", "<empty>", 43}]. -policy_mappings() -> +policy_mappings_tests() -> %%{ "4.10", "Policy Mappings" }, [{"4.10.1.1", "Valid Policy Mapping Test1", "-policy ?NIST1", "True", "?NIST1", "?NIST1", 0}, {"4.10.1.2", "Valid Policy Mapping Test1", "-policy ?NIST2", "True", "?NIST1", "<empty>", 43}, @@ -1697,7 +1577,7 @@ policy_mappings() -> %% TODO: check notice display {"4.10.14", "Valid Policy Mapping Test14", "-policy anyPolicy", "True", "?NIST1", "?NIST1", 0}]. -inhibit_policy_mapping() -> +inhibit_policy_mapping_tests() -> %%{ "4.11", "Inhibit Policy Mapping" }, [{"4.11.1", "Invalid inhibitPolicyMapping Test1", "-policy anyPolicy", "True", "<empty>", "<empty>", 43}, {"4.11.2", "Valid inhibitPolicyMapping Test2", "-policy anyPolicy", "True", "?NIST1", "?NIST1", 0}, @@ -1710,7 +1590,7 @@ inhibit_policy_mapping() -> {"4.11.9", "Invalid Self-Issued inhibitPolicyMapping Test9", "-policy anyPolicy", "True", "<empty>", "<empty>", 43}, {"4.11.10", "Invalid Self-Issued inhibitPolicyMapping Test10", "-policy anyPolicy", "True", "<empty>", "<empty>", 43}, {"4.11.11", "Invalid Self-Issued inhibitPolicyMapping Test11", "-policy anyPolicy", "True", "<empty>", "<empty>", 43}]. -inhibit_any_policy() -> +inhibit_any_policy_tests() -> %%{ "4.12", "Inhibit Any Policy" }, [{"4.12.1", "Invalid inhibitAnyPolicy Test1", "-policy anyPolicy", "True", "<empty>", "<empty>", 43}, {"4.12.2", "Valid inhibitAnyPolicy Test2", "-policy anyPolicy", "True", "?NIST1", "?NIST1", 0}, diff --git a/lib/public_key/test/public_key_SUITE.erl b/lib/public_key/test/public_key_SUITE.erl index 557092b690..ea48479f0b 100644 --- a/lib/public_key/test/public_key_SUITE.erl +++ b/lib/public_key/test/public_key_SUITE.erl @@ -20,85 +20,19 @@ %% -module(public_key_SUITE). +-include_lib("common_test/include/ct.hrl"). +-include_lib("public_key/include/public_key.hrl"). + %% Note: This directive should only be used in test suites. -compile(export_all). -%%-include_lib("common_test/include/ct.hrl"). --include_lib("test_server/include/test_server.hrl"). - --include_lib("public_key/include/public_key.hrl"). - -define(TIMEOUT, 120000). % 2 min -%% Test server callback functions -%%-------------------------------------------------------------------- -%% Function: init_per_suite(Config) -> Config -%% Config - [tuple()] -%% A list of key/value pairs, holding the test case configuration. -%% Description: Initialization before the whole suite -%% -%% Note: This function is free to add any key/value pairs to the Config -%% variable, but should NOT alter/remove any existing entries. -%%-------------------------------------------------------------------- -init_per_suite(Config) -> - try crypto:start() of - ok -> - Config - catch _:_ -> - {skip, "Crypto did not start"} - end. -%%-------------------------------------------------------------------- -%% Function: end_per_suite(Config) -> _ -%% Config - [tuple()] -%% A list of key/value pairs, holding the test case configuration. -%% Description: Cleanup after the whole suite -%%-------------------------------------------------------------------- -end_per_suite(_Config) -> - application:stop(crypto). %%-------------------------------------------------------------------- -%% Function: init_per_testcase(TestCase, Config) -> Config -%% Case - atom() -%% Name of the test case that is about to be run. -%% Config - [tuple()] -%% A list of key/value pairs, holding the test case configuration. -%% -%% Description: Initialization before each test case -%% -%% Note: This function is free to add any key/value pairs to the Config -%% variable, but should NOT alter/remove any existing entries. -%% Description: Initialization before each test case +%% Common Test interface functions ----------------------------------- %%-------------------------------------------------------------------- -init_per_testcase(_TestCase, Config0) -> - Config = lists:keydelete(watchdog, 1, Config0), - Dog = test_server:timetrap(?TIMEOUT), - [{watchdog, Dog} | Config]. -%%-------------------------------------------------------------------- -%% Function: end_per_testcase(TestCase, Config) -> _ -%% Case - atom() -%% Name of the test case that is about to be run. -%% Config - [tuple()] -%% A list of key/value pairs, holding the test case configuration. -%% Description: Cleanup after each test case -%%-------------------------------------------------------------------- -end_per_testcase(_TestCase, Config) -> - Dog = ?config(watchdog, Config), - case Dog of - undefined -> - ok; - _ -> - test_server:timetrap_cancel(Dog) - end. - -%%-------------------------------------------------------------------- -%% Function: all(Clause) -> TestCases -%% Clause - atom() - suite | doc -%% TestCases - [Case] -%% Case - atom() -%% Name of a test case. -%% Description: Returns a list of all test cases in this test suite -%%-------------------------------------------------------------------- suite() -> [{ct_hooks,[ts_install_cth]}]. all() -> @@ -119,30 +53,46 @@ groups() -> ssh_openssh_public_key_long_header]}, {sign_verify, [], [rsa_sign_verify, dsa_sign_verify]} ]. +%%------------------------------------------------------------------- +init_per_suite(Config) -> + try crypto:start() of + ok -> + Config + catch _:_ -> + {skip, "Crypto did not start"} + end. + +end_per_suite(_Config) -> + application:stop(crypto). +%%------------------------------------------------------------------- init_per_group(_GroupName, Config) -> Config. end_per_group(_GroupName, Config) -> Config. +%%------------------------------------------------------------------- +init_per_testcase(_TestCase, Config0) -> + Config = lists:keydelete(watchdog, 1, Config0), + Dog = ct:timetrap(?TIMEOUT), + [{watchdog, Dog} | Config]. -%% Test cases starts here. +end_per_testcase(_TestCase, _Config) -> + ok. +%%-------------------------------------------------------------------- +%% Test Cases -------------------------------------------------------- %%-------------------------------------------------------------------- -app(doc) -> - "Test that the public_key app file is ok"; -app(suite) -> - []; +app() -> + [{doc, "Test that the public_key app file is ok"}]. app(Config) when is_list(Config) -> - ok = test_server:app_test(public_key). + ok = ?t:app_test(public_key). %%-------------------------------------------------------------------- -dsa_pem(doc) -> - [""]; -dsa_pem(suite) -> - []; +dsa_pem() -> + [{doc, "DSA PEM-file decode/encode"}]. dsa_pem(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), @@ -164,10 +114,8 @@ dsa_pem(Config) when is_list(Config) -> %%-------------------------------------------------------------------- -rsa_pem(doc) -> - [""]; -rsa_pem(suite) -> - []; +rsa_pem() -> + [{doc, "RSA PEM-file decode/encode"}]. rsa_pem(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), [{'RSAPrivateKey', DerRSAKey, not_encrypted} = Entry0 ] = @@ -201,10 +149,8 @@ rsa_pem(Config) when is_list(Config) -> %%-------------------------------------------------------------------- -encrypted_pem(doc) -> - [""]; -encrypted_pem(suite) -> - []; +encrypted_pem() -> + [{doc, "Encrypted PEM-file decode/encode"}]. encrypted_pem(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), @@ -234,10 +180,8 @@ encrypted_pem(Config) when is_list(Config) -> %%-------------------------------------------------------------------- -dh_pem(doc) -> - [""]; -dh_pem(suite) -> - []; +dh_pem() -> + [{doc, "DH parametrs PEM-file decode/encode"}]. dh_pem(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), [{'DHParameter', DerDH, not_encrypted} = Entry] = @@ -252,10 +196,8 @@ dh_pem(Config) when is_list(Config) -> %%-------------------------------------------------------------------- -pkcs10_pem(doc) -> - [""]; -pkcs10_pem(suite) -> - []; +pkcs10_pem() -> + [{doc, "PKCS-10 PEM-file decode/encode"}]. pkcs10_pem(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), [{'CertificationRequest', DerPKCS10, not_encrypted} = Entry] = @@ -269,10 +211,8 @@ pkcs10_pem(Config) when is_list(Config) -> Entry = public_key:pem_entry_encode('CertificationRequest', PKCS10). %%-------------------------------------------------------------------- -pkcs7_pem(doc) -> - [""]; -pkcs7_pem(suite) -> - []; +pkcs7_pem() -> + [{doc, "PKCS-7 PEM-file decode/encode"}]. pkcs7_pem(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), [{'ContentInfo', DerPKCS7, not_encrypted} = Entry] = @@ -286,10 +226,8 @@ pkcs7_pem(Config) when is_list(Config) -> Entry = public_key:pem_entry_encode('ContentInfo', PKCS7). %%-------------------------------------------------------------------- -cert_pem(doc) -> - [""]; -cert_pem(suite) -> - []; +cert_pem() -> + [{doc, "Certificate PEM-file decode/encode"}]. cert_pem(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), @@ -315,10 +253,8 @@ cert_pem(Config) when is_list(Config) -> [Entry0] = erl_make_certs:pem_to_der(filename:join(Datadir, "wdsa.pem")). %%-------------------------------------------------------------------- -ssh_rsa_public_key(doc) -> - ""; -ssh_rsa_public_key(suite) -> - []; +ssh_rsa_public_key() -> + [{doc, "ssh rsa public key decode/encode"}]. ssh_rsa_public_key(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), @@ -343,10 +279,8 @@ ssh_rsa_public_key(Config) when is_list(Config) -> %%-------------------------------------------------------------------- -ssh_dsa_public_key(doc) -> - ""; -ssh_dsa_public_key(suite) -> - []; +ssh_dsa_public_key() -> + [{doc, "ssh dsa public key decode/encode"}]. ssh_dsa_public_key(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), @@ -370,10 +304,8 @@ ssh_dsa_public_key(Config) when is_list(Config) -> public_key:ssh_decode(EncodedOpenSsh, public_key). %%-------------------------------------------------------------------- -ssh_rfc4716_rsa_comment(doc) -> - "Test comment header and rsa key"; -ssh_rfc4716_rsa_comment(suite) -> - []; +ssh_rfc4716_rsa_comment() -> + [{doc, "Test comment header and rsa key"}]. ssh_rfc4716_rsa_comment(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), @@ -388,10 +320,8 @@ ssh_rfc4716_rsa_comment(Config) when is_list(Config) -> RSARawSsh2 = public_key:ssh_encode([{PubKey, Attributes}], rfc4716_public_key). %%-------------------------------------------------------------------- -ssh_rfc4716_dsa_comment(doc) -> - "Test comment header and dsa key"; -ssh_rfc4716_dsa_comment(suite) -> - []; +ssh_rfc4716_dsa_comment() -> + [{doc, "Test comment header and dsa key"}]. ssh_rfc4716_dsa_comment(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), @@ -410,10 +340,8 @@ ssh_rfc4716_dsa_comment(Config) when is_list(Config) -> public_key:ssh_decode(Encoded, public_key). %%-------------------------------------------------------------------- -ssh_rfc4716_rsa_subject(doc) -> - "Test another header value than comment"; -ssh_rfc4716_rsa_subject(suite) -> - []; +ssh_rfc4716_rsa_subject() -> + [{doc, "Test another header value than comment"}]. ssh_rfc4716_rsa_subject(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), @@ -432,10 +360,8 @@ ssh_rfc4716_rsa_subject(Config) when is_list(Config) -> public_key:ssh_decode(Encoded, public_key). %%-------------------------------------------------------------------- -ssh_known_hosts(doc) -> - ""; -ssh_known_hosts(suite) -> - []; +ssh_known_hosts() -> + [{doc, "ssh known hosts file encode/decode"}]. ssh_known_hosts(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), @@ -463,10 +389,8 @@ ssh_known_hosts(Config) when is_list(Config) -> %%-------------------------------------------------------------------- -ssh1_known_hosts(doc) -> - ""; -ssh1_known_hosts(suite) -> - []; +ssh1_known_hosts() -> + [{doc, "ssh (ver 1) known hosts file encode/decode"}]. ssh1_known_hosts(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), @@ -485,10 +409,8 @@ ssh1_known_hosts(Config) when is_list(Config) -> Decoded = public_key:ssh_decode(Encoded, known_hosts). %%-------------------------------------------------------------------- -ssh_auth_keys(doc) -> - ""; -ssh_auth_keys(suite) -> - []; +ssh_auth_keys() -> + [{doc, "ssh authorized keys file encode/decode"}]. ssh_auth_keys(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), @@ -513,10 +435,8 @@ ssh_auth_keys(Config) when is_list(Config) -> Decoded = public_key:ssh_decode(Encoded, auth_keys). %%-------------------------------------------------------------------- -ssh1_auth_keys(doc) -> - ""; -ssh1_auth_keys(suite) -> - []; +ssh1_auth_keys() -> + [{doc, "ssh (ver 1) authorized keys file encode/decode"}]. ssh1_auth_keys(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), @@ -543,10 +463,8 @@ ssh1_auth_keys(Config) when is_list(Config) -> Decoded = public_key:ssh_decode(Encoded, auth_keys). %%-------------------------------------------------------------------- -ssh_openssh_public_key_with_comment(doc) -> - "Test that emty lines and lines starting with # are ignored"; -ssh_openssh_public_key_with_comment(suite) -> - []; +ssh_openssh_public_key_with_comment() -> + [{doc, "Test that emty lines and lines starting with # are ignored"}]. ssh_openssh_public_key_with_comment(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), @@ -554,10 +472,8 @@ ssh_openssh_public_key_with_comment(Config) when is_list(Config) -> [{{_, #'Dss-Parms'{}}, _}] = public_key:ssh_decode(DSARawOpenSsh, openssh_public_key). %%-------------------------------------------------------------------- -ssh_openssh_public_key_long_header(doc) -> - "Test that long headers are handled"; -ssh_openssh_public_key_long_header(suite) -> - []; +ssh_openssh_public_key_long_header() -> + [{doc, "Test that long headers are handled"}]. ssh_openssh_public_key_long_header(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), @@ -568,10 +484,8 @@ ssh_openssh_public_key_long_header(Config) when is_list(Config) -> Decoded = public_key:ssh_decode(Encoded, rfc4716_public_key). %%-------------------------------------------------------------------- -encrypt_decrypt(doc) -> - [""]; -encrypt_decrypt(suite) -> - []; +encrypt_decrypt() -> + [{doc, "Test public_key:encrypt_private and public_key:decrypt_public"}]. encrypt_decrypt(Config) when is_list(Config) -> {PrivateKey, _DerKey} = erl_make_certs:gen_rsa(64), #'RSAPrivateKey'{modulus=Mod, publicExponent=Exp} = PrivateKey, @@ -588,10 +502,8 @@ encrypt_decrypt(Config) when is_list(Config) -> ok. %%-------------------------------------------------------------------- -rsa_sign_verify(doc) -> - ["Checks that we can sign and verify rsa signatures."]; -rsa_sign_verify(suite) -> - []; +rsa_sign_verify() -> + [{doc, "Checks that we can sign and verify rsa signatures."}]. rsa_sign_verify(Config) when is_list(Config) -> Ca = {_, CaKey} = erl_make_certs:make_cert([]), {Cert1, _} = erl_make_certs:make_cert([{key, dsa}, {issuer, Ca}]), @@ -611,10 +523,8 @@ rsa_sign_verify(Config) when is_list(Config) -> %%-------------------------------------------------------------------- -dsa_sign_verify(doc) -> - ["Checks that we can sign and verify dsa signatures."]; -dsa_sign_verify(suite) -> - []; +dsa_sign_verify() -> + [{doc, "Checks that we can sign and verify dsa signatures."}]. dsa_sign_verify(Config) when is_list(Config) -> Ca = erl_make_certs:make_cert([]), CertInfo = {_,CertKey1} = erl_make_certs:make_cert([{key, dsa}, {issuer, Ca}]), @@ -650,10 +560,8 @@ dsa_sign_verify(Config) when is_list(Config) -> {DSAPublicKey, DSAParams}). %%-------------------------------------------------------------------- -pkix(doc) -> - "Misc pkix tests not covered elsewhere"; -pkix(suite) -> - []; +pkix() -> + [{doc, "Misc pkix tests not covered elsewhere"}]. pkix(Config) when is_list(Config) -> Datadir = ?config(data_dir, Config), Certs0 = erl_make_certs:pem_to_der(filename:join(Datadir, "cacerts.pem")), @@ -698,10 +606,8 @@ pkix(Config) when is_list(Config) -> ok. %%-------------------------------------------------------------------- -pkix_countryname(doc) -> - "Test workaround for certs that code x509countryname as utf8"; -pkix_countryname(suite) -> - []; +pkix_countryname() -> + [{doc, "Test workaround for certs that code x509countryname as utf8"}]. pkix_countryname(Config) when is_list(Config) -> Cert = incorrect_pkix_cert(), OTPCert = public_key:pkix_decode_cert(Cert, otp), @@ -711,24 +617,9 @@ pkix_countryname(Config) when is_list(Config) -> check_countryname(Issuer), check_countryname(Subj). -check_countryname({rdnSequence,DirName}) -> - do_check_countryname(DirName). -do_check_countryname([]) -> - ok; -do_check_countryname([#'AttributeTypeAndValue'{type = ?'id-at-countryName', - value = "US"}|_]) -> - ok; -do_check_countryname([#'AttributeTypeAndValue'{type = ?'id-at-countryName', - value = Value}|_]) -> - test_server:fail({incorrect_cuntry_name, Value}); -do_check_countryname([_| Rest]) -> - do_check_countryname(Rest). - %%-------------------------------------------------------------------- -pkix_path_validation(doc) -> - "Misc pkix tests not covered elsewhere"; -pkix_path_validation(suite) -> - []; +pkix_path_validation() -> + [{doc, "Test PKIX path validation"}]. pkix_path_validation(Config) when is_list(Config) -> CaK = {Trusted,_} = erl_make_certs:make_cert([{key, dsa}, @@ -797,6 +688,21 @@ pkix_path_validation(Config) when is_list(Config) -> public_key:pkix_path_validation(unknown_ca, [Cert1], [{verify_fun, VerifyFunAndState1}]), ok. +%%-------------------------------------------------------------------- +%% Internal functions ------------------------------------------------ +%%-------------------------------------------------------------------- +check_countryname({rdnSequence,DirName}) -> + do_check_countryname(DirName). +do_check_countryname([]) -> + ok; +do_check_countryname([#'AttributeTypeAndValue'{type = ?'id-at-countryName', + value = "US"}|_]) -> + ok; +do_check_countryname([#'AttributeTypeAndValue'{type = ?'id-at-countryName', + value = Value}|_]) -> + ct:fail({incorrect_cuntry_name, Value}); +do_check_countryname([_| Rest]) -> + do_check_countryname(Rest). check_entry_type(#'DSAPrivateKey'{}, 'DSAPrivateKey') -> true; |