Search in sources :

Example 1 with JSObjectBuilder

use of org.keycloak.testsuite.util.javascript.JSObjectBuilder in project keycloak by keycloak.

the class JavascriptAdapterTest method equalsSignInRedirectUrl.

@Test
public void equalsSignInRedirectUrl() {
    testAppUrl = authServerContextRootPage.toString().replace(AUTH_SERVER_HOST, JS_APP_HOST) + JAVASCRIPT_URL + "/index.html?test=bla=bla&super=man";
    jsDriver.navigate().to(testAppUrl);
    JSObjectBuilder arguments = defaultArguments();
    testExecutor.init(arguments, this::assertInitNotAuth).login(this::assertOnLoginPage).loginForm(testUser, this::assertOnTestAppUrl).init(arguments, (driver1, output1, events2) -> {
        assertTrue(driver1.getCurrentUrl().contains("bla=bla"));
        assertInitAuth(driver1, output1, events2);
    });
}
Also used : JSObjectBuilder(org.keycloak.testsuite.util.javascript.JSObjectBuilder) Test(org.junit.Test)

Example 2 with JSObjectBuilder

use of org.keycloak.testsuite.util.javascript.JSObjectBuilder in project keycloak by keycloak.

the class JavascriptAdapterTest method testSilentCheckSsoNotAuthenticated.

@Test
public void testSilentCheckSsoNotAuthenticated() {
    JSObjectBuilder checkSSO = defaultArguments().checkSSOOnLoad().add("checkLoginIframe", false).add("silentCheckSsoRedirectUri", authServerContextRootPage.toString().replace(AUTH_SERVER_HOST, JS_APP_HOST) + JAVASCRIPT_URL + "/silent-check-sso.html");
    testExecutor.init(checkSSO, this::assertInitNotAuth, SuiteContext.BROWSER_STRICT_COOKIES);
}
Also used : JSObjectBuilder(org.keycloak.testsuite.util.javascript.JSObjectBuilder) Test(org.junit.Test)

Example 3 with JSObjectBuilder

use of org.keycloak.testsuite.util.javascript.JSObjectBuilder in project keycloak by keycloak.

the class JavascriptAdapterTest method testSilentCheckSsoWithFallbackDisabled.

@Test
public void testSilentCheckSsoWithFallbackDisabled() {
    JSObjectBuilder checkSSO = defaultArguments().checkSSOOnLoad().disableSilentCheckSSOFallback().add("silentCheckSsoRedirectUri", authServerContextRootPage.toString().replace(AUTH_SERVER_HOST, JS_APP_HOST) + JAVASCRIPT_URL + "/silent-check-sso.html");
    testExecutor.init(checkSSO, this::assertInitNotAuth).login(this::assertOnLoginPage).loginForm(testUser, this::assertOnTestAppUrl).init(checkSSO, this::assertInitAuth).refresh().init(checkSSO, // with the fall back disabled, the adapter won't do full redirect to KC
    SuiteContext.BROWSER_STRICT_COOKIES ? this::assertInitNotAuth : this::assertInitAuth);
}
Also used : JSObjectBuilder(org.keycloak.testsuite.util.javascript.JSObjectBuilder) Test(org.junit.Test)

Example 4 with JSObjectBuilder

use of org.keycloak.testsuite.util.javascript.JSObjectBuilder in project keycloak by keycloak.

the class JavascriptAdapterTest method testCheckSso.

@Test
public void testCheckSso() {
    JSObjectBuilder checkSSO = defaultArguments().checkSSOOnLoad();
    // when 3rd party cookies are disabled, the adapter has to do a full redirect to KC to check whether the user
    // is logged in or not – it can't rely on the login iframe
    testExecutor.init(checkSSO, this::assertInitNotAuth, SuiteContext.BROWSER_STRICT_COOKIES).login(this::assertOnLoginPage).loginForm(testUser, this::assertOnTestAppUrl).init(checkSSO, this::assertInitAuth, false).refresh().init(checkSSO, this::assertInitAuth, true);
}
Also used : JSObjectBuilder(org.keycloak.testsuite.util.javascript.JSObjectBuilder) Test(org.junit.Test)

Example 5 with JSObjectBuilder

use of org.keycloak.testsuite.util.javascript.JSObjectBuilder in project keycloak by keycloak.

the class JavascriptAdapterTest method testScopeInLoginOptionsShouldBeConsideredByLoginUrl.

/**
 * Test for scope handling via {@code loginOptions}: <pre>{@code
 * Keycloak keycloak = new Keycloak(); keycloak.login({.... scope: "profile email phone"})
 * }</pre>
 * See KEYCLOAK-14412
 */
@Test
public void testScopeInLoginOptionsShouldBeConsideredByLoginUrl() {
    testExecutor.configure().init(defaultArguments());
    JSObjectBuilder loginOptions = JSObjectBuilder.create().add("scope", "profile email phone");
    testExecutor.login(loginOptions, (JavascriptStateValidator) (driver, output, events) -> {
        assertThat(driver.getCurrentUrl(), containsString("&scope=openid%20profile%20email%20phone"));
    });
}
Also used : JavascriptBrowser(org.keycloak.testsuite.util.JavascriptBrowser) URL(java.net.URL) JavascriptStateValidator(org.keycloak.testsuite.util.javascript.JavascriptStateValidator) AssertEvents(org.keycloak.testsuite.AssertEvents) WebElement(org.openqa.selenium.WebElement) Page(org.jboss.arquillian.graphene.page.Page) OAuthClient(org.keycloak.testsuite.util.OAuthClient) Assert.assertThat(org.junit.Assert.assertThat) Map(java.util.Map) ClientResource(org.keycloak.admin.client.resource.ClientResource) IsMapContaining.hasEntry(org.hamcrest.collection.IsMapContaining.hasEntry) UriUtils(org.keycloak.common.util.UriUtils) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DisableFeature(org.keycloak.testsuite.arquillian.annotation.DisableFeature) AUTH_SERVER_HOST(org.keycloak.testsuite.util.ServerURLs.AUTH_SERVER_HOST) UpdatePassword(org.keycloak.testsuite.auth.page.login.UpdatePassword) IDToken(org.keycloak.representations.IDToken) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) EventRepresentation(org.keycloak.representations.idm.EventRepresentation) XMLHttpRequest(org.keycloak.testsuite.util.javascript.XMLHttpRequest) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) List(java.util.List) URLAssert.assertCurrentUrlStartsWith(org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWith) TimeoutException(org.openqa.selenium.TimeoutException) Details(org.keycloak.events.Details) OIDCLoginProtocol(org.keycloak.protocol.oidc.OIDCLoginProtocol) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) OAuth2Constants(org.keycloak.OAuth2Constants) WaitUtils.waitUntilElement(org.keycloak.testsuite.util.WaitUtils.waitUntilElement) CoreMatchers.anyOf(org.hamcrest.CoreMatchers.anyOf) Profile(org.keycloak.common.Profile) Assert(org.keycloak.testsuite.Assert) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) WebDriver(org.openqa.selenium.WebDriver) WebDriverException(org.openqa.selenium.WebDriverException) JavascriptTestExecutor(org.keycloak.testsuite.util.javascript.JavascriptTestExecutor) OAuthGrant(org.keycloak.testsuite.auth.page.login.OAuthGrant) RealmBuilder(org.keycloak.testsuite.util.RealmBuilder) UserBuilder(org.keycloak.testsuite.util.UserBuilder) CoreMatchers.both(org.hamcrest.CoreMatchers.both) Matchers.lessThan(org.hamcrest.Matchers.lessThan) URLAssert.assertCurrentUrlDoesntStartWith(org.keycloak.testsuite.util.URLAssert.assertCurrentUrlDoesntStartWith) Assume(org.junit.Assume) Math.toIntExact(java.lang.Math.toIntExact) AuthServer(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude.AuthServer) Retry(org.keycloak.common.util.Retry) Before(org.junit.Before) ClaimsRepresentation(org.keycloak.representations.ClaimsRepresentation) ApiUtil(org.keycloak.testsuite.admin.ApiUtil) SuiteContext(org.keycloak.testsuite.arquillian.SuiteContext) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) EventType(org.keycloak.events.EventType) IOException(java.io.IOException) WaitUtils.waitForPageToLoad(org.keycloak.testsuite.util.WaitUtils.waitForPageToLoad) JsonSerialization(org.keycloak.util.JsonSerialization) Rule(org.junit.Rule) JSObjectBuilder(org.keycloak.testsuite.util.javascript.JSObjectBuilder) Applications(org.keycloak.testsuite.auth.page.account.Applications) Assert.assertEquals(org.junit.Assert.assertEquals) JSObjectBuilder(org.keycloak.testsuite.util.javascript.JSObjectBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 JSObjectBuilder (org.keycloak.testsuite.util.javascript.JSObjectBuilder)14 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 IOException (java.io.IOException)2 Math.toIntExact (java.lang.Math.toIntExact)2 URL (java.net.URL)2 List (java.util.List)2 Map (java.util.Map)2 CoreMatchers.anyOf (org.hamcrest.CoreMatchers.anyOf)2 CoreMatchers.both (org.hamcrest.CoreMatchers.both)2 Matchers.greaterThan (org.hamcrest.Matchers.greaterThan)2 Matchers.is (org.hamcrest.Matchers.is)2 Matchers.lessThan (org.hamcrest.Matchers.lessThan)2 IsMapContaining.hasEntry (org.hamcrest.collection.IsMapContaining.hasEntry)2 Page (org.jboss.arquillian.graphene.page.Page)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertThat (org.junit.Assert.assertThat)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Assume (org.junit.Assume)2 Before (org.junit.Before)2