Skip to content

Commit

Permalink
Add JWT validator test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeshLK committed May 30, 2024
1 parent 0a415bf commit 4ff47fd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ballerina/tests/jwt_validator_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// NOTE: All the tokens/credentials used in this test are dummy tokens/credentials and used only for testing purposes.

import ballerina/test;
import ballerina/io;
import ballerina/crypto;

@test:Config {}
isolated function testValidateJwtWithAudAsArray() returns Error? {
Expand Down Expand Up @@ -693,6 +695,22 @@ isolated function testValidateJwtSignatureWithPublicCert() returns Error? {
test:assertEquals(result?.iss, "wso2");
}

@test:Config {}
isolated function testValidateJwtSignatureWithCryptoPublicKey() returns io:Error|crypto:Error|Error? {
byte[] pubicCertContent = check io:fileReadBytes(PUBLIC_CERT_PATH);
crypto:PublicKey publicKey = check crypto:decodeRsaPublicKeyFromContent(pubicCertContent);
ValidatorConfig validatorConfig = {
issuer: "wso2",
audience: ["ballerina", "ballerinaSamples"],
clockSkew: 60,
signatureConfig: {
certFile: publicKey
}
};
Payload result = check validate(JWT1, validatorConfig);
test:assertEquals(result?.iss, "wso2");
}

@test:Config {}
isolated function testValidateJwtSignatureWithInvalidPublicCert() {
ValidatorConfig validatorConfig = {
Expand Down

0 comments on commit 4ff47fd

Please sign in to comment.