use of org.keycloak.testsuite.util.javascript.XMLHttpRequest in project keycloak by keycloak.
the class JavascriptAdapterTest method testUpdateToken.
@Test
public void testUpdateToken() {
XMLHttpRequest request = XMLHttpRequest.create().url(authServerContextRootPage + "/auth/admin/realms/" + REALM_NAME + "/roles").method("GET").addHeader("Accept", "application/json").addHeader("Authorization", "Bearer ' + keycloak.token + '");
testExecutor.logInAndInit(defaultArguments(), testUser, this::assertInitAuth).addTimeSkew(-33);
setTimeOffset(33);
testExecutor.refreshToken(5, assertEventsContains("Auth Refresh Success"));
setTimeOffset(67);
testExecutor.addTimeSkew(-34).sendXMLHttpRequest(request, response -> assertThat(response, hasEntry(is("status"), anyOf(is(0L), is(401L))))).refreshToken(5, assertEventsContains("Auth Refresh Success")).sendXMLHttpRequest(request, assertResponseStatus(200));
}
use of org.keycloak.testsuite.util.javascript.XMLHttpRequest in project keycloak by keycloak.
the class JavascriptAdapterTest method testBearerRequest.
@Test
public void testBearerRequest() {
XMLHttpRequest request = XMLHttpRequest.create().url(authServerContextRootPage + "/auth/admin/realms/" + REALM_NAME + "/roles").method("GET").addHeader("Accept", "application/json").addHeader("Authorization", "Bearer ' + keycloak.token + '");
testExecutor.init(defaultArguments()).sendXMLHttpRequest(request, response -> assertThat(response, hasEntry(is("status"), anyOf(is(0L), is(401L))))).refresh();
if (!"phantomjs".equals(System.getProperty("js.browser"))) {
// I have no idea why, but this request doesn't work with phantomjs, it works in chrome
testExecutor.logInAndInit(defaultArguments(), unauthorizedUser, this::assertInitAuth).sendXMLHttpRequest(request, output -> Assert.assertThat(output, hasEntry("status", 403L))).logout(this::assertOnTestAppUrl).refresh();
}
testExecutor.logInAndInit(defaultArguments(), testUser, this::assertInitAuth).sendXMLHttpRequest(request, assertResponseStatus(200));
}
use of org.keycloak.testsuite.util.javascript.XMLHttpRequest in project keycloak by keycloak.
the class JavascriptAdapterTest method testLocationHeaderInResponse.
@Test
public void testLocationHeaderInResponse() {
XMLHttpRequest request = XMLHttpRequest.create().url(authServerContextRootPage + "/auth/admin/realms/" + REALM_NAME + "/users").method("POST").content("JSON.stringify(JSON.parse('{\"emailVerified\" : false, \"enabled\" : true, \"username\": \"mhajas\", \"firstName\" :\"First\", \"lastName\":\"Last\",\"email\":\"email@redhat.com\", \"attributes\": {}}'))").addHeader("Accept", "application/json").addHeader("Authorization", "Bearer ' + keycloak.token + '").addHeader("Content-Type", "application/json; charset=UTF-8");
testExecutor.logInAndInit(defaultArguments(), testUser, this::assertInitAuth).sendXMLHttpRequest(request, response -> {
List<UserRepresentation> users = adminClient.realm(REALM_NAME).users().search("mhajas", 0, 1);
assertEquals("There should be created user mhajas", 1, users.size());
assertThat(((String) response.get("responseHeaders")).toLowerCase(), containsString("location: " + authServerContextRootPage.toString() + "/auth/admin/realms/" + REALM_NAME + "/users/" + users.get(0).getId()));
});
}
Aggregations