Search in sources :

Example 96 with Response

use of io.restassured.response.Response in project SSM by Intel-bigdata.

the class CmdletRestApi method getCmdletInfo.

public static JsonPath getCmdletInfo(long cmdletId) {
    Response cmdletInfo = RestAssured.get(CMDLETROOT + "/" + cmdletId + "/info");
    cmdletInfo.then().body("status", Matchers.equalTo("OK"));
    JsonPath path = cmdletInfo.jsonPath().setRoot("body");
    return path;
}
Also used : Response(io.restassured.response.Response) JsonPath(io.restassured.path.json.JsonPath)

Example 97 with Response

use of io.restassured.response.Response in project SSM by Intel-bigdata.

the class TestSystemRestApi method testVersion.

@Test
public void testVersion() throws Exception {
    Response response1 = RestAssured.get(RestApiBase.SYSTEMROOT + "/version");
    String json1 = response1.asString();
    response1.then().body("body", Matchers.equalTo("1.6.0-SNAPSHOT"));
}
Also used : Response(io.restassured.response.Response) Test(org.junit.Test)

Example 98 with Response

use of io.restassured.response.Response in project SSM by Intel-bigdata.

the class TestClusterRestApi method testPrimary.

@Test
public void testPrimary() {
    Response response = RestAssured.get(RestApiBase.PRIMCLUSTERROOT);
    String json = response.asString();
    response.then().body("message", Matchers.equalTo("Namenode URL"));
    response.then().body("body", Matchers.containsString("localhost"));
}
Also used : Response(io.restassured.response.Response) Test(org.junit.Test)

Example 99 with Response

use of io.restassured.response.Response in project ddf by codice.

the class TestOidc method testLogout.

// --------------------------Logout Tests--------------------------//
@Test
public void testLogout() throws Exception {
    String jsessionidValue = login();
    // Send initial request to get OIDC logout url
    Response initialLogoutResponse = given().cookie(JSESSIONID, jsessionidValue).header(USER_AGENT, BROWSER_USER_AGENT).header("Referer", ROOT_URL + "?client_name=" + DDF_CLIENT_ID).header(HOST, "localhost:" + HTTPS_PORT.getPort()).header("X-Requested-With", "XMLHttpRequest").redirects().follow(false).expect().statusCode(200).when().get(LOGOUT_REQUEST_URL.getUrl());
    // Get and verify the logout url from body
    String body = initialLogoutResponse.getBody().prettyPrint();
    Map<String, String> oidcLogoutProperties = GSON.fromJson(body, Map.class);
    assertThat(oidcLogoutProperties.get("auth"), is(ADMIN));
    URI logoutUri = new URI(oidcLogoutProperties.get("url"));
    assertThat(logoutUri.getPath(), is("/auth/admin/master/protocol/openid-connect/logout"));
    Map<String, String> requestParams = URLEncodedUtils.parse(logoutUri, StandardCharsets.UTF_8).stream().collect(Collectors.toMap(NameValuePair::getName, NameValuePair::getValue));
    assertTrue(requestParams.containsKey("id_token_hint"));
    assertTrue(requestParams.containsKey("post_logout_redirect_uri"));
    assertThat(requestParams.get("post_logout_redirect_uri"), is(LOGOUT_URL.getUrl()));
    // send response keycloak would have sent after logging out user
    Response logoutResponse = given().cookie(JSESSIONID, jsessionidValue).header(USER_AGENT, BROWSER_USER_AGENT).header(HOST, "localhost:" + HTTPS_PORT.getPort()).redirects().follow(false).expect().statusCode(303).when().get(requestParams.get("post_logout_redirect_uri"));
    String location = logoutResponse.header(LOCATION);
    assertThat(location, is(SECURE_ROOT + HTTPS_PORT.getPort() + "/logout/logout-response.html"));
    // Verify that we're not logged in
    Map<String, Object> userInfoList = getUserInfo(jsessionidValue);
    assertThat(userInfoList.get("isGuest"), is(true));
}
Also used : Response(io.restassured.response.Response) JSONObject(org.json.simple.JSONObject) URI(java.net.URI) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) Test(org.junit.Test)

Example 100 with Response

use of io.restassured.response.Response in project ddf by codice.

the class TestOidc method processCredentialFlow.

/**
 * Processes a credential flow request/response
 *
 * <ul>
 *   <li>Sets up a userinfo endpoint that responds with the given {@param userInfoResponse} when
 *       given {@param accessToken}
 *   <li>Sends a request to Intrigue with the {@param accessToken} as a parameter
 *   <li>Asserts that the response is teh expected response
 *   <li>Verifies if the userinfo endpoint is hit or not
 * </ul>
 *
 * @return the response for additional verification
 */
private Response processCredentialFlow(String accessToken, String userInfoResponse, boolean isSigned, int expectedStatusCode, boolean userInfoShouldBeHit) {
    // Host the user info endpoint with the access token in the auth header
    String basicAuthHeader = "Bearer " + accessToken;
    String contentType = isSigned ? "application/jwt" : APPLICATION_JSON;
    whenHttp(server).match(get(USER_INFO_ENDPOINT_PATH), withHeader(AUTHORIZATION, basicAuthHeader)).then(ok(), contentType(contentType), bytesContent(userInfoResponse.getBytes()));
    // Send a request to DDF with the access token
    Response response = given().redirects().follow(false).expect().statusCode(expectedStatusCode).when().get(ROOT_URL.getUrl() + "?access_token=" + accessToken);
    List<Call> endpointCalls = server.getCalls().stream().filter(call -> call.getMethod().getMethodString().equals(GET)).filter(call -> call.getUrl().equals(URL_START + USER_INFO_ENDPOINT_PATH)).collect(Collectors.toList());
    if (userInfoShouldBeHit) {
        assertThat(endpointCalls.size(), is(greaterThanOrEqualTo(1)));
    } else {
        assertThat(endpointCalls.size(), is(0));
    }
    return response;
}
Also used : Response(io.restassured.response.Response) KeyPair(java.security.KeyPair) Arrays(java.util.Arrays) StubServer(com.xebialabs.restito.server.StubServer) GET(javax.ws.rs.HttpMethod.GET) Enumeration(java.util.Enumeration) Date(java.util.Date) PREFERRED_USERNAME(org.pac4j.oidc.profile.OidcProfileDefinition.PREFERRED_USERNAME) HttpStatus(org.apache.http.HttpStatus) GsonBuilder(com.google.gson.GsonBuilder) Algorithm(com.auth0.jwt.algorithms.Algorithm) NONCE(org.pac4j.oidc.profile.OidcProfileDefinition.NONCE) RSAPublicKey(java.security.interfaces.RSAPublicKey) Gson(com.google.gson.Gson) Duration(java.time.Duration) Map(java.util.Map) Base64URL(com.nimbusds.jose.util.Base64URL) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) URI(java.net.URI) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) KeyPairGenerator(java.security.KeyPairGenerator) Awaitility.await(org.awaitility.Awaitility.await) ImmutableMap(com.google.common.collect.ImmutableMap) JWTCreator(com.auth0.jwt.JWTCreator) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) Condition.parameter(com.xebialabs.restito.semantics.Condition.parameter) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) JWK(com.nimbusds.jose.jwk.JWK) StandardCharsets(java.nio.charset.StandardCharsets) HOST(javax.ws.rs.core.HttpHeaders.HOST) PerSuite(org.ops4j.pax.exam.spi.reactors.PerSuite) List(java.util.List) JSONObject(org.json.simple.JSONObject) Action.bytesContent(com.xebialabs.restito.semantics.Action.bytesContent) KeyUse(com.nimbusds.jose.jwk.KeyUse) URLEncodedUtils(org.apache.http.client.utils.URLEncodedUtils) SECURE_ROOT(org.codice.ddf.itests.common.AbstractIntegrationTest.DynamicUrl.SECURE_ROOT) Action.ok(com.xebialabs.restito.semantics.Action.ok) RestAssured.given(io.restassured.RestAssured.given) Matchers.is(org.hamcrest.Matchers.is) Condition.withHeader(com.xebialabs.restito.semantics.Condition.withHeader) AfterExam(org.codice.ddf.test.common.annotations.AfterExam) NameValuePair(org.apache.http.NameValuePair) Dictionary(java.util.Dictionary) StubHttp.whenHttp(com.xebialabs.restito.builder.stub.StubHttp.whenHttp) PaxExam(org.ops4j.pax.exam.junit.PaxExam) JWT(com.auth0.jwt.JWT) Call(com.xebialabs.restito.semantics.Call) MessageDigest(java.security.MessageDigest) RunWith(org.junit.runner.RunWith) BeforeExam(org.codice.ddf.test.common.annotations.BeforeExam) AZP(org.pac4j.oidc.profile.OidcProfileDefinition.AZP) REFRESH_TOKEN(org.pac4j.oidc.profile.OidcProfileDefinition.REFRESH_TOKEN) LOCATION(javax.ws.rs.core.HttpHeaders.LOCATION) Condition.post(com.xebialabs.restito.semantics.Condition.post) ImmutableList(com.google.common.collect.ImmutableList) Configuration(org.osgi.service.cm.Configuration) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Condition.get(com.xebialabs.restito.semantics.Condition.get) AUTHORIZATION(javax.ws.rs.core.HttpHeaders.AUTHORIZATION) GsonTypeAdapters(org.codice.gsonsupport.GsonTypeAdapters) Hashtable(java.util.Hashtable) Before(org.junit.Before) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) PublicClaims(com.auth0.jwt.impl.PublicClaims) Assert.assertTrue(org.junit.Assert.assertTrue) AUTH_TIME(org.pac4j.oidc.profile.OidcProfileDefinition.AUTH_TIME) Test(org.junit.Test) USER_AGENT(javax.ws.rs.core.HttpHeaders.USER_AGENT) EMAIL_VERIFIED(org.pac4j.oidc.profile.OidcProfileDefinition.EMAIL_VERIFIED) TimeUnit(java.util.concurrent.TimeUnit) ExamReactorStrategy(org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy) RSAKey(com.nimbusds.jose.jwk.RSAKey) Response(io.restassured.response.Response) Action.contentType(com.xebialabs.restito.semantics.Action.contentType) ACCESS_TOKEN(org.pac4j.oidc.profile.OidcProfileDefinition.ACCESS_TOKEN) LoggingUtils(org.codice.ddf.test.common.LoggingUtils) Call(com.xebialabs.restito.semantics.Call)

Aggregations

Response (io.restassured.response.Response)270 Test (org.junit.Test)209 Matchers.containsString (org.hamcrest.Matchers.containsString)43 ValidatableResponse (io.restassured.response.ValidatableResponse)32 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)31 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)29 RestAssuredClient (guru.nidi.ramltester.restassured3.RestAssuredClient)25 HttpResponse (org.apache.http.HttpResponse)25 Matchers.emptyString (org.hamcrest.Matchers.emptyString)24 FilterContext (io.restassured.filter.FilterContext)17 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)17 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)17 CswTestCommons.getMetacardIdFromCswInsertResponse (org.codice.ddf.itests.common.csw.CswTestCommons.getMetacardIdFromCswInsertResponse)17 Filter (io.restassured.filter.Filter)16 VerifyTest (org.apache.knox.test.category.VerifyTest)15 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)14 Book (org.baeldung.persistence.model.Book)13 JSONObject (org.json.simple.JSONObject)13 ResponseBuilder (io.restassured.builder.ResponseBuilder)12 IOException (java.io.IOException)11