File tree Expand file tree Collapse file tree 3 files changed +12
-12
lines changed
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation
main/java/org/springframework/web/cors
test/java/org/springframework/web/cors Expand file tree Collapse file tree 3 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -549,31 +549,31 @@ private List<OriginPattern> combinePatterns(
549
549
550
550
/**
551
551
* Check the origin of the request against the configured allowed origins.
552
- * @param requestOrigin the origin to check
552
+ * @param origin the origin to check
553
553
* @return the origin to use for the response, or {@code null} which
554
554
* means the request origin is not allowed
555
555
*/
556
556
@ Nullable
557
- public String checkOrigin (@ Nullable String requestOrigin ) {
558
- if (!StringUtils .hasText (requestOrigin )) {
557
+ public String checkOrigin (@ Nullable String origin ) {
558
+ if (!StringUtils .hasText (origin )) {
559
559
return null ;
560
560
}
561
- requestOrigin = trimTrailingSlash (requestOrigin );
561
+ String originToCheck = trimTrailingSlash (origin );
562
562
if (!ObjectUtils .isEmpty (this .allowedOrigins )) {
563
563
if (this .allowedOrigins .contains (ALL )) {
564
564
validateAllowCredentials ();
565
565
return ALL ;
566
566
}
567
567
for (String allowedOrigin : this .allowedOrigins ) {
568
- if (requestOrigin .equalsIgnoreCase (allowedOrigin )) {
569
- return requestOrigin ;
568
+ if (originToCheck .equalsIgnoreCase (allowedOrigin )) {
569
+ return origin ;
570
570
}
571
571
}
572
572
}
573
573
if (!ObjectUtils .isEmpty (this .allowedOriginPatterns )) {
574
574
for (OriginPattern p : this .allowedOriginPatterns ) {
575
- if (p .getDeclaredPattern ().equals (ALL ) || p .getPattern ().matcher (requestOrigin ).matches ()) {
576
- return requestOrigin ;
575
+ if (p .getDeclaredPattern ().equals (ALL ) || p .getPattern ().matcher (originToCheck ).matches ()) {
576
+ return origin ;
577
577
}
578
578
}
579
579
}
Original file line number Diff line number Diff line change @@ -294,12 +294,12 @@ public void checkOriginAllowed() {
294
294
// specific origin matches Origin header with or without trailing "/"
295
295
config .setAllowedOrigins (Collections .singletonList ("https://domain.com" ));
296
296
assertThat (config .checkOrigin ("https://domain.com" )).isEqualTo ("https://domain.com" );
297
- assertThat (config .checkOrigin ("https://domain.com/" )).isEqualTo ("https://domain.com" );
297
+ assertThat (config .checkOrigin ("https://domain.com/" )).isEqualTo ("https://domain.com/ " );
298
298
299
299
// specific origin with trailing "/" matches Origin header with or without trailing "/"
300
300
config .setAllowedOrigins (Collections .singletonList ("https://domain.com/" ));
301
301
assertThat (config .checkOrigin ("https://domain.com" )).isEqualTo ("https://domain.com" );
302
- assertThat (config .checkOrigin ("https://domain.com/" )).isEqualTo ("https://domain.com" );
302
+ assertThat (config .checkOrigin ("https://domain.com/" )).isEqualTo ("https://domain.com/ " );
303
303
304
304
config .setAllowCredentials (false );
305
305
assertThat (config .checkOrigin ("https://domain.com" )).isEqualTo ("https://domain.com" );
Original file line number Diff line number Diff line change @@ -284,7 +284,7 @@ void classLevelComposedAnnotation(TestRequestMappingInfoHandlerMapping mapping)
284
284
CorsConfiguration config = getCorsConfiguration (chain , false );
285
285
assertThat (config ).isNotNull ();
286
286
assertThat (config .getAllowedMethods ()).containsExactly ("GET" );
287
- assertThat (config .getAllowedOrigins ()).containsExactly ("http://www.foo.example/ " );
287
+ assertThat (config .getAllowedOrigins ()).containsExactly ("http://www.foo.example" );
288
288
assertThat (config .getAllowCredentials ()).isTrue ();
289
289
}
290
290
@@ -297,7 +297,7 @@ void methodLevelComposedAnnotation(TestRequestMappingInfoHandlerMapping mapping)
297
297
CorsConfiguration config = getCorsConfiguration (chain , false );
298
298
assertThat (config ).isNotNull ();
299
299
assertThat (config .getAllowedMethods ()).containsExactly ("GET" );
300
- assertThat (config .getAllowedOrigins ()).containsExactly ("http://www.foo.example/ " );
300
+ assertThat (config .getAllowedOrigins ()).containsExactly ("http://www.foo.example" );
301
301
assertThat (config .getAllowCredentials ()).isTrue ();
302
302
}
303
303
You can’t perform that action at this time.
0 commit comments