aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-12-19 19:30:35 -0500
committerJack Lloyd <[email protected]>2016-12-19 19:30:35 -0500
commitc304620247b5281950eb58b13bada74ca20c6477 (patch)
tree6bcc4c1a45bef537ffdfcaf1e1496cbb83b68c2d
parent97905c5243bfbdcb00a07f7915c58981e6890bbe (diff)
parent146ecb8c31215a1c75336681bf1f0c37fc0937d7 (diff)
Merge GH #780 Add more PKCS11 tests
-rw-r--r--src/tests/test_pkcs11_high_level.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/tests/test_pkcs11_high_level.cpp b/src/tests/test_pkcs11_high_level.cpp
index b82dbdca7..10723d6b2 100644
--- a/src/tests/test_pkcs11_high_level.cpp
+++ b/src/tests/test_pkcs11_high_level.cpp
@@ -213,6 +213,39 @@ Test::Result test_get_slot_info()
return result;
}
+SlotId get_invalid_slot_id(Module& module)
+ {
+ std::vector<SlotId> slot_vec = Slot::get_available_slots(module, false);
+
+ SlotId invalid_id = 0;
+
+ // find invalid slot id
+ while(std::find(slot_vec.begin(), slot_vec.end(), invalid_id) != slot_vec.end())
+ {
+ invalid_id++;
+ }
+
+ return invalid_id;
+ }
+
+Test::Result test_slot_invalid_id()
+ {
+ Test::Result result("Slot get_slot_info with invalid slot id");
+
+ Module module(Test::pkcs11_lib());
+
+ SlotId invalid_id = get_invalid_slot_id(module);
+
+ Slot slot(module, invalid_id);
+
+ result.test_throws("get_slot_info fails for non existent slot id", [ &slot ]()
+ {
+ slot.get_slot_info();
+ });
+
+ return result;
+ }
+
Test::Result test_get_token_info()
{
Test::Result result("Slot get_token_info");
@@ -266,6 +299,7 @@ class Slot_Tests : public PKCS11_Test
test_slot_get_available_slots,
test_slot_ctor,
test_get_slot_info,
+ test_slot_invalid_id,
test_get_token_info,
test_get_mechanism_list,
test_get_mechanisms_info
@@ -309,6 +343,23 @@ Test::Result test_session_ctor()
return result;
}
+Test::Result test_session_ctor_invalid_slot()
+ {
+ Test::Result result("Session ctor with invalid slot id");
+
+ Module module(Test::pkcs11_lib());
+
+ SlotId invalid_id = get_invalid_slot_id(module);
+ Slot slot(module, invalid_id);
+
+ result.test_throws("Session ctor with invalid slot id fails", [&slot]()
+ {
+ Session session(slot, true);
+ });
+
+ return result;
+ }
+
Test::Result test_session_release()
{
Test::Result result("Session release/take ownership");
@@ -381,6 +432,7 @@ class Session_Tests : public PKCS11_Test
std::vector<std::function<Test::Result()>> fns =
{
test_session_ctor,
+ test_session_ctor_invalid_slot,
test_session_release,
test_session_login_logout,
test_session_info