Skip to content

Commit 412e41e

Browse files
check in test cases planned so far
1 parent 5cf731b commit 412e41e

3 files changed

Lines changed: 138 additions & 0 deletions

File tree

src/wh_auth_base.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,18 @@ int wh_AuthBase_Init(void* context, const void *config)
5353
whAuthPermissions permissions;
5454
int rc;
5555
uint16_t out_user_id;
56+
int i;
5657

5758
/* TODO: Initialize auth manager context */
5859
(void)context;
5960
(void)config;
6061

6162
memset(&permissions, 0xFF, sizeof(whAuthPermissions));
63+
permissions.keyIdCount = 0;
64+
for (i = 0; i < WH_AUTH_MAX_KEY_IDS; i++) {
65+
permissions.keyIds[i] = 0;
66+
}
67+
6268
/* add a demo user with admin permissions */
6369
rc = wh_AuthBase_UserAdd(context, "admin", &out_user_id, permissions,
6470
WH_AUTH_METHOD_PIN, "1234", 4);

test/wh_test_auth.c

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (C) 2025 wolfSSL Inc.
3+
*
4+
* This file is part of wolfHSM.
5+
*
6+
* wolfHSM is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* wolfHSM is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with wolfHSM. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
/*
20+
* test/wh_test_auth.c
21+
*/
22+
23+
#include <stdint.h>
24+
#include <stdio.h>
25+
#include <string.h>
26+
27+
#include "wolfhsm/wh_settings.h"
28+
#include "wolfhsm/wh_error.h"
29+
#include "wolfhsm/wh_comm.h"
30+
#include "wolfhsm/wh_transport_mem.h"
31+
#include "wolfhsm/wh_client.h"
32+
#include "wolfhsm/wh_server.h"
33+
#include "wolfhsm/wh_auth.h"
34+
#include "wolfhsm/wh_auth_base.h"
35+
#include "wolfhsm/wh_nvm.h"
36+
#include "wolfhsm/wh_nvm_flash.h"
37+
#include "wolfhsm/wh_flash_ramsim.h"
38+
39+
#include "wh_test_common.h"
40+
#include "wh_test_auth.h"
41+
42+
43+
/* test cases */
44+
45+
/* Logout tests */
46+
/* test logout before login */
47+
/* test logout after login */
48+
/* test logout with invalid user id */
49+
50+
/* Login tests */
51+
/* test login with invalid credentials */
52+
/* test login with valid credentials */
53+
/* test login with invalid user name */
54+
/* test login if already logged in */
55+
56+
/* Add user tests */
57+
/* test add user with invalid user name (too long?) */
58+
/* test add user with invalid permissions */
59+
/* test add user if already exists */
60+
61+
/* Delete user tests */
62+
/* test delete user with invalid user id */
63+
/* test delete user that does not exist */
64+
/* test delete user when not logged in */
65+
66+
/* Set user permissions tests */
67+
/* test set user permissions with invalid user id */
68+
/* test set user permissions with invalid permissions */
69+
/* test set user permissions that does not exist */
70+
/* test set user permissions when not logged in */
71+
72+
/* Set user credentials tests */
73+
/* test set user credentials with invalid user id */
74+
/* test set user credentials with invalid credentials (wrong method) */
75+
/* test set user credentials for a userthat does not exist */
76+
/* test an admin user setting credentials for non admin user */
77+
78+
/* Tests for authorization checks */
79+
/* try operation when not logged in and not allowed */
80+
/* re-try operation when logged in and allowed */
81+
/* try operation when logged in and not allowed */
82+
/* try operation when logged in as different user and allowed */
83+
/* try operation when logged in as different user and not allowed */
84+
85+
/* Tests for key authorization checks */
86+
/* test of access to key ID that is not allowed */
87+
/* test of access to key ID that is allowed */
88+
/* test of access to key ID that is allowed for different user */

test/wh_test_auth.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (C) 2025 wolfSSL Inc.
3+
*
4+
* This file is part of wolfHSM.
5+
*
6+
* wolfHSM is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* wolfHSM is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with wolfHSM. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
/*
20+
* test/wh_test_auth.h
21+
*/
22+
23+
#ifndef WOLFHSM_WH_TEST_AUTH_H_
24+
#define WOLFHSM_WH_TEST_AUTH_H_
25+
26+
#include "wolfhsm/wh_server.h"
27+
#include "wolfhsm/wh_client.h"
28+
29+
#include "wolfhsm/wh_auth.h"
30+
#include "wh_test_common.h"
31+
32+
33+
/* Self-contained test that creates client and server with auth */
34+
int whTest_Auth(void);
35+
36+
/* Individual test functions that require a connected client */
37+
int whTest_AuthLogin(whClientContext* client);
38+
int whTest_AuthLogout(whClientContext* client);
39+
int whTest_AuthAddUser(whClientContext* client);
40+
int whTest_AuthDeleteUser(whClientContext* client);
41+
int whTest_AuthSetPermissions(whClientContext* client);
42+
int whTest_AuthSetCredentials(whClientContext* client);
43+
44+
#endif /* WOLFHSM_WH_TEST_AUTH_H_ */

0 commit comments

Comments
 (0)