Search in sources :

Example 1 with AuthenticationScheme

use of io.restassured.authentication.AuthenticationScheme in project rest-assured by rest-assured.

the class OAuthITest method oauth2_works_with_non_preemptive_header_signing.

@Test
public void oauth2_works_with_non_preemptive_header_signing() {
    final String accessToken = "accessToken";
    given().auth().oauth2(accessToken).filter(new Filter() {

        public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
            AuthenticationScheme scheme = requestSpec.getAuthenticationScheme();
            assertThat(scheme, instanceOf(PreemptiveOAuth2HeaderScheme.class));
            assertThat(((PreemptiveOAuth2HeaderScheme) scheme).getAccessToken(), equalTo(accessToken));
            return new ResponseBuilder().setBody("ok").setStatusCode(200).build();
        }
    }).when().get("/somewhere").then().statusCode(200);
}
Also used : Response(io.restassured.response.Response) AuthenticationScheme(io.restassured.authentication.AuthenticationScheme) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) Filter(io.restassured.filter.Filter) PreemptiveOAuth2HeaderScheme(io.restassured.authentication.PreemptiveOAuth2HeaderScheme) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) ResponseBuilder(io.restassured.builder.ResponseBuilder) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Aggregations

AuthenticationScheme (io.restassured.authentication.AuthenticationScheme)1 PreemptiveOAuth2HeaderScheme (io.restassured.authentication.PreemptiveOAuth2HeaderScheme)1 ResponseBuilder (io.restassured.builder.ResponseBuilder)1 Filter (io.restassured.filter.Filter)1 FilterContext (io.restassured.filter.FilterContext)1 Response (io.restassured.response.Response)1 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)1 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)1 Test (org.junit.Test)1