* fix(auth): await cookie scope hydration before ticket mint and request loading (#961) * refactor(auth): scope latch activation to active store hydration --------- Co-authored-by: M57 <hy4ri@users.noreply.github.com>
This commit is contained in:
1 parent
913ae1275d
commit
764cb3455f
3 files changed
+66
-9
No files matched your search
@@ -1,5 +1,9 @@
|
||||
package com.m57.hermescontrol.data.remote
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import okhttp3.Cookie
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
@@ -239,4 +243,39 @@ class PersistentCookieJarTest {
|
||||
|
||||
assertEquals("secure-value", jar.getSessionCookieValue())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun loadForRequest_awaitsAsyncScopeHydration() =
|
||||
runTest {
|
||||
val fakeStore = FakeEncryptedCookieStore()
|
||||
fakeStore.save("cold-server", listOf(sessionCookie("dash.local", "cold-cookie-xyz")))
|
||||
|
||||
val store =
|
||||
object : CookieStore by fakeStore {
|
||||
override suspend fun load(serverId: String): List<Cookie> {
|
||||
delay(50)
|
||||
return fakeStore.load(serverId)
|
||||
}
|
||||
}
|
||||
|
||||
val testScope = CoroutineScope(Dispatchers.IO)
|
||||
val jar =
|
||||
PersistentCookieJar(
|
||||
store = store,
|
||||
storeScope = testScope,
|
||||
initialServerId = "cold-server",
|
||||
)
|
||||
|
||||
val job =
|
||||
testScope.launch {
|
||||
jar.useStore("cold-server")
|
||||
}
|
||||
|
||||
delay(10)
|
||||
|
||||
val loaded = jar.loadForRequest("http://dash.local/api/status".toHttpUrl())
|
||||
assertEquals(1, loaded.size)
|
||||
assertEquals("cold-cookie-xyz", loaded[0].value)
|
||||
job.join()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user