49
49
/**
50
50
* @author Peter Müller
51
51
*/
52
- @ SpringBootTest (properties = {"management.endpoint.gateway.enabled=true" ,
53
- "management.endpoints.web.exposure.include=*" , "spring.cloud.gateway.actuator.verbose.enabled=true" },
52
+ @ SpringBootTest (properties = { "management.endpoint.gateway.enabled=true" ,
53
+ "management.endpoints.web.exposure.include=*" , "spring.cloud.gateway.actuator.verbose.enabled=true" },
54
54
webEnvironment = RANDOM_PORT )
55
55
@ DirtiesContext (classMode = DirtiesContext .ClassMode .AFTER_EACH_TEST_METHOD )
56
56
@ ActiveProfiles ("redis-route-repository" )
@@ -94,8 +94,9 @@ public void testCorsConfigurationAfterReload() {
94
94
createOrUpdateRouteWithCors (cors );
95
95
96
96
Awaitility .await ().atMost (Duration .ofSeconds (3 )).untilAsserted (() -> assertRouteHasCorsConfig (cors ));
97
- Awaitility .await ().atMost (Duration .ofSeconds (3 ))
98
- .untilAsserted (() -> assertPreflightAllowOrigin ("http://example.org" ));
97
+ Awaitility .await ()
98
+ .atMost (Duration .ofSeconds (3 ))
99
+ .untilAsserted (() -> assertPreflightAllowOrigin ("http://example.org" ));
99
100
}
100
101
101
102
void createOrUpdateRouteWithCors (Map <String , Object > cors ) {
@@ -108,41 +109,41 @@ void createOrUpdateRouteWithCors(Map<String, Object> cors) {
108
109
testRouteDefinition .setMetadata (Map .of ("cors" , cors ));
109
110
110
111
testClient .post ()
111
- .uri ("http://localhost:" + port + "/actuator/gateway/routes/cors-test-route" )
112
- .accept (MediaType .APPLICATION_JSON )
113
- .body (BodyInserters .fromValue (testRouteDefinition ))
114
- .exchange ()
115
- .expectStatus ()
116
- .isCreated ();
112
+ .uri ("http://localhost:" + port + "/actuator/gateway/routes/cors-test-route" )
113
+ .accept (MediaType .APPLICATION_JSON )
114
+ .body (BodyInserters .fromValue (testRouteDefinition ))
115
+ .exchange ()
116
+ .expectStatus ()
117
+ .isCreated ();
117
118
118
119
testClient .post ()
119
- .uri ("http://localhost:" + port + "/actuator/gateway/refresh" )
120
- .exchange ()
121
- .expectStatus ()
122
- .isOk ();
120
+ .uri ("http://localhost:" + port + "/actuator/gateway/refresh" )
121
+ .exchange ()
122
+ .expectStatus ()
123
+ .isOk ();
123
124
}
124
125
125
126
void assertRouteHasCorsConfig (Map <String , Object > cors ) {
126
127
testClient .get ()
127
- .uri ("http://localhost:" + port + "/actuator/gateway/routes/cors-test-route" )
128
- .exchange ()
129
- .expectStatus ()
130
- .isOk ()
131
- .expectBody ()
132
- .jsonPath ("$.metadata" )
133
- .value (map -> assertThat ((Map <String , Object >) map ).hasSize (1 )
134
- .containsEntry ("cors" , cors ));
128
+ .uri ("http://localhost:" + port + "/actuator/gateway/routes/cors-test-route" )
129
+ .exchange ()
130
+ .expectStatus ()
131
+ .isOk ()
132
+ .expectBody ()
133
+ .jsonPath ("$.metadata" )
134
+ .value (map -> assertThat ((Map <String , Object >) map ).hasSize (1 ).containsEntry ("cors" , cors ));
135
135
}
136
136
137
137
void assertPreflightAllowOrigin (String origin ) {
138
138
testClient .options ()
139
- .uri ("http://localhost:" + port + "/" )
140
- .header ("Origin" , "http://example.org" )
141
- .header ("Access-Control-Request-Method" , "GET" )
142
- .exchange ()
143
- .expectStatus ()
144
- .isOk ()
145
- .expectHeader ()
146
- .valueEquals ("Access-Control-Allow-Origin" , origin );
139
+ .uri ("http://localhost:" + port + "/" )
140
+ .header ("Origin" , "http://example.org" )
141
+ .header ("Access-Control-Request-Method" , "GET" )
142
+ .exchange ()
143
+ .expectStatus ()
144
+ .isOk ()
145
+ .expectHeader ()
146
+ .valueEquals ("Access-Control-Allow-Origin" , origin );
147
147
}
148
+
148
149
}
0 commit comments