2424import org .springframework .data .rest .tests .AbstractWebIntegrationTests ;
2525import org .springframework .data .rest .webmvc .RepositoryRestHandlerMapping ;
2626import org .springframework .data .rest .webmvc .config .RepositoryRestConfigurer ;
27- import org .springframework .hateoas .Link ;
2827import org .springframework .hateoas .LinkRelation ;
2928import org .springframework .http .HttpHeaders ;
3029import org .springframework .http .HttpMethod ;
@@ -50,19 +49,20 @@ RepositoryRestConfigurer repositoryRestConfigurer() {
5049 /**
5150 * @see ItemRepository
5251 */
53- @ Test // DATAREST-1397
52+ @ Test // DATAREST-1397, #2208
5453 void appliesRepositoryCorsConfiguration () throws Exception {
5554
56- Link findItems = client .discoverUnique (LinkRelation .of ("items" ));
55+ var findItems = client .discoverUnique (LinkRelation .of ("items" ));
5756
5857 // Preflight request
59- String header = mvc
60- .perform (options (findItems .expand ().getHref ()).header (HttpHeaders .ORIGIN , "http://far.far.example" )
61- .header (HttpHeaders .ACCESS_CONTROL_REQUEST_METHOD , "POST" )) //
62- .andExpect (status ().isOk ()) //
63- .andReturn ().getResponse ().getHeader (HttpHeaders .ACCESS_CONTROL_ALLOW_METHODS );
58+ var request = options (findItems .expand ().getHref ()) //
59+ .header (HttpHeaders .ORIGIN , "https://far.far.example" ) //
60+ .header (HttpHeaders .ACCESS_CONTROL_REQUEST_METHOD , "POST" );
6461
65- assertThat (header .split ("," ))
62+ var response = mvc .perform (request ).andExpect (status ().isOk ()).andReturn ().getResponse ();
63+
64+ assertThat (response .getHeader (HttpHeaders .ACCESS_CONTROL_ALLOW_ORIGIN )).isEqualTo ("*" );
65+ assertThat (response .getHeader (HttpHeaders .ACCESS_CONTROL_ALLOW_METHODS ).split ("," ))
6666 .containsExactlyInAnyOrderElementsOf (
6767 RepositoryRestHandlerMapping .DEFAULT_ALLOWED_METHODS .map (HttpMethod ::name ));
6868 }
0 commit comments