Skip to content

Commit

Permalink
Using a valid URI when deleting cookies before/after running tests
Browse files Browse the repository at this point in the history
Closes keycloak#22691

Signed-off-by: Pedro Igor <[email protected]>
  • Loading branch information
pedroigor committed Jan 5, 2024
1 parent c2112b9 commit d540584
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 68,6 @@
import org.keycloak.services.managers.AuthenticationManager;
import org.keycloak.services.resource.RealmResourceProvider;
import org.keycloak.services.scheduled.ClearExpiredUserSessions;
import org.keycloak.services.util.CacheControlUtil;
import org.keycloak.services.util.CookieHelper;
import org.keycloak.sessions.RootAuthenticationSessionModel;
import org.keycloak.storage.UserStorageProvider;
Expand Down Expand Up @@ -1177,4 1176,10 @@ public Response getNoCacheAnnotatedEndpointResponse(@QueryParam("programmatic_ma
return Response.noContent().cacheControl(cacheControl).build();
}

@GET
@Path("/blank")
@Produces(MediaType.TEXT_HTML_UTF_8)
public Response getBlankPage() {
return Response.ok("<html><body></body></html>").build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 32,10 @@
import org.jboss.arquillian.test.spi.annotation.ClassScoped;
import org.jboss.logging.Logger;
import org.keycloak.testsuite.util.WaitUtils;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.remote.RemoteWebDriver;

Expand Down Expand Up @@ -84,8 87,20 @@ private void configureDriverSettings(WebDriver driver) {
driver.manage().timeouts().implicitlyWait(implicitWaitMillis, TimeUnit.MILLISECONDS);
driver.manage().timeouts().pageLoadTimeout(pageLoadTimeoutMillis, TimeUnit.MILLISECONDS);
driver.manage().window().maximize();

configureFirefoxDriver(driver);
}

private void configureFirefoxDriver(WebDriver driver) {
if (driver instanceof FirefoxDriver) {
FirefoxDriver firefoxDriver = (FirefoxDriver) driver;
Capabilities capabilities = firefoxDriver.getCapabilities();
FirefoxOptions options = new FirefoxOptions(capabilities);
// disables extension automatic updates as we don't need it when running the test suite
options.addPreference("extensions.update.enabled", "false");
firefoxDriver.getCapabilities().merge(options);
}
}

public static class HtmlUnitInterceptor implements Interceptor {

Expand Down Expand Up @@ -133,6 148,6 @@ public Object intercept(InvocationContext context) throws Throwable {
public int getPrecedence() {
return -1;
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 283,7 @@ public void deleteAllCookiesForMasterRealm() {
}

protected void deleteAllCookiesForRealm(String realmName) {
// we can't use /auth/realms/{realmName} because some browsers (e.g. Chrome) apparently don't send cookies
// to JSON pages and therefore can't delete realms cookies there; a non existing page will do just fine
navigateToUri(oauth.SERVER_ROOT "/auth/realms/" realmName "/super-random-page");
navigateToUri(oauth.SERVER_ROOT "/auth/realms/" realmName "/testing/blank");
log.info("deleting cookies in '" realmName "' realm");
driver.manage().deleteAllCookies();
}
Expand Down

0 comments on commit d540584

Please sign in to comment.