Apply allowedOriginPatterns in SockJsService

See gh-26108
This commit is contained in:
Rossen Stoyanchev
2020-11-18 20:57:49 +00:00
parent 9beca06404
commit 8130bf505f
3 changed files with 37 additions and 32 deletions

View File

@@ -215,7 +215,7 @@ public class SockJsServiceTests extends AbstractHttpRequestTests {
@Test // SPR-12283
public void handleInfoOptionsWithOriginAndCorsHeadersDisabled() {
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain2.example");
this.service.setAllowedOrigins(Collections.singletonList("*"));
this.service.setAllowedOriginPatterns(Collections.singletonList("*"));
this.service.setSuppressCors(true);
this.servletRequest.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "Last-Modified");
@@ -223,10 +223,12 @@ public class SockJsServiceTests extends AbstractHttpRequestTests {
assertThat(this.service.getCorsConfiguration(this.servletRequest)).isNull();
this.service.setAllowedOrigins(Collections.singletonList("https://mydomain1.example"));
this.service.setAllowedOriginPatterns(Collections.emptyList());
resetResponseAndHandleRequest("OPTIONS", "/echo/info", HttpStatus.FORBIDDEN);
assertThat(this.service.getCorsConfiguration(this.servletRequest)).isNull();
this.service.setAllowedOrigins(Arrays.asList("https://mydomain1.example", "https://mydomain2.example", "http://mydomain3.example"));
this.service.setAllowedOriginPatterns(Collections.emptyList());
resetResponseAndHandleRequest("OPTIONS", "/echo/info", HttpStatus.NO_CONTENT);
assertThat(this.service.getCorsConfiguration(this.servletRequest)).isNull();
}