From 4c0fcb3786fe32a53cb3e0d938937ae0cc93ba45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vandendaelen?= Date: Sat, 31 Aug 2024 11:32:10 +0200 Subject: [PATCH] fix: Fixed not implemented guard for JWT auth --- src/main/kotlin/be/vandeas/logic/impl/AuthLogicImpl.kt | 7 ++++--- src/test/kotlin/be/vandeas/v2/ApplicationTest.kt | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/be/vandeas/logic/impl/AuthLogicImpl.kt b/src/main/kotlin/be/vandeas/logic/impl/AuthLogicImpl.kt index 51f660f..4d0238c 100644 --- a/src/main/kotlin/be/vandeas/logic/impl/AuthLogicImpl.kt +++ b/src/main/kotlin/be/vandeas/logic/impl/AuthLogicImpl.kt @@ -42,9 +42,10 @@ class AuthLogicImpl( override fun guard(token: String, path: Path, protectedMethod: () -> T): T = validateOneTimeToken(token, path).let { protectedMethod() } - override fun guard(jwt: String, protectedMethod: () -> T): T { - TODO("Not yet implemented") - } + override fun guard(jwt: String, protectedMethod: () -> T): T = + validateJwtToken(jwt).let { + protectedMethod() + } override fun getJwtToken(apiKey: String, duration: Duration): String { if (!validateApiKey(apiKey)) { diff --git a/src/test/kotlin/be/vandeas/v2/ApplicationTest.kt b/src/test/kotlin/be/vandeas/v2/ApplicationTest.kt index a0325f3..81adb84 100644 --- a/src/test/kotlin/be/vandeas/v2/ApplicationTest.kt +++ b/src/test/kotlin/be/vandeas/v2/ApplicationTest.kt @@ -14,6 +14,7 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import java.util.* import kotlin.io.path.toPath +import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals import kotlin.time.Duration @@ -38,6 +39,11 @@ class ApplicationTest { }.body>()["token"] } + @BeforeTest + fun setup() { + // DELETE ALL FILES FROM SCRATCH + } + @Test fun `Should be able to write and read`() { runBlocking {