use of io.restassured.module.mockmvc.http.SecuredController in project rest-assured by rest-assured.
the class SecuredControllerTest method statically_defined_auth_has_precedence_over_statically_defined_request_spec.
@Test
public void statically_defined_auth_has_precedence_over_statically_defined_request_spec() {
RestAssuredMockMvc.authentication = RestAssuredMockMvc.principal(new User("authorized_user", "password", Collections.<GrantedAuthority>emptyList()));
RestAssuredMockMvc.requestSpecification = new MockMvcRequestSpecBuilder().setAuth(RestAssuredMockMvc.authentication(new TestingAuthenticationToken("name", "pw"))).build();
try {
RestAssuredMockMvc.given().standaloneSetup(new SecuredController()).param("name", "Johan").when().get("/springSecurityGreeting").then().statusCode(200).body("content", equalTo("Hello, Johan!"));
} finally {
RestAssuredMockMvc.reset();
}
}
use of io.restassured.module.mockmvc.http.SecuredController in project rest-assured by rest-assured.
the class SecuredControllerTest method spring_context_holder_is_cleared_after_failed_test.
@Test
public void spring_context_holder_is_cleared_after_failed_test() {
exception.expect(NestedServletException.class);
exception.expectMessage("Not authorized");
try {
RestAssuredMockMvc.given().standaloneSetup(new SecuredController()).auth().principal(new User("authorized_user2", "password", Collections.<GrantedAuthority>emptyList())).param("name", "Johan").when().get("/springSecurityGreeting").then().statusCode(200).body("content", equalTo("Hello, Johan!"));
} finally {
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
}
}
use of io.restassured.module.mockmvc.http.SecuredController in project rest-assured by rest-assured.
the class SecuredControllerTest method spring_context_holder_is_cleared_after_test.
@Test
public void spring_context_holder_is_cleared_after_test() {
RestAssuredMockMvc.given().standaloneSetup(new SecuredController()).auth().principal(new User("authorized_user", "password", Collections.<GrantedAuthority>emptyList())).param("name", "Johan").when().get("/springSecurityGreeting").then().statusCode(200).body("content", equalTo("Hello, Johan!"));
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
}
use of io.restassured.module.mockmvc.http.SecuredController in project rest-assured by rest-assured.
the class SecuredControllerTest method spring_context_holder_is_cleared_after_failed_test_when_auth_is_statically_defined.
@Test
public void spring_context_holder_is_cleared_after_failed_test_when_auth_is_statically_defined() {
RestAssuredMockMvc.authentication = RestAssuredMockMvc.principal(new User("authorized_user", "password", Collections.<GrantedAuthority>emptyList()));
try {
RestAssuredMockMvc.given().standaloneSetup(new SecuredController()).param("name", "Johan").when().get("/springSecurityGreeting").then().statusCode(200).body("content", equalTo("Hello, Johan!"));
} finally {
RestAssuredMockMvc.reset();
}
assertThat(SecurityContextHolder.getContext().getAuthentication()).isNull();
}
Aggregations