Move deleteCookies to before for RecoveryAuthnCodesAuthenticatorTest

Closes #26176

Signed-off-by: rmartinc <rmartinc@redhat.com>
This commit is contained in:
rmartinc 2024-09-27 16:26:42 +02:00 committed by Marek Posolda
parent 068d383d44
commit aaf8136c89
3 changed files with 19 additions and 14 deletions

View file

@ -139,7 +139,9 @@ public final class WaitUtils {
wait.until(not(urlToBe(currentUrl))); wait.until(not(urlToBe(currentUrl)));
} }
catch (TimeoutException e) { catch (TimeoutException e) {
break; // URL has not changed recently - ok, the URL is stable and page is current if (driver.getPageSource() != null) {
break; // URL has not changed recently - ok, the URL is stable and page is current
}
} }
if (maxRedirects == 1) { if (maxRedirects == 1) {
log.warn("URL seems unstable! (Some redirect are probably still in progress)"); log.warn("URL seems unstable! (Some redirect are probably still in progress)");

View file

@ -17,10 +17,8 @@
package org.keycloak.testsuite; package org.keycloak.testsuite;
import org.junit.After; import org.junit.Before;
import org.keycloak.admin.client.resource.RealmResource; import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.common.ClientConnection;
import org.keycloak.common.util.Resteasy;
import org.keycloak.common.util.reflections.Reflections; import org.keycloak.common.util.reflections.Reflections;
import org.keycloak.events.Details; import org.keycloak.events.Details;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
@ -78,8 +76,13 @@ public abstract class AbstractTestRealmKeycloakTest extends AbstractKeycloakTest
} }
// Logout user after test @Before
@After @Override
public void beforeAbstractKeycloakTest() throws Exception {
deleteCookies();
super.beforeAbstractKeycloakTest();
}
public void deleteCookies() { public void deleteCookies() {
deleteAllCookiesForRealm("test"); deleteAllCookiesForRealm("test");
} }

View file

@ -113,9 +113,9 @@ public class BruteForceTest extends AbstractTestRealmKeycloakTest {
testRealm.setBruteForceProtected(true); testRealm.setBruteForceProtected(true);
testRealm.setFailureFactor(failureFactor); testRealm.setFailureFactor(failureFactor);
testRealm.setMaxDeltaTimeSeconds(20); testRealm.setMaxDeltaTimeSeconds(60);
testRealm.setMaxFailureWaitSeconds(100); testRealm.setMaxFailureWaitSeconds(100);
testRealm.setWaitIncrementSeconds(5); testRealm.setWaitIncrementSeconds(20);
testRealm.setOtpPolicyCodeReusable(true); testRealm.setOtpPolicyCodeReusable(true);
//testRealm.setQuickLoginCheckMilliSeconds(0L); //testRealm.setQuickLoginCheckMilliSeconds(0L);
@ -132,9 +132,9 @@ public class BruteForceTest extends AbstractTestRealmKeycloakTest {
clearAllUserFailures(); clearAllUserFailures();
RealmRepresentation realm = adminClient.realm("test").toRepresentation(); RealmRepresentation realm = adminClient.realm("test").toRepresentation();
realm.setFailureFactor(failureFactor); realm.setFailureFactor(failureFactor);
realm.setMaxDeltaTimeSeconds(20); realm.setMaxDeltaTimeSeconds(60);
realm.setMaxFailureWaitSeconds(100); realm.setMaxFailureWaitSeconds(100);
realm.setWaitIncrementSeconds(5); realm.setWaitIncrementSeconds(20);
realm.setOtpPolicyCodeReusable(true); realm.setOtpPolicyCodeReusable(true);
adminClient.realm("test").update(realm); adminClient.realm("test").update(realm);
} catch (Exception e) { } catch (Exception e) {
@ -492,7 +492,7 @@ public class BruteForceTest extends AbstractTestRealmKeycloakTest {
// KEYCLOAK-5420 // KEYCLOAK-5420
// Test to make sure that temporarily disabled doesn't increment failure count // Test to make sure that temporarily disabled doesn't increment failure count
testingClient.testing().setTimeOffset(Collections.singletonMap("offset", String.valueOf(6))); testingClient.testing().setTimeOffset(Collections.singletonMap("offset", String.valueOf(21)));
// should be unlocked now // should be unlocked now
loginSuccess(); loginSuccess();
clearUserFailures(); clearUserFailures();
@ -674,11 +674,11 @@ public class BruteForceTest extends AbstractTestRealmKeycloakTest {
loginInvalidPassword(); loginInvalidPassword();
loginInvalidPassword(); loginInvalidPassword();
expectTemporarilyDisabled(); expectTemporarilyDisabled();
testingClient.testing().setTimeOffset(Collections.singletonMap("offset", String.valueOf(6))); testingClient.testing().setTimeOffset(Collections.singletonMap("offset", String.valueOf(21)));
loginInvalidPassword(); loginInvalidPassword();
expectTemporarilyDisabled(); expectTemporarilyDisabled();
testingClient.testing().setTimeOffset(Collections.singletonMap("offset", String.valueOf(11))); testingClient.testing().setTimeOffset(Collections.singletonMap("offset", String.valueOf(42)));
loginInvalidPassword(); loginInvalidPassword();
expectPermanentlyDisabled(); expectPermanentlyDisabled();
@ -703,7 +703,7 @@ public class BruteForceTest extends AbstractTestRealmKeycloakTest {
loginInvalidPassword(); loginInvalidPassword();
loginInvalidPassword(); loginInvalidPassword();
expectTemporarilyDisabled(); expectTemporarilyDisabled();
testingClient.testing().setTimeOffset(Collections.singletonMap("offset", String.valueOf(6))); testingClient.testing().setTimeOffset(Collections.singletonMap("offset", String.valueOf(21)));
UserRepresentation user = adminClient.realm("test").users().search("test-user@localhost", 0, 1).get(0); UserRepresentation user = adminClient.realm("test").users().search("test-user@localhost", 0, 1).get(0);
Map<String, Object> status = adminClient.realm("test").attackDetection().bruteForceUserStatus(user.getId()); Map<String, Object> status = adminClient.realm("test").attackDetection().bruteForceUserStatus(user.getId());
assertEquals(1, status.get("numTemporaryLockouts")); assertEquals(1, status.get("numTemporaryLockouts"));