Skip to content

Commit

Permalink
fix: Fixed failing test and null pointer exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoe Maas committed Jul 23, 2024
1 parent 859d788 commit 3fb5bb6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,10 @@ actual fun sign(
.keyID(UUID.randomUUID().toString())
.generate()

val kid = rsaJWK?.keyID

val header: JWSHeader?
if (opts["jwtHeader"] != null) {
header = JWSHeader.parse(opts["jwtHeader"] as String?)
} else {
header = JWSHeader.Builder(JWSAlgorithm.RS256).keyID(kid).build()
}

val header = opts["jwtHeader"]?.let {
JWSHeader.parse(it as String?)
} ?: JWSHeader.Builder(JWSAlgorithm.RS256).keyID(rsaJWK.keyID).build()

val signer: JWSSigner = RSASSASigner(rsaJWK)

val claimsSet = JWTClaimsSet.parse(payload)
Expand All @@ -54,6 +49,6 @@ actual fun verify(
val verified = signedJWT.verify(verifier)
return verified
} catch (e: Exception) {
throw Exception("Couldn't verify the JWT Signature: ${e.message}")
throw Exception("Couldn't verify the JWT Signature: ${e.message}", e)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class JoseJwtTest {

@Test
fun signTest() {
val signature = sign("{ \"iss\": \"test\" }", mutableMapOf())
val signature = sign("{ \"iss\": \"test\" }", emptyMap())
assertTrue { signature.startsWith("ey") }
}

Expand Down

0 comments on commit 3fb5bb6

Please sign in to comment.