@@ -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(),
@@ -100,22 +100,6 @@ internal class CookieServerRequestCacheTest {
100
100
verify(exactly = 1 ) { cookieService.createCookie(exchange, SPRING_REDIRECT_URI , any()) }
101
101
}
102
102
103
- @Test
104
- fun `should remove redirect URI from cookies` () {
105
- val request = MockServerHttpRequest .get(" http://localhost/requestURI" ).queryParam(" query" , " true" ).build()
106
- val exchange = MockServerWebExchange .from(request)
107
- every { cookieService.invalidateCookie(any(), any()) } returns Unit
108
-
109
- val matchingRequest = cache.removeMatchingRequest(exchange)
110
-
111
- expectThat(matchingRequest.blockOptional()) {
112
- get { isPresent }.isTrue()
113
- get { get() }.isEqualTo(request)
114
- }
115
-
116
- verify(exactly = 1 ) { cookieService.invalidateCookie(exchange, SPRING_REDIRECT_URI ) }
117
- }
118
-
119
103
@Test
120
104
fun `should not load redirect URI when nothing is stored in cookies` () {
121
105
val exchange = MockServerWebExchange .from(
@@ -169,11 +153,10 @@ internal class CookieServerRequestCacheTest {
169
153
}
170
154
171
155
@Test
172
- fun `should preserve redirect URI during 401 response ` () {
156
+ fun `should invalidate cookie after reading redirect URI ` () {
173
157
val webExchange = mockk<ServerWebExchange > {
174
158
every { request.uri.host } returns " localhost"
175
159
every { attributes[OrganizationWebFilter .ORGANIZATION_CACHE_KEY ] } returns Organization (ORG_ID )
176
- every { response.statusCode } returns HttpStatus .UNAUTHORIZED
177
160
}
178
161
179
162
val redirect = " /requestURI?query=true"
@@ -182,36 +165,12 @@ internal class CookieServerRequestCacheTest {
182
165
HttpCookie (SPRING_REDIRECT_URI , cookieSerializer.encodeCookieBlocking(webExchange, redirect))
183
166
)
184
167
)
185
- exchange.response.statusCode = HttpStatus .UNAUTHORIZED
186
168
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
169
+ val uri = cache.getRedirectUri(exchange).block()
209
170
210
- val request = cache.removeMatchingRequest(exchange).block( )
171
+ expectThat(uri).isEqualTo( URI .create(redirect) )
211
172
212
- // Verify the cookie was invalidated
213
173
verify(exactly = 1 ) { cookieService.invalidateCookie(exchange, SPRING_REDIRECT_URI ) }
214
- expectThat(request).isNotNull()
215
174
}
216
175
217
176
companion object {
0 commit comments