Skip to content

Commit

Permalink
add code verifier tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-tennert committed May 5, 2024
1 parent 5a31088 commit 70fd56a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ interface CodeVerifierCache {
/**
* A [CodeVerifierCache] that uses the [AtomicRef] API.
*/
class MemoryCodeVerifierCache: CodeVerifierCache {
class MemoryCodeVerifierCache(codeVerifier: String? = null): CodeVerifierCache {

private var codeVerifier by atomic<String?>(null)
private var codeVerifier by atomic(codeVerifier)

override suspend fun saveCodeVerifier(codeVerifier: String) {
this.codeVerifier = codeVerifier
Expand Down
23 changes: 23 additions & 0 deletions GoTrue/src/commonTest/kotlin/CodeVerifierCacheTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import io.github.jan.supabase.gotrue.MemoryCodeVerifierCache
import kotlinx.coroutines.test.runTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull

class CodeVerifierCacheTest {

@Test
fun testMemoryCodeVerifierCache() {
runTest {
val codeVerifier = "codeVerifier"
val codeVerifierCache = MemoryCodeVerifierCache(codeVerifier)
assertEquals(codeVerifier, codeVerifierCache.loadCodeVerifier())
val newCodeVerifier = "newCodeVerifier"
codeVerifierCache.saveCodeVerifier(newCodeVerifier)
assertEquals(newCodeVerifier, codeVerifierCache.loadCodeVerifier())
codeVerifierCache.deleteCodeVerifier()
assertNull(codeVerifierCache.loadCodeVerifier())
}
}

}

0 comments on commit 70fd56a

Please sign in to comment.