File tree 2 files changed +26
-0
lines changed
main/kotlin/no/nav/security/mock/oauth2/token
test/kotlin/no/nav/security/mock/oauth2/token
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import com.nimbusds.jose.JWSAlgorithm
5
5
import com.nimbusds.jose.JWSHeader
6
6
import com.nimbusds.jose.crypto.RSASSASigner
7
7
import com.nimbusds.jose.jwk.JWKSet
8
+ import com.nimbusds.jose.jwk.KeyUse
8
9
import com.nimbusds.jose.jwk.RSAKey
9
10
import com.nimbusds.jwt.JWTClaimsSet
10
11
import com.nimbusds.jwt.SignedJWT
@@ -124,6 +125,7 @@ class OAuth2TokenProvider {
124
125
private fun createRSAKey (keyID : String , keyPair : KeyPair ) =
125
126
RSAKey .Builder (keyPair.public as RSAPublicKey )
126
127
.privateKey(keyPair.private as RSAPrivateKey )
128
+ .keyUse(KeyUse .SIGNATURE )
127
129
.keyID(keyID)
128
130
.build()
129
131
}
Original file line number Diff line number Diff line change
1
+ package no.nav.security.mock.oauth2.token
2
+
3
+ import com.nimbusds.jose.jwk.KeyType
4
+ import com.nimbusds.jose.jwk.KeyUse
5
+ import io.kotest.matchers.shouldBe
6
+ import io.kotest.matchers.shouldNotBe
7
+ import org.junit.jupiter.api.Test
8
+
9
+ internal class OAuth2TokenProviderTest {
10
+ private val jwkSet = OAuth2TokenProvider ().publicJwkSet()
11
+
12
+ @Test
13
+ fun `public jwks returns public part of JWKs` () =
14
+ jwkSet.keys.any { it.isPrivate } shouldNotBe true
15
+
16
+ @Test
17
+ fun `all keys in public jwks should contain kty, use and kid` () {
18
+ jwkSet.keys.forEach {
19
+ it.keyID shouldNotBe null
20
+ it.keyType shouldBe KeyType .RSA
21
+ it.keyUse shouldBe KeyUse .SIGNATURE
22
+ }
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments