3333import org .labkey .test .pages .core .login .DatabaseAuthConfigureDialog ;
3434import org .labkey .test .pages .core .login .LoginConfigurePage ;
3535import org .labkey .test .params .login .DatabaseAuthenticationProvider ;
36+ import org .labkey .test .util .APIUserHelper ;
3637import org .labkey .test .util .LogMethod ;
3738import org .labkey .test .util .LoggedParam ;
3839import org .labkey .test .util .core .login .DbLoginUtils ;
@@ -256,7 +257,11 @@ public void testPasswordParameter()
256257 @ Test
257258 public void testChooseNewPasswordMessages () throws IOException
258259 {
259- // Hold an admin connection open, allowing us to reset the config regardless of what happens during the test
260+ // Test bad API key
261+ signOut ();
262+ signInShouldFailUiAndApi ("apikey" , "abc123" , "The API key you provided is invalid." );
263+
264+ // Hold an admin API connection open, allowing us to reset the config without the browser session interfering
260265 Connection adminConnection = WebTestHelper .getRemoteApiConnection ();
261266 DbLoginProperties savedProperties = DbLoginUtils .getDbLoginConfig (adminConnection );
262267
@@ -268,25 +273,28 @@ public void testChooseNewPasswordMessages() throws IOException
268273 );
269274
270275 // Set a weak password
271- signOut ();
272276 String resetUrl = userInitiatePasswordReset (USER );
273277 beginAt (resetUrl );
274278 new SetPasswordForm (getDriver ())
275279 .setNewPassword (WEAK_PASSWORD )
276280 .clickSubmit ();
277281
278- // Test bogus password first
279- signOut ();
280- signInShouldFail ("bogus" , "The email address and password you entered did not match any accounts on file." );
281- signIn (USER , WEAK_PASSWORD );
282+ // Test bogus password
282283 signOut ();
284+ signInShouldFailUiAndApi (USER , "bogus" , "The email address and password you entered did not match any accounts on file." );
285+
286+ // Test deactivated user
287+ APIUserHelper helper = new APIUserHelper (() -> adminConnection );
288+ helper .deactivateUsers (_userId );
289+ signInShouldFailUiAndApi (USER , WEAK_PASSWORD , "Your account has been deactivated." );
290+ helper .activateUsers (_userId );
283291
284292 // Change the configuration and test password that no longer meets complexity requirements
285293 DbLoginUtils .setDbLoginConfig (adminConnection ,
286294 PasswordStrength .Strong ,
287295 PasswordExpiration .Never
288296 );
289- signInShouldFail ( WEAK_PASSWORD , "Your password does not meet the complexity requirements; please choose a new password." );
297+ signInShouldFailUiAndApi ( USER , WEAK_PASSWORD , "Your password does not meet the complexity requirements; please choose a new password." );
290298 String strongPassword = VERY_STRONG_PASSWORD + "!" ;
291299 changeInvalidPassword (WEAK_PASSWORD , strongPassword );
292300
@@ -297,7 +305,7 @@ public void testChooseNewPasswordMessages() throws IOException
297305 );
298306 // Wait six seconds for expiration
299307 sleep (6000 );
300- signInShouldFail ( strongPassword , "Your password has expired; please choose a new password." );
308+ signInShouldFailUiAndApi ( USER , strongPassword , "Your password has expired; please choose a new password." );
301309 changeInvalidPassword (strongPassword , VERY_STRONG_PASSWORD + "@" );
302310 }
303311 finally
@@ -307,10 +315,10 @@ public void testChooseNewPasswordMessages() throws IOException
307315 }
308316
309317 // Attempt to sign in via UI and API, expecting both to fail with the specified message
310- private void signInShouldFail ( String password , String expectedMessage ) throws IOException
318+ private void signInShouldFailUiAndApi ( String email , String password , String expectedMessage ) throws IOException
311319 {
312- signInShouldFail (USER , password , expectedMessage );
313- Connection userConnection = new Connection (WebTestHelper .getBaseURL (), USER , password );
320+ signInShouldFail (email , password , expectedMessage );
321+ Connection userConnection = new Connection (WebTestHelper .getBaseURL (), email , password );
314322 EnsureLoginCommand ensureLoginCommand = new EnsureLoginCommand ();
315323 try
316324 {
0 commit comments