Add a couple of additional tests to sess_mgmt.c testcase to
make sure that we're handling invalid session handles OK.

Signed-off-by: Klaus Heinrich Kiwi <[email protected]>
---
 testcases/driver/sess_mgmt.c |   62 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/testcases/driver/sess_mgmt.c b/testcases/driver/sess_mgmt.c
index a0d7488..7c251d1 100755
--- a/testcases/driver/sess_mgmt.c
+++ b/testcases/driver/sess_mgmt.c
@@ -43,6 +43,7 @@ int do_OpenSession( void )
        CK_SLOT_ID        slot_id;
        CK_FLAGS          flags;
        CK_SESSION_HANDLE handle;
+        CK_SESSION_INFO   info;
        CK_RV             rc;
 
        printf("do_OpenSession...\n");
@@ -62,6 +63,13 @@ int do_OpenSession( void )
                return FALSE;
        }
 
+       rc = funcs->C_GetSessionInfo( handle, &info );
+       show_error("   C_GetSessionInfo #1 (should fail)", rc );
+       if (rc == CKR_OK) {
+                return FALSE;
+       }
+
+
        printf("Looks okay...\n");
 
        return TRUE;
@@ -1155,6 +1163,53 @@ int do_OperationState3( void )
        return TRUE;
 }
 
+//
+//
+int do_UseInvalidSession( void )
+{
+        CK_SLOT_ID        slot_id;
+       CK_SESSION_HANDLE handle;
+        CK_SESSION_INFO   info;
+       CK_RV             rc;
+
+       printf("do_UseInvalidSession...\n");
+
+        slot_id = SLOT_ID;
+
+       rc = funcs->C_CloseAllSessions( slot_id );
+       if (rc != CKR_OK) {
+               show_error("   C_CloseAllSessions", rc );
+               return FALSE;
+       }
+
+        printf("C_GetSessionInfo(CK_INVALID_HANDLE, ...) - should fail\n");
+        handle = CK_INVALID_HANDLE;
+       rc = funcs->C_GetSessionInfo( handle, &info );
+       show_error("   C_GetSessionInfo #1", rc );
+       if (rc == CKR_OK) {
+                return FALSE;
+       }
+
+        printf("C_GetSessionInfo(-1, ...) - should fail\n");
+        handle = (CK_SESSION_HANDLE) -1;
+       rc = funcs->C_GetSessionInfo( handle, &info );
+       show_error("   C_GetSessionInfo #2", rc );
+       if (rc == CKR_OK) {
+                return FALSE;
+       }
+
+        printf("C_GetSessionInfo(0x9a8a8000, ...) - should fail\n");
+        handle = (CK_SESSION_HANDLE) 0x9a8a8000;
+       rc = funcs->C_GetSessionInfo( handle, &info );
+       show_error("   C_GetSessionInfo #3", rc );
+       if (rc == CKR_OK) {
+                return FALSE;
+       }
+
+       printf("Looks okay...\n");
+
+       return TRUE;
+}
 int main(int argc, char **argv)
 {
        CK_C_INITIALIZE_ARGS cinit_args;
@@ -1265,5 +1320,12 @@ int sess_mgmt_functions()
        GetSystemTime(&t2);
        process_time( t1, t2 );
 
+       GetSystemTime(&t1);
+        rc = do_UseInvalidSession();
+       if (!rc && !no_stop)
+               return FALSE;
+       GetSystemTime(&t2);
+       process_time( t1, t2 );
+
        return TRUE;
 }
-- 
1.6.6.1


------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Opencryptoki-tech mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opencryptoki-tech

Reply via email to