Skip to content

Commit aea23e4

Browse files
committed
Polish
1 parent 0d1b7fd commit aea23e4

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

spring-web/src/test/java/org/springframework/web/cors/DefaultCorsProcessorTests.java

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void setup() {
5959
@Test
6060
public void actualRequestWithOriginHeader() throws Exception {
6161
this.request.setMethod(HttpMethod.GET.name());
62-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
62+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
6363
this.processor.processRequest(this.conf, request, response);
6464
assertFalse(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
6565
assertEquals(HttpServletResponse.SC_FORBIDDEN, response.getStatus());
@@ -68,7 +68,7 @@ public void actualRequestWithOriginHeader() throws Exception {
6868
@Test
6969
public void actualRequestWithOriginHeaderAndNullConfig() throws Exception {
7070
this.request.setMethod(HttpMethod.GET.name());
71-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
71+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
7272
this.processor.processRequest(null, request, response);
7373
assertFalse(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
7474
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
@@ -77,7 +77,7 @@ public void actualRequestWithOriginHeaderAndNullConfig() throws Exception {
7777
@Test
7878
public void actualRequestWithOriginHeaderAndAllowedOrigin() throws Exception {
7979
this.request.setMethod(HttpMethod.GET.name());
80-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
80+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
8181
this.conf.addAllowedOrigin("*");
8282
this.processor.processRequest(this.conf, request, response);
8383
assertTrue(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
@@ -88,16 +88,16 @@ public void actualRequestWithOriginHeaderAndAllowedOrigin() throws Exception {
8888
}
8989

9090
@Test
91-
public void actualRequestCrendentials() throws Exception {
91+
public void actualRequestCredentials() throws Exception {
9292
this.request.setMethod(HttpMethod.GET.name());
93-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
94-
this.conf.addAllowedOrigin("http://domain2.com/home.html");
95-
this.conf.addAllowedOrigin("http://domain2.com/test.html");
96-
this.conf.addAllowedOrigin("http://domain2.com/logout.html");
93+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
94+
this.conf.addAllowedOrigin("http://domain1.com");
95+
this.conf.addAllowedOrigin("http://domain2.com");
96+
this.conf.addAllowedOrigin("http://domain3.com");
9797
this.conf.setAllowCredentials(true);
9898
this.processor.processRequest(this.conf, request, response);
9999
assertTrue(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
100-
assertEquals("http://domain2.com/test.html", response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
100+
assertEquals("http://domain2.com", response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
101101
assertTrue(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
102102
assertEquals("true", response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
103103
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
@@ -106,12 +106,12 @@ public void actualRequestCrendentials() throws Exception {
106106
@Test
107107
public void actualRequestCredentialsWithOriginWildcard() throws Exception {
108108
this.request.setMethod(HttpMethod.GET.name());
109-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
109+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
110110
this.conf.addAllowedOrigin("*");
111111
this.conf.setAllowCredentials(true);
112112
this.processor.processRequest(this.conf, request, response);
113113
assertTrue(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
114-
assertEquals("http://domain2.com/test.html", response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
114+
assertEquals("http://domain2.com", response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
115115
assertTrue(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
116116
assertEquals("true", response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
117117
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
@@ -120,8 +120,8 @@ public void actualRequestCredentialsWithOriginWildcard() throws Exception {
120120
@Test
121121
public void actualRequestCaseInsensitiveOriginMatch() throws Exception {
122122
this.request.setMethod(HttpMethod.GET.name());
123-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
124-
this.conf.addAllowedOrigin("http://domain2.com/TEST.html");
123+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
124+
this.conf.addAllowedOrigin("http://DOMAIN2.com");
125125
this.processor.processRequest(this.conf, request, response);
126126
assertTrue(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
127127
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
@@ -130,13 +130,13 @@ public void actualRequestCaseInsensitiveOriginMatch() throws Exception {
130130
@Test
131131
public void actualRequestExposedHeaders() throws Exception {
132132
this.request.setMethod(HttpMethod.GET.name());
133-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
133+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
134134
this.conf.addExposedHeader("header1");
135135
this.conf.addExposedHeader("header2");
136-
this.conf.addAllowedOrigin("http://domain2.com/test.html");
136+
this.conf.addAllowedOrigin("http://domain2.com");
137137
this.processor.processRequest(this.conf, request, response);
138138
assertTrue(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
139-
assertEquals("http://domain2.com/test.html", response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
139+
assertEquals("http://domain2.com", response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
140140
assertTrue(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS));
141141
assertTrue(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS).contains("header1"));
142142
assertTrue(this.response.getHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS).contains("header2"));
@@ -146,7 +146,7 @@ public void actualRequestExposedHeaders() throws Exception {
146146
@Test
147147
public void preflightRequestAllOriginsAllowed() throws Exception {
148148
this.request.setMethod(HttpMethod.OPTIONS.name());
149-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
149+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
150150
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
151151
this.conf.addAllowedOrigin("*");
152152
this.processor.processRequest(this.conf, request, response);
@@ -156,7 +156,7 @@ public void preflightRequestAllOriginsAllowed() throws Exception {
156156
@Test
157157
public void preflightRequestWrongAllowedMethod() throws Exception {
158158
this.request.setMethod(HttpMethod.OPTIONS.name());
159-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
159+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
160160
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "DELETE");
161161
this.conf.addAllowedOrigin("*");
162162
this.processor.processRequest(this.conf, request, response);
@@ -166,7 +166,7 @@ public void preflightRequestWrongAllowedMethod() throws Exception {
166166
@Test
167167
public void preflightRequestMatchedAllowedMethod() throws Exception {
168168
this.request.setMethod(HttpMethod.OPTIONS.name());
169-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
169+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
170170
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
171171
this.conf.addAllowedOrigin("*");
172172
this.processor.processRequest(this.conf, request, response);
@@ -177,7 +177,7 @@ public void preflightRequestMatchedAllowedMethod() throws Exception {
177177
@Test
178178
public void preflightRequestTestWithOriginButWithoutOtherHeaders() throws Exception {
179179
this.request.setMethod(HttpMethod.OPTIONS.name());
180-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
180+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
181181
this.processor.processRequest(this.conf, request, response);
182182
assertFalse(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
183183
assertEquals(HttpServletResponse.SC_FORBIDDEN, response.getStatus());
@@ -186,7 +186,7 @@ public void preflightRequestTestWithOriginButWithoutOtherHeaders() throws Except
186186
@Test
187187
public void preflightRequestWithoutRequestMethod() throws Exception {
188188
this.request.setMethod(HttpMethod.OPTIONS.name());
189-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
189+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
190190
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "Header1");
191191
this.processor.processRequest(this.conf, request, response);
192192
assertFalse(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
@@ -196,7 +196,7 @@ public void preflightRequestWithoutRequestMethod() throws Exception {
196196
@Test
197197
public void preflightRequestWithRequestAndMethodHeaderButNoConfig() throws Exception {
198198
this.request.setMethod(HttpMethod.OPTIONS.name());
199-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
199+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
200200
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "Header1");
201201
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
202202
this.processor.processRequest(this.conf, request, response);
@@ -207,7 +207,7 @@ public void preflightRequestWithRequestAndMethodHeaderButNoConfig() throws Excep
207207
@Test
208208
public void preflightRequestValidRequestAndConfig() throws Exception {
209209
this.request.setMethod(HttpMethod.OPTIONS.name());
210-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
210+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
211211
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "Header1");
212212
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
213213
this.conf.addAllowedOrigin("*");
@@ -225,19 +225,19 @@ public void preflightRequestValidRequestAndConfig() throws Exception {
225225
}
226226

227227
@Test
228-
public void preflightRequestCrendentials() throws Exception {
228+
public void preflightRequestCredentials() throws Exception {
229229
this.request.setMethod(HttpMethod.OPTIONS.name());
230-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
230+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
231231
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "Header1");
232232
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
233-
this.conf.addAllowedOrigin("http://domain2.com/home.html");
234-
this.conf.addAllowedOrigin("http://domain2.com/test.html");
235-
this.conf.addAllowedOrigin("http://domain2.com/logout.html");
233+
this.conf.addAllowedOrigin("http://domain1.com");
234+
this.conf.addAllowedOrigin("http://domain2.com");
235+
this.conf.addAllowedOrigin("http://domain3.com");
236236
this.conf.addAllowedHeader("Header1");
237237
this.conf.setAllowCredentials(true);
238238
this.processor.processRequest(this.conf, request, response);
239239
assertTrue(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
240-
assertEquals("http://domain2.com/test.html", response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
240+
assertEquals("http://domain2.com", response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
241241
assertTrue(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
242242
assertEquals("true", response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
243243
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
@@ -246,30 +246,30 @@ public void preflightRequestCrendentials() throws Exception {
246246
@Test
247247
public void preflightRequestCredentialsWithOriginWildcard() throws Exception {
248248
this.request.setMethod(HttpMethod.OPTIONS.name());
249-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
249+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
250250
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "Header1");
251251
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
252-
this.conf.addAllowedOrigin("http://domain2.com/home.html");
252+
this.conf.addAllowedOrigin("http://domain1.com");
253253
this.conf.addAllowedOrigin("*");
254-
this.conf.addAllowedOrigin("http://domain2.com/logout.html");
254+
this.conf.addAllowedOrigin("http://domain3.com");
255255
this.conf.addAllowedHeader("Header1");
256256
this.conf.setAllowCredentials(true);
257257
this.processor.processRequest(this.conf, request, response);
258258
assertTrue(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
259-
assertEquals("http://domain2.com/test.html", response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
259+
assertEquals("http://domain2.com", response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
260260
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
261261
}
262262

263263
@Test
264264
public void preflightRequestAllowedHeaders() throws Exception {
265265
this.request.setMethod(HttpMethod.OPTIONS.name());
266-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
266+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
267267
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "Header1, Header2");
268268
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
269269
this.conf.addAllowedHeader("Header1");
270270
this.conf.addAllowedHeader("Header2");
271271
this.conf.addAllowedHeader("Header3");
272-
this.conf.addAllowedOrigin("http://domain2.com/test.html");
272+
this.conf.addAllowedOrigin("http://domain2.com");
273273
this.processor.processRequest(this.conf, request, response);
274274
assertTrue(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
275275
assertTrue(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS));
@@ -282,11 +282,11 @@ public void preflightRequestAllowedHeaders() throws Exception {
282282
@Test
283283
public void preflightRequestAllowsAllHeaders() throws Exception {
284284
this.request.setMethod(HttpMethod.OPTIONS.name());
285-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
285+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
286286
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "Header1, Header2");
287287
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
288288
this.conf.addAllowedHeader("*");
289-
this.conf.addAllowedOrigin("http://domain2.com/test.html");
289+
this.conf.addAllowedOrigin("http://domain2.com");
290290
this.processor.processRequest(this.conf, request, response);
291291
assertTrue(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
292292
assertTrue(this.response.containsHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS));
@@ -299,7 +299,7 @@ public void preflightRequestAllowsAllHeaders() throws Exception {
299299
@Test
300300
public void preflightRequestWithNullConfig() throws Exception {
301301
this.request.setMethod(HttpMethod.OPTIONS.name());
302-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
302+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
303303
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
304304
this.conf.addAllowedOrigin("*");
305305
this.processor.processRequest(null, request, response);

spring-webmvc/src/test/java/org/springframework/web/servlet/handler/CorsAbstractHandlerMappingTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void setup() {
6666
public void actualRequestWithoutCorsConfigurationProvider() throws Exception {
6767
this.request.setMethod(RequestMethod.GET.name());
6868
this.request.setRequestURI("/foo");
69-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
69+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
7070
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
7171
HandlerExecutionChain chain = handlerMapping.getHandler(this.request);
7272
assertNotNull(chain);
@@ -77,7 +77,7 @@ public void actualRequestWithoutCorsConfigurationProvider() throws Exception {
7777
public void preflightRequestWithoutCorsConfigurationProvider() throws Exception {
7878
this.request.setMethod(RequestMethod.OPTIONS.name());
7979
this.request.setRequestURI("/foo");
80-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
80+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
8181
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
8282
HandlerExecutionChain chain = handlerMapping.getHandler(this.request);
8383
assertNotNull(chain);
@@ -89,7 +89,7 @@ public void preflightRequestWithoutCorsConfigurationProvider() throws Exception
8989
public void actualRequestWithCorsConfigurationProvider() throws Exception {
9090
this.request.setMethod(RequestMethod.GET.name());
9191
this.request.setRequestURI("/cors");
92-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
92+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
9393
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
9494
HandlerExecutionChain chain = handlerMapping.getHandler(this.request);
9595
assertNotNull(chain);
@@ -103,7 +103,7 @@ public void actualRequestWithCorsConfigurationProvider() throws Exception {
103103
public void preflightRequestWithCorsConfigurationProvider() throws Exception {
104104
this.request.setMethod(RequestMethod.OPTIONS.name());
105105
this.request.setRequestURI("/cors");
106-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
106+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
107107
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
108108
HandlerExecutionChain chain = handlerMapping.getHandler(this.request);
109109
assertNotNull(chain);
@@ -121,7 +121,7 @@ public void actualRequestWithMappedCorsConfiguration() throws Exception {
121121
this.handlerMapping.setCorsConfiguration(Collections.singletonMap("/foo", config));
122122
this.request.setMethod(RequestMethod.GET.name());
123123
this.request.setRequestURI("/foo");
124-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
124+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
125125
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
126126
HandlerExecutionChain chain = handlerMapping.getHandler(this.request);
127127
assertNotNull(chain);
@@ -138,7 +138,7 @@ public void preflightRequestWithMappedCorsConfiguration() throws Exception {
138138
this.handlerMapping.setCorsConfiguration(Collections.singletonMap("/foo", config));
139139
this.request.setMethod(RequestMethod.OPTIONS.name());
140140
this.request.setRequestURI("/foo");
141-
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com/test.html");
141+
this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
142142
this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
143143
HandlerExecutionChain chain = handlerMapping.getHandler(this.request);
144144
assertNotNull(chain);

0 commit comments

Comments
 (0)