|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2020 the original author or authors. |
| 2 | + * Copyright 2002-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.security.web.savedrequest;
|
18 | 18 |
|
| 19 | +import java.util.Arrays; |
19 | 20 | import java.util.Base64;
|
| 21 | +import java.util.Collections; |
| 22 | +import java.util.Locale; |
20 | 23 |
|
21 | 24 | import javax.servlet.http.Cookie;
|
22 | 25 | import javax.servlet.http.HttpServletRequest;
|
@@ -183,6 +186,25 @@ public void removeRequestWhenInvokedThenSetsAnExpiredCookieOnResponse() {
|
183 | 186 | assertThat(expiredCookie.getMaxAge()).isZero();
|
184 | 187 | }
|
185 | 188 |
|
| 189 | + // gh-13792 |
| 190 | + @Test |
| 191 | + public void matchingRequestWhenMatchThenKeepOriginalRequestLocale() { |
| 192 | + CookieRequestCache cookieRequestCache = new CookieRequestCache(); |
| 193 | + MockHttpServletRequest request = new MockHttpServletRequest(); |
| 194 | + request.setServerPort(443); |
| 195 | + request.setSecure(true); |
| 196 | + request.setScheme("https"); |
| 197 | + request.setServerName("example.com"); |
| 198 | + request.setRequestURI("/destination"); |
| 199 | + request.setPreferredLocales(Arrays.asList(Locale.FRENCH, Locale.GERMANY)); |
| 200 | + String redirectUrl = "https://example.com/destination"; |
| 201 | + request.setCookies(new Cookie(DEFAULT_COOKIE_NAME, encodeCookie(redirectUrl))); |
| 202 | + MockHttpServletResponse response = new MockHttpServletResponse(); |
| 203 | + HttpServletRequest matchingRequest = cookieRequestCache.getMatchingRequest(request, response); |
| 204 | + assertThat(matchingRequest).isNotNull(); |
| 205 | + assertThat(Collections.list(matchingRequest.getLocales())).contains(Locale.FRENCH, Locale.GERMANY); |
| 206 | + } |
| 207 | + |
186 | 208 | private static String encodeCookie(String cookieValue) {
|
187 | 209 | return Base64.getEncoder().encodeToString(cookieValue.getBytes());
|
188 | 210 | }
|
|
0 commit comments