Search in sources :

Example 1 with SpringTestContext

use of org.springframework.security.config.test.SpringTestContext in project spring-security by spring-projects.

the class AccessDeniedConfigTests method configureWhenAccessDeniedHandlerUsesPathAndRefThenException.

@Test
public void configureWhenAccessDeniedHandlerUsesPathAndRefThenException() {
    SpringTestContext context = this.spring.configLocations(this.xml("UsesPathAndRef"));
    assertThatExceptionOfType(BeanDefinitionParsingException.class).isThrownBy(() -> context.autowire()).withMessageContaining("attribute error-page cannot be used together with the 'ref' attribute");
}
Also used : SpringTestContext(org.springframework.security.config.test.SpringTestContext) Test(org.junit.jupiter.api.Test)

Example 2 with SpringTestContext

use of org.springframework.security.config.test.SpringTestContext in project spring-security by spring-projects.

the class CsrfConfigTests method requestWhenUsingCustomRequestMatcherConfiguredThenAppliesAccordingly.

@Test
public void requestWhenUsingCustomRequestMatcherConfiguredThenAppliesAccordingly() throws Exception {
    SpringTestContext context = this.spring.configLocations(this.xml("shared-controllers"), this.xml("WithRequestMatcher"), this.xml("mock-request-matcher"));
    context.autowire();
    RequestMatcher matcher = context.getContext().getBean(RequestMatcher.class);
    given(matcher.matches(any(HttpServletRequest.class))).willReturn(false);
    // @formatter:off
    this.mvc.perform(post("/ok")).andExpect(status().isOk());
    // @formatter:on
    given(matcher.matches(any(HttpServletRequest.class))).willReturn(true);
    // @formatter:off
    this.mvc.perform(get("/ok")).andExpect(status().isForbidden());
// @formatter:on
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) SpringTestContext(org.springframework.security.config.test.SpringTestContext) RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) Test(org.junit.jupiter.api.Test)

Example 3 with SpringTestContext

use of org.springframework.security.config.test.SpringTestContext in project spring-security by spring-projects.

the class AccessDeniedConfigTests method configureWhenAccessDeniedHandlerIsMissingLeadingSlashThenException.

@Test
public void configureWhenAccessDeniedHandlerIsMissingLeadingSlashThenException() {
    SpringTestContext context = this.spring.configLocations(this.xml("NoLeadingSlash"));
    assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> context.autowire()).withMessageContaining("errorPage must begin with '/'");
}
Also used : SpringTestContext(org.springframework.security.config.test.SpringTestContext) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 SpringTestContext (org.springframework.security.config.test.SpringTestContext)3 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 RequestMatcher (org.springframework.security.web.util.matcher.RequestMatcher)1