Search in sources :

Example 71 with ResultMatcher

use of org.springframework.test.web.servlet.ResultMatcher in project spring-security by spring-projects.

the class HeadersConfigurerTests method getWhenHstsConfiguredWithPreloadInLambdaThenStrictTransportSecurityHeaderWithPreloadInResponse.

@Test
public void getWhenHstsConfiguredWithPreloadInLambdaThenStrictTransportSecurityHeaderWithPreloadInResponse() throws Exception {
    this.spring.register(HstsWithPreloadInLambdaConfig.class).autowire();
    ResultMatcher hsts = header().string(HttpHeaders.STRICT_TRANSPORT_SECURITY, "max-age=31536000 ; includeSubDomains ; preload");
    // @formatter:off
    MvcResult mvcResult = this.mvc.perform(get("/").secure(true)).andExpect(hsts).andReturn();
    // @formatter:on
    assertThat(mvcResult.getResponse().getHeaderNames()).containsExactly(HttpHeaders.STRICT_TRANSPORT_SECURITY);
}
Also used : ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.jupiter.api.Test)

Example 72 with ResultMatcher

use of org.springframework.test.web.servlet.ResultMatcher in project spring-security by spring-projects.

the class HeadersConfigurerTests method getWhenReferrerPolicyConfiguredThenReferrerPolicyHeaderInResponse.

@Test
public void getWhenReferrerPolicyConfiguredThenReferrerPolicyHeaderInResponse() throws Exception {
    this.spring.register(ReferrerPolicyDefaultConfig.class).autowire();
    ResultMatcher referrerPolicy = header().string("Referrer-Policy", ReferrerPolicy.NO_REFERRER.getPolicy());
    // @formatter:off
    MvcResult mvcResult = this.mvc.perform(get("/").secure(true)).andExpect(referrerPolicy).andReturn();
    // @formatter:on
    assertThat(mvcResult.getResponse().getHeaderNames()).containsExactly("Referrer-Policy");
}
Also used : ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.jupiter.api.Test)

Example 73 with ResultMatcher

use of org.springframework.test.web.servlet.ResultMatcher in project spring-security by spring-projects.

the class HeadersConfigurerTests method getWhenHstsConfiguredWithPreloadThenStrictTransportSecurityHeaderWithPreloadInResponse.

@Test
public void getWhenHstsConfiguredWithPreloadThenStrictTransportSecurityHeaderWithPreloadInResponse() throws Exception {
    this.spring.register(HstsWithPreloadConfig.class).autowire();
    ResultMatcher hsts = header().string(HttpHeaders.STRICT_TRANSPORT_SECURITY, "max-age=31536000 ; includeSubDomains ; preload");
    // @formatter:off
    MvcResult mvcResult = this.mvc.perform(get("/").secure(true)).andExpect(hsts).andReturn();
    // @formatter:on
    assertThat(mvcResult.getResponse().getHeaderNames()).containsExactly(HttpHeaders.STRICT_TRANSPORT_SECURITY);
}
Also used : ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.jupiter.api.Test)

Example 74 with ResultMatcher

use of org.springframework.test.web.servlet.ResultMatcher in project spring-security by spring-projects.

the class HeadersConfigurerTests method getWhenPermissionsPolicyConfiguredWithStringThenPermissionsPolicyHeaderInResponse.

@Test
public void getWhenPermissionsPolicyConfiguredWithStringThenPermissionsPolicyHeaderInResponse() throws Exception {
    this.spring.register(PermissionsPolicyStringConfig.class).autowire();
    ResultMatcher permissionsPolicy = header().string("Permissions-Policy", "geolocation=(self)");
    // @formatter:off
    MvcResult mvcResult = this.mvc.perform(get("/").secure(true)).andExpect(permissionsPolicy).andReturn();
    // @formatter:on
    assertThat(mvcResult.getResponse().getHeaderNames()).containsExactly("Permissions-Policy");
}
Also used : ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.jupiter.api.Test)

Aggregations

ResultMatcher (org.springframework.test.web.servlet.ResultMatcher)74 MvcResult (org.springframework.test.web.servlet.MvcResult)69 Test (org.junit.jupiter.api.Test)22 Cookie (javax.servlet.http.Cookie)15 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)13 ModelAndView (org.springframework.web.servlet.ModelAndView)11 Test (org.junit.Test)5 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)5 BindingResult (org.springframework.validation.BindingResult)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 HandlerMethod (org.springframework.web.method.HandlerMethod)4 Method (java.lang.reflect.Method)2 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HttpStatus (org.springframework.http.HttpStatus)1 MediaType (org.springframework.http.MediaType)1 AssertionErrors (org.springframework.test.util.AssertionErrors)1 StubMvcResult (org.springframework.test.web.servlet.StubMvcResult)1