24
24
import org .springframework .data .rest .tests .AbstractWebIntegrationTests ;
25
25
import org .springframework .data .rest .webmvc .RepositoryRestHandlerMapping ;
26
26
import org .springframework .data .rest .webmvc .config .RepositoryRestConfigurer ;
27
- import org .springframework .hateoas .Link ;
28
27
import org .springframework .hateoas .LinkRelation ;
29
28
import org .springframework .http .HttpHeaders ;
30
29
import org .springframework .http .HttpMethod ;
@@ -50,19 +49,20 @@ RepositoryRestConfigurer repositoryRestConfigurer() {
50
49
/**
51
50
* @see ItemRepository
52
51
*/
53
- @ Test // DATAREST-1397
52
+ @ Test // DATAREST-1397, #2208
54
53
void appliesRepositoryCorsConfiguration () throws Exception {
55
54
56
- Link findItems = client .discoverUnique (LinkRelation .of ("items" ));
55
+ var findItems = client .discoverUnique (LinkRelation .of ("items" ));
57
56
58
57
// 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" );
64
61
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 ("," ))
66
66
.containsExactlyInAnyOrderElementsOf (
67
67
RepositoryRestHandlerMapping .DEFAULT_ALLOWED_METHODS .map (HttpMethod ::name ));
68
68
}
0 commit comments