Search in sources :

Example 6 with JSObjectBuilder

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

the class JavascriptAdapterTest method testIframeInit.

@Test
public // KEYCLOAK-13206
void testIframeInit() {
    // to speed up the test a bit
    JSObjectBuilder iframeInterval = defaultArguments().setCheckLoginIframeIntervalTo1();
    testExecutor.init(iframeInterval).login().loginForm(testUser).init(iframeInterval).wait(2000, (driver1, output, events) -> {
        // iframe is initialized after ~1 second, 2 seconds is just to be sure
        assertAdapterIsLoggedIn(driver1, output, events);
        final String logMsg = "3rd party cookies aren't supported by this browser.";
        if (SuiteContext.BROWSER_STRICT_COOKIES) {
            // this is here not really to test the log but also to make sure the browser is configured properly
            // and cookies were blocked
            assertEventsWebElementContains(logMsg, driver1, output, events);
        } else {
            assertEventsWebElementDoesntContain(logMsg, driver1, output, events);
        }
    });
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) JSObjectBuilder(org.keycloak.testsuite.util.javascript.JSObjectBuilder) Test(org.junit.Test)

Example 7 with JSObjectBuilder

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

the class JavascriptAdapterTest method checkInitWithUnavailableAuthServer.

// In case of unavailable Authorization Server due to network or other kind of problems,
// JavaScript Adapter init() should fail-fast and reject Promise with KeycloakError.
@Test
public void checkInitWithUnavailableAuthServer() {
    JSObjectBuilder keycloakConfig = JSObjectBuilder.create().add("url", "https://localhost:12345/auth").add("realm", REALM_NAME).add("clientId", CLIENT_ID);
    JSObjectBuilder initOptions = defaultArguments().add("messageReceiveTimeout", 5000);
    testExecutor.configure(keycloakConfig).init(initOptions, assertErrorResponse("Timeout when waiting for 3rd party check iframe message."));
}
Also used : JSObjectBuilder(org.keycloak.testsuite.util.javascript.JSObjectBuilder) Test(org.junit.Test)

Example 8 with JSObjectBuilder

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

the class JavascriptAdapterTest method testLoginWithPkceS256.

@Test
public void testLoginWithPkceS256() {
    JSObjectBuilder pkceS256 = defaultArguments().pkceS256();
    testExecutor.init(pkceS256, this::assertInitNotAuth).login(this::assertOnLoginPage).loginForm(testUser, this::assertOnTestAppUrl).init(pkceS256, this::assertInitAuth).logout(this::assertOnTestAppUrl).init(pkceS256, this::assertInitNotAuth);
}
Also used : JSObjectBuilder(org.keycloak.testsuite.util.javascript.JSObjectBuilder) Test(org.junit.Test)

Example 9 with JSObjectBuilder

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

the class JavascriptAdapterTest method testSilentCheckSso.

@Test
public void testSilentCheckSso() {
    JSObjectBuilder checkSSO = defaultArguments().checkSSOOnLoad().add("silentCheckSsoRedirectUri", authServerContextRootPage.toString().replace(AUTH_SERVER_HOST, JS_APP_HOST) + JAVASCRIPT_URL + "/silent-check-sso.html");
    // 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 silent check-sso 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, SuiteContext.BROWSER_STRICT_COOKIES);
}
Also used : JSObjectBuilder(org.keycloak.testsuite.util.javascript.JSObjectBuilder) Test(org.junit.Test)

Example 10 with JSObjectBuilder

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

the class JavascriptAdapterTest method spaceInRealmNameTest.

@Test
public void spaceInRealmNameTest() {
    // Unfortunately this test doesn't work on phantomjs
    // it looks like phantomjs double encode %20 => %25%20
    Assume.assumeTrue("This test doesn't work with phantomjs", !"phantomjs".equals(System.getProperty("js.browser")));
    try {
        adminClient.realm(REALM_NAME).update(RealmBuilder.edit(adminClient.realm(REALM_NAME).toRepresentation()).name(SPACE_REALM_NAME).build());
        JSObjectBuilder configuration = JSObjectBuilder.create().add("url", authServerContextRootPage + "/auth").add("realm", SPACE_REALM_NAME).add("clientId", CLIENT_ID);
        testAppUrl = authServerContextRootPage + JAVASCRIPT_ENCODED_SPACE_URL + "/index.html";
        jsDriver.navigate().to(testAppUrl);
        jsDriverTestRealmLoginPage.setAuthRealm(SPACE_REALM_NAME);
        testExecutor.configure(configuration).init(defaultArguments(), this::assertInitNotAuth).login(this::assertOnLoginPage).loginForm(testUser, this::assertOnTestAppUrl).configure(configuration).init(defaultArguments(), this::assertInitAuth);
    } finally {
        adminClient.realm(SPACE_REALM_NAME).update(RealmBuilder.edit(adminClient.realm(SPACE_REALM_NAME).toRepresentation()).name(REALM_NAME).build());
        jsDriverTestRealmLoginPage.setAuthRealm(REALM_NAME);
    }
}
Also used : 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