aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2015-12-21 10:37:54 -0500
committerJack Lloyd <[email protected]>2015-12-21 10:37:54 -0500
commit3467948a1fd8c0e12650197e9e29636e57b0fcdb (patch)
tree0fb1b295864d137ef78c1921b60a7d689d14ee5a /src/tests
parent66fb50a462d72c106bd4a4102a1faff92bd5f7e2 (diff)
Add missing try/catch in signature verification test.
Improve diagnostics when an exception escapes a test GH #369
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/main.cpp2
-rw-r--r--src/tests/test_pubkey.cpp24
-rw-r--r--src/tests/tests.cpp16
-rw-r--r--src/tests/tests.h2
4 files changed, 30 insertions, 14 deletions
diff --git a/src/tests/main.cpp b/src/tests/main.cpp
index 0a09bacc3..692bc41af 100644
--- a/src/tests/main.cpp
+++ b/src/tests/main.cpp
@@ -161,7 +161,7 @@ class Test_Runner : public Botan_CLI::Command
auto i = combined.find(who);
if(i == combined.end())
{
- combined[who] = Botan_Tests::Test::Result(who);
+ combined.insert(std::make_pair(who, Botan_Tests::Test::Result(who)));
i = combined.find(who);
}
diff --git a/src/tests/test_pubkey.cpp b/src/tests/test_pubkey.cpp
index db2a0ae31..fa6146bf8 100644
--- a/src/tests/test_pubkey.cpp
+++ b/src/tests/test_pubkey.cpp
@@ -116,7 +116,8 @@ PK_Signature_Generation_Test::run_one_test(const std::string&, const VarMap& var
rng.reset(new Fixed_Output_RNG(get_req_bin(vars, "Nonce")));
}
- const std::vector<uint8_t> generated_signature = signer->sign_message(message, rng ? *rng : Test::rng());
+ const std::vector<uint8_t> generated_signature =
+ signer->sign_message(message, rng ? *rng : Test::rng());
if(sign_provider == "base")
{
@@ -161,11 +162,21 @@ PK_Signature_Verification_Test::run_one_test(const std::string&, const VarMap& v
Test::Result result(algo_name() + "/" + padding + " signature verification");
- Botan::PK_Verifier verifier(*pubkey, padding);
-
- result.test_eq("correct signature valid", verifier.verify_message(message, signature), true);
+ for(auto&& verify_provider : possible_pk_providers())
+ {
+ std::unique_ptr<Botan::PK_Verifier> verifier;
- check_invalid_signatures(result, verifier, message, signature);
+ try
+ {
+ verifier.reset(new Botan::PK_Verifier(*pubkey, padding, Botan::IEEE_1363, verify_provider));
+ result.test_eq("correct signature valid", verifier->verify_message(message, signature), true);
+ check_invalid_signatures(result, *verifier, message, signature);
+ }
+ catch(Botan::Lookup_Error&)
+ {
+ result.test_note("Skipping verifying with " + verify_provider);
+ }
+ }
return result;
}
@@ -184,6 +195,7 @@ PK_Encryption_Decryption_Test::run_one_test(const std::string&, const VarMap& va
// instead slice the private key to work around elgamal test inputs
//std::unique_ptr<Botan::Public_Key> pubkey(Botan::X509::load_key(Botan::X509::BER_encode(*privkey)));
+ Botan::Public_Key* pubkey = privkey.get();
for(auto&& enc_provider : possible_pk_providers())
{
@@ -191,7 +203,7 @@ PK_Encryption_Decryption_Test::run_one_test(const std::string&, const VarMap& va
try
{
- encryptor.reset(new Botan::PK_Encryptor_EME(*privkey, padding, enc_provider));
+ encryptor.reset(new Botan::PK_Encryptor_EME(*pubkey, padding, enc_provider));
}
catch(Botan::Lookup_Error&)
{
diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp
index b0292926e..4d035c0c8 100644
--- a/src/tests/tests.cpp
+++ b/src/tests/tests.cpp
@@ -667,7 +667,7 @@ std::vector<Test::Result> Text_Based_Test::run()
{
std::vector<Test::Result> results;
- std::string who;
+ std::string header, header_or_name = m_data_src;
VarMap vars;
size_t test_cnt = 0;
@@ -679,7 +679,8 @@ std::vector<Test::Result> Text_Based_Test::run()
if(line[0] == '[' && line[line.size()-1] == ']')
{
- who = line.substr(1, line.size() - 2);
+ header = line.substr(1, line.size() - 2);
+ header_or_name = header;
test_cnt = 0;
continue;
}
@@ -690,7 +691,8 @@ std::vector<Test::Result> Text_Based_Test::run()
if(equal_i == std::string::npos)
{
- results.push_back(Test::Result::Failure(who, "invalid input '" + line + "'"));
+ results.push_back(Test::Result::Failure(header_or_name,
+ "invalid input '" + line + "'"));
continue;
}
@@ -698,7 +700,8 @@ std::vector<Test::Result> Text_Based_Test::run()
std::string val = strip_ws(std::string(line.begin() + equal_i + 1, line.end()));
if(m_required_keys.count(key) == 0 && m_optional_keys.count(key) == 0)
- results.push_back(Test::Result::Failure(who, test_id + " failed unknown key " + key));
+ results.push_back(Test::Result::Failure(header_or_name,
+ test_id + " failed unknown key " + key));
vars[key] = val;
@@ -709,7 +712,7 @@ std::vector<Test::Result> Text_Based_Test::run()
++test_cnt;
uint64_t start = Test::timestamp();
- Test::Result result = run_one_test(who, vars);
+ Test::Result result = run_one_test(header, vars);
result.set_ns_consumed(Test::timestamp() - start);
if(result.tests_failed())
@@ -718,7 +721,8 @@ std::vector<Test::Result> Text_Based_Test::run()
}
catch(std::exception& e)
{
- results.push_back(Test::Result::Failure(who, "test " + std::to_string(test_cnt) +
+ results.push_back(Test::Result::Failure(header_or_name,
+ "test " + std::to_string(test_cnt) +
" failed with exception '" + e.what() + "'"));
}
diff --git a/src/tests/tests.h b/src/tests/tests.h
index c38145504..e12f5f6de 100644
--- a/src/tests/tests.h
+++ b/src/tests/tests.h
@@ -61,7 +61,7 @@ class Test
class Result
{
public:
- Result(const std::string& who = "") : m_who(who) {}
+ Result(const std::string& who) : m_who(who) {}
size_t tests_passed() const { return m_tests_passed; }
size_t tests_failed() const { return m_fail_log.size(); }