Skip to content

Commit 27c6b08

Browse files
add client only tcp auth tests
1 parent 8c8b9f5 commit 27c6b08

5 files changed

Lines changed: 461 additions & 281 deletions

File tree

examples/posix/wh_posix_server/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ endif
5959
# Set to @ if you want to suppress command echo
6060
CMD_ECHO ?=
6161

62+
# Add code coverage option
63+
ifeq ($(COVERAGE),1)
64+
CFLAGS += --coverage
65+
LDFLAGS += --coverage
66+
endif
67+
6268
# Check if DEBUG is set to 1 and append debug flags
6369
ifeq ($(DEBUG),1)
6470
DBGFLAGS = -ggdb -g3

src/wh_auth_base.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,17 @@ int wh_AuthBase_UserAdd(void* context, const char* username,
377377

378378
int wh_AuthBase_UserDelete(void* context, uint16_t current_user_id, uint16_t user_id)
379379
{
380-
whAuthBase_User* user = &users[user_id - 1];
380+
whAuthBase_User* user;
381+
382+
if (user_id == WH_USER_ID_INVALID || user_id >= WH_AUTH_BASE_MAX_USERS) {
383+
return WH_ERROR_NOTFOUND;
384+
}
385+
386+
user = &users[user_id - 1];
381387
if (user->user.user_id == WH_USER_ID_INVALID) {
382388
return WH_ERROR_NOTFOUND;
383389
}
390+
384391
memset(user, 0, sizeof(whAuthBase_User));
385392
(void)context;
386393
(void)current_user_id;
@@ -390,7 +397,13 @@ int wh_AuthBase_UserDelete(void* context, uint16_t current_user_id, uint16_t use
390397
int wh_AuthBase_UserSetPermissions(void* context, uint16_t current_user_id,
391398
uint16_t user_id, whAuthPermissions permissions)
392399
{
393-
whAuthBase_User* user = &users[user_id - 1];
400+
whAuthBase_User* user;
401+
402+
if (user_id == WH_USER_ID_INVALID || user_id >= WH_AUTH_BASE_MAX_USERS) {
403+
return WH_ERROR_NOTFOUND;
404+
}
405+
406+
user = &users[user_id - 1];
394407
if (user->user.user_id == WH_USER_ID_INVALID) {
395408
return WH_ERROR_NOTFOUND;
396409
}
@@ -435,7 +448,7 @@ int wh_AuthBase_UserSetCredentials(void* context, uint16_t user_id,
435448
whAuthBase_User* user;
436449
int rc = WH_ERROR_OK;
437450

438-
if (user_id == WH_USER_ID_INVALID) {
451+
if (user_id == WH_USER_ID_INVALID || user_id >= WH_AUTH_BASE_MAX_USERS) {
439452
return WH_ERROR_BADARGS;
440453
}
441454

@@ -445,7 +458,6 @@ int wh_AuthBase_UserSetCredentials(void* context, uint16_t user_id,
445458
}
446459

447460
user = &users[user_id - 1]; /* subtract 1 to get the index */
448-
449461
if (user->user.user_id == WH_USER_ID_INVALID) {
450462
return WH_ERROR_NOTFOUND;
451463
}

test/wh_test.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ int whTest_Unit(void)
8989
WH_TEST_ASSERT(0 == whTest_ClientServer());
9090

9191
/* Auth tests */
92-
WH_TEST_ASSERT(0 == whTest_Auth());
92+
WH_TEST_ASSERT(0 == whTest_AuthMEM());
9393

9494
#ifndef WOLFHSM_CFG_NO_CRYPTO
9595
/* Crypto Tests */
@@ -150,6 +150,8 @@ int whTest_ClientConfig(whClientConfig* clientCfg)
150150
WH_TEST_RETURN_ON_FAIL(whTest_WolfCryptTestCfg(clientCfg));
151151
#endif /* WOLFHSM_CFG_TEST_WOLFCRYPTTEST */
152152

153+
WH_TEST_RETURN_ON_FAIL(whTest_AuthTCP(clientCfg));
154+
153155
return WH_ERROR_OK;
154156
}
155157

0 commit comments

Comments
 (0)