Search in sources :

Example 1 with MockMvcAuthenticationScheme

use of io.restassured.module.mockmvc.specification.MockMvcAuthenticationScheme in project rest-assured by rest-assured.

the class MockMvcRequestSpecificationMergingTest method authentication_is_not_overwritten_when_not_defined_in_specification.

@Test
public void authentication_is_not_overwritten_when_not_defined_in_specification() {
    // Given
    MockMvcAuthenticationScheme thisAuth = RestAssuredMockMvc.principal("this");
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addQueryParam("param1", "value1").build();
    // When
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().spec(new MockMvcRequestSpecBuilder().setAuth(thisAuth).build()).spec(specToMerge);
    // Then
    assertThat(((TestingAuthenticationToken) implOf(spec).getAuthentication()).getPrincipal()).isEqualTo("this");
    Assertions.assertThat(implOf(spec).getQueryParams()).containsOnly(entry("param1", "value1"));
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) MockMvcAuthenticationScheme(io.restassured.module.mockmvc.specification.MockMvcAuthenticationScheme) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 2 with MockMvcAuthenticationScheme

use of io.restassured.module.mockmvc.specification.MockMvcAuthenticationScheme in project rest-assured by rest-assured.

the class MockMvcRequestSpecificationMergingTest method authentication_is_overwritten_when_defined_in_specification.

@Test
public void authentication_is_overwritten_when_defined_in_specification() {
    // Given
    MockMvcAuthenticationScheme otherAuth = RestAssuredMockMvc.principal("other");
    MockMvcAuthenticationScheme thisAuth = RestAssuredMockMvc.principal("this");
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setAuth(otherAuth).build();
    // When
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().spec(new MockMvcRequestSpecBuilder().setAuth(thisAuth).build()).spec(specToMerge);
    // Then
    assertThat(((TestingAuthenticationToken) implOf(spec).getAuthentication()).getPrincipal()).isEqualTo("other");
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) MockMvcAuthenticationScheme(io.restassured.module.mockmvc.specification.MockMvcAuthenticationScheme) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 3 with MockMvcAuthenticationScheme

use of io.restassured.module.mockmvc.specification.MockMvcAuthenticationScheme in project rest-assured by rest-assured.

the class MockMvcRequestSpecificationMergingTest method authentication_is_overwritten_when_using_dsl_and_defined_in_specification.

@Test
public void authentication_is_overwritten_when_using_dsl_and_defined_in_specification() {
    // Given
    MockMvcAuthenticationScheme otherAuth = RestAssuredMockMvc.principal("other");
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setAuth(otherAuth).build();
    // When
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().auth().principal("this").and().spec(specToMerge);
    // Then
    assertThat(((TestingAuthenticationToken) implOf(spec).getAuthentication()).getPrincipal()).isEqualTo("other");
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) MockMvcAuthenticationScheme(io.restassured.module.mockmvc.specification.MockMvcAuthenticationScheme) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Aggregations

MockMvcAuthenticationScheme (io.restassured.module.mockmvc.specification.MockMvcAuthenticationScheme)3 MockMvcRequestSpecBuilder (io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder)3 MockMvcRequestSpecification (io.restassured.module.mockmvc.specification.MockMvcRequestSpecification)3 Test (org.junit.Test)3 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)3