@@ -23,10 +23,12 @@ import io.mockk.slot
23
23
import io.mockk.spyk
24
24
import io.mockk.verify
25
25
import io.netty.handler.codec.http.cookie.CookieHeaderNames
26
+ import java.net.URI
27
+ import java.time.Duration
28
+ import java.time.Instant
26
29
import org.intellij.lang.annotations.Language
27
30
import org.junit.jupiter.api.Test
28
31
import org.springframework.http.HttpCookie
29
- import org.springframework.http.HttpStatus
30
32
import org.springframework.mock.http.server.reactive.MockServerHttpRequest
31
33
import org.springframework.mock.web.server.MockServerWebExchange
32
34
import org.springframework.util.CollectionUtils
@@ -35,10 +37,6 @@ import reactor.core.publisher.Mono
35
37
import strikt.api.expectThat
36
38
import strikt.assertions.isEqualTo
37
39
import strikt.assertions.isTrue
38
- import java.net.URI
39
- import java.time.Duration
40
- import java.time.Instant
41
- import strikt.assertions.isNotNull
42
40
43
41
internal class CookieServerRequestCacheTest {
44
42
@@ -68,7 +66,9 @@ internal class CookieServerRequestCacheTest {
68
66
"""
69
67
70
68
private val client: AuthenticationStoreClient = mockk {
71
- mockCookieSecurityProperties(this , ORG_ID ,
69
+ mockCookieSecurityProperties(
70
+ this ,
71
+ ORG_ID ,
72
72
CookieSecurityProperties (
73
73
keySet = CleartextKeysetHandle .read(JsonKeysetReader .withBytes(keyset.toByteArray())),
74
74
lastRotation = Instant .now(),
@@ -169,11 +169,10 @@ internal class CookieServerRequestCacheTest {
169
169
}
170
170
171
171
@Test
172
- fun `should preserve redirect URI during 401 response ` () {
172
+ fun `should invalidate cookie after reading redirect URI ` () {
173
173
val webExchange = mockk<ServerWebExchange > {
174
174
every { request.uri.host } returns " localhost"
175
175
every { attributes[OrganizationWebFilter .ORGANIZATION_CACHE_KEY ] } returns Organization (ORG_ID )
176
- every { response.statusCode } returns HttpStatus .UNAUTHORIZED
177
176
}
178
177
179
178
val redirect = " /requestURI?query=true"
@@ -182,36 +181,12 @@ internal class CookieServerRequestCacheTest {
182
181
HttpCookie (SPRING_REDIRECT_URI , cookieSerializer.encodeCookieBlocking(webExchange, redirect))
183
182
)
184
183
)
185
- exchange.response.statusCode = HttpStatus .UNAUTHORIZED
186
184
187
- val request = cache.removeMatchingRequest(exchange).block()
188
-
189
- // Verify the cookie was not invalidated
190
- verify(exactly = 0 ) { cookieService.invalidateCookie(exchange, SPRING_REDIRECT_URI ) }
191
- expectThat(request).isNotNull()
192
- }
193
-
194
- @Test
195
- fun `should clear redirect URI for non-401 response` () {
196
- val webExchange = mockk<ServerWebExchange > {
197
- every { request.uri.host } returns " localhost"
198
- every { attributes[OrganizationWebFilter .ORGANIZATION_CACHE_KEY ] } returns Organization (ORG_ID )
199
- every { response.statusCode } returns HttpStatus .FOUND
200
- }
201
-
202
- val redirect = " /requestURI?query=true"
203
- val exchange = MockServerWebExchange .from(
204
- MockServerHttpRequest .get(" http://localhost/" ).cookie(
205
- HttpCookie (SPRING_REDIRECT_URI , cookieSerializer.encodeCookieBlocking(webExchange, redirect))
206
- )
207
- )
208
- exchange.response.statusCode = HttpStatus .FOUND
185
+ val uri = cache.getRedirectUri(exchange).block()
209
186
210
- val request = cache.removeMatchingRequest(exchange).block( )
187
+ expectThat(uri).isEqualTo( URI .create(redirect) )
211
188
212
- // Verify the cookie was invalidated
213
189
verify(exactly = 1 ) { cookieService.invalidateCookie(exchange, SPRING_REDIRECT_URI ) }
214
- expectThat(request).isNotNull()
215
190
}
216
191
217
192
companion object {
0 commit comments