From 402e56840652cc9459d154144d8509a635bfd84c Mon Sep 17 00:00:00 2001 From: xuanswe <24372782+xuanswe@users.noreply.github.com> Date: Wed, 29 May 2024 15:38:26 +0200 Subject: [PATCH] #691 `OAuth2TokenProvider` should allow dynamic `systemTime` --- .../mock/oauth2/token/OAuth2TokenProvider.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/no/nav/security/mock/oauth2/token/OAuth2TokenProvider.kt b/src/main/kotlin/no/nav/security/mock/oauth2/token/OAuth2TokenProvider.kt index a8f12daf..b3a67390 100644 --- a/src/main/kotlin/no/nav/security/mock/oauth2/token/OAuth2TokenProvider.kt +++ b/src/main/kotlin/no/nav/security/mock/oauth2/token/OAuth2TokenProvider.kt @@ -19,12 +19,23 @@ import java.time.Instant import java.util.Date import java.util.UUID +typealias TimeProvider = () -> Instant? + class OAuth2TokenProvider @JvmOverloads constructor( private val keyProvider: KeyProvider = KeyProvider(), - val systemTime: Instant? = null, + private val timeProvider: TimeProvider, ) { + val systemTime + get() = timeProvider() + + @JvmOverloads + constructor( + keyProvider: KeyProvider = KeyProvider(), + systemTime: Instant? = null, + ) : this(keyProvider, { systemTime }) + @JvmOverloads fun publicJwkSet(issuerId: String = "default"): JWKSet { return JWKSet(keyProvider.signingKey(issuerId)).toPublicJWKSet()