Skip to content

Commit 07c88c1

Browse files
add WH_TEST_SKIP and authentication skipping when server does not support auth
1 parent d22ad58 commit 07c88c1

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

test/wh_test_auth.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,11 @@ int whTest_AuthLogin(whClientContext* client)
576576
WH_TEST_RETURN_ON_FAIL(
577577
_whTest_Auth_LoginOp(client, WH_AUTH_METHOD_PIN, TEST_ADMIN_USERNAME,
578578
"wrong", 5, &server_rc, &user_id));
579+
if (server_rc == WH_AUTH_NOT_ENABLED) {
580+
WH_TEST_PRINT("Server does not support authentication, skipping "
581+
"authentication tests\n");
582+
return WH_AUTH_NOT_ENABLED;
583+
}
579584
WH_TEST_ASSERT_RETURN(server_rc == WH_AUTH_LOGIN_FAILED ||
580585
server_rc != WH_ERROR_OK);
581586
WH_TEST_ASSERT_RETURN(user_id == WH_USER_ID_INVALID);
@@ -1165,11 +1170,35 @@ int whTest_AuthRequestAuthorization(whClientContext* client)
11651170
return WH_TEST_SUCCESS;
11661171
}
11671172

1173+
1174+
static int CheckServerSupportsAuth(whClientContext* client_ctx)
1175+
{
1176+
int32_t server_rc;
1177+
whUserId user_id;
1178+
int isSupported = 0;
1179+
1180+
WH_TEST_RETURN_ON_FAIL(wh_Client_AuthLogin(client_ctx, WH_AUTH_METHOD_PIN,
1181+
TEST_ADMIN_USERNAME, TEST_ADMIN_PIN, strlen(TEST_ADMIN_PIN), &server_rc,
1182+
&user_id));
1183+
if (server_rc != WH_AUTH_NOT_ENABLED) {
1184+
WH_TEST_RETURN_ON_FAIL(wh_Client_AuthLogout(client_ctx, user_id,
1185+
&server_rc));
1186+
isSupported = 1;
1187+
}
1188+
return isSupported;
1189+
}
1190+
11681191
/* Main Test Function */
11691192
int whTest_AuthTest(whClientContext* client_ctx)
11701193
{
11711194
WH_TEST_PRINT("Testing authentication functionality...\n");
11721195

1196+
if (!CheckServerSupportsAuth(client_ctx)) {
1197+
WH_TEST_PRINT("Server does not support authentication, skipping "
1198+
"authentication tests\n");
1199+
return WH_TEST_SKIP;
1200+
}
1201+
11731202
WH_TEST_PRINT("Running auth bad-args tests...\n");
11741203
WH_TEST_RETURN_ON_FAIL(_whTest_Auth_BadArgs());
11751204
WH_TEST_PRINT("Running auth message bad-args tests...\n");

test/wh_test_common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#define WH_TEST_FAIL (-1)
3535
#define WH_TEST_SUCCESS (0)
36+
#define WH_TEST_SKIP (1)
3637
#define WH_TEST_DEFAULT_CLIENT_ID (1)
3738

3839
/* Test-specific print macro that always prints (replacement for printf in tests)
@@ -75,7 +76,7 @@
7576
#define WH_TEST_RETURN_ON_FAIL(call) \
7677
do { \
7778
int ret = (call); \
78-
if (ret != 0) { \
79+
if (ret != WH_TEST_SUCCESS && ret != WH_TEST_SKIP) { \
7980
WH_ERROR_PRINT(#call ": ret=%d\n", ret); \
8081
return ret; \
8182
} \

test/wh_test_crypto.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5757,10 +5757,12 @@ int whTest_CryptoClientConfig(whClientConfig* config)
57575757

57585758
if (ret == 0) {
57595759
#ifdef WOLFHSM_CFG_ENABLE_AUTHENTICATION
5760+
int serverRc;
5761+
57605762
/* Attempt log in as an admin user for the rest of the tests */
57615763
WH_TEST_RETURN_ON_FAIL(wh_Client_AuthLogin(client, WH_AUTH_METHOD_PIN,
57625764
TEST_ADMIN_USERNAME, TEST_ADMIN_PIN, strlen(TEST_ADMIN_PIN),
5763-
NULL, NULL));
5765+
&serverRc, NULL));
57645766
#endif /* WOLFHSM_CFG_ENABLE_AUTHENTICATION */
57655767
}
57665768

0 commit comments

Comments
 (0)