-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
79 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
modules/services/src/commonTest/kotlin/com.sphereon.oid.fed.services/JwkServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.sphereon.oid.fed.services | ||
|
||
import com.sphereon.oid.fed.openapi.models.Account | ||
import com.sphereon.oid.fed.openapi.models.JwkWithPrivateKey | ||
import com.sphereon.oid.fed.persistence.Persistence | ||
import com.sphereon.oid.fed.persistence.models.JwkQueries | ||
import io.mockk.* | ||
import java.time.LocalDateTime | ||
import kotlin.test.* | ||
|
||
class JwkServiceTest { | ||
private lateinit var jwkService: JwkService | ||
private lateinit var kmsClient: KmsClient | ||
private lateinit var jwkQueries: JwkQueries | ||
|
||
companion object { | ||
private val FIXED_TIMESTAMP: LocalDateTime = LocalDateTime.parse("2025-01-13T12:00:00") | ||
} | ||
|
||
@BeforeTest | ||
fun setup() { | ||
kmsClient = mockk<KmsClient>(relaxed = true) | ||
jwkQueries = mockk<JwkQueries>(relaxed = true) | ||
mockkObject(Persistence) | ||
every { Persistence.jwkQueries } returns jwkQueries | ||
jwkService = JwkService(kmsClient) | ||
} | ||
|
||
@AfterTest | ||
fun cleanup() { | ||
clearAllMocks() | ||
unmockkObject(Persistence) | ||
} | ||
|
||
@Test | ||
fun testCreateKey() { | ||
val account = Account( | ||
id = 1, | ||
username = "testUser", | ||
identifier = "test-identifier" | ||
) | ||
|
||
val expectedJwk = JwkWithPrivateKey( | ||
kty = "EC", | ||
crv = "P-256", | ||
x = "example-x", | ||
y = "example-y", | ||
kid = "test-kid-124", | ||
alg = "ES256", | ||
use = "sig" | ||
) | ||
|
||
every { kmsClient.generateKeyPair() } returns expectedJwk | ||
|
||
val result = jwkService.createKey(account) | ||
|
||
assertNotNull(result) | ||
assertEquals(expectedJwk.kid, result.kid) | ||
assertEquals(expectedJwk.use, result.use) | ||
assertEquals(expectedJwk.alg, result.alg) | ||
|
||
verify { kmsClient.generateKeyPair() } | ||
verify { jwkQueries.create(any(), any(), any()) } | ||
} | ||
} |