@@ -45,8 +45,8 @@ void test_read_secret_ok()
4545{
4646 test_start ();
4747 char * pwd = readSecret ("./src/mqAdminPassword" );
48- char * password = "fred:$2y$05$3Fp9 " ;
49- if (0 == strncmp (pwd , password , strlen ( password ) ))
48+ char * password = "passw0rd " ;
49+ if (0 == strcmp (pwd , password ))
5050 test_pass ();
5151 else
5252 test_fail (__func__ );
@@ -120,6 +120,49 @@ void test_simpleauth_authenticate_user_admin_ok()
120120 test_pass ();
121121}
122122
123+ void test_simpleauth_authenticate_user_app_invalidpwd ()
124+ {
125+ test_start ();
126+ char * password [] = {"passw0r" , "pass" , "passw0rd1" , "NULL" , "" ,"password123" };
127+ setenv ("MQ_APP_PASSWORD" , "passw0rd" , 1 );
128+
129+ for (int i = 0 ; i < (sizeof (password )/sizeof (password [0 ])); ++ i )
130+ {
131+ int rc = simpleauth_authenticate_user ("app" , password [i ]);
132+ printf ("%s: Validating app user with password set to %s and rc is %d\n" , __func__ ,password [i ], rc );
133+ if (rc != SIMPLEAUTH_INVALID_PASSWORD )
134+ test_fail (__func__ );
135+ }
136+ test_pass ();
137+ }
138+
139+ void test_simpleauth_authenticate_user_admin_invalidpwd ()
140+ {
141+ test_start ();
142+ char * password [] = {"passw0r" , "pass" , "passw0rd1" , "NULL" , "" ,"password123" };
143+ setenv ("MQ_ADMIN_PASSWORD" , "passw0rd" , 1 );
144+
145+ for (int i = 0 ; i < (sizeof (password )/sizeof (password [0 ])); ++ i )
146+ {
147+ int rc = simpleauth_authenticate_user ("admin" , password [i ]);
148+ printf ("%s: validating admin user with password set to %s and rc is %d\n" , __func__ ,password [i ], rc );
149+ if (rc != SIMPLEAUTH_INVALID_PASSWORD )
150+ test_fail (__func__ );
151+ }
152+ test_pass ();
153+ }
154+
155+ void test_simpleauth_authenticate_user_admin_with_null_pwd ()
156+ {
157+ test_start ();
158+ setenv ("MQ_ADMIN_PASSWORD" , "" , 1 );
159+ int rc = simpleauth_authenticate_user ("admin" , "passw0rd" );
160+ printf ("%s: admin - %d\n" , __func__ , rc );
161+ if (rc == SIMPLEAUTH_VALID )
162+ test_fail (__func__ );
163+ test_pass ();
164+ }
165+
123166void test_simpleauth_authenticate_user_admin_invalidpassword ()
124167{
125168 test_start ();
@@ -131,6 +174,17 @@ void test_simpleauth_authenticate_user_admin_invalidpassword()
131174 test_pass ();
132175}
133176
177+ void test_simpleauth_authenticate_user_admin_invalishortdpassword ()
178+ {
179+ test_start ();
180+ setenv ("MQ_ADMIN_PASSWORD" , "password" , 1 );
181+ int rc = simpleauth_authenticate_user ("admin" , "pass" );
182+ printf ("%s: admin - %d\n" , __func__ , rc );
183+ if (rc != SIMPLEAUTH_INVALID_PASSWORD )
184+ test_fail (__func__ );
185+ test_pass ();
186+ }
187+
134188
135189// ----------------------------------------------------------------------------
136190// Multi-threaded test
@@ -220,15 +274,18 @@ int main()
220274 // Turn on debugging for the tests
221275 setenv ("DEBUG" , "true" , true);
222276 log_init ("simpleauth_test.log" );
223-
224277 test_read_secret_ok ();
278+ test_simpleauth_authenticate_user_admin_invalidpwd ();
279+ test_simpleauth_authenticate_user_app_invalidpwd ();
225280 test_simpleauth_valid_user_app_valid ();
226281 test_simpleauth_valid_user_admin_valid ();
227282 test_simpleauth_valid_user_george_invalid ();
228283 test_simpleauth_authenticate_user_fred_unknown ();
229284 test_simpleauth_authenticate_user_app_ok ();
285+ test_simpleauth_authenticate_user_admin_with_null_pwd ();
230286 test_simpleauth_authenticate_user_admin_ok ();
231287 test_simpleauth_authenticate_user_admin_invalidpassword ();
288+ test_simpleauth_authenticate_user_admin_invalishortdpassword ();
232289
233290 log_close ();
234291
0 commit comments