diff --git a/ballerina/tests/jwt_validator_test.bal b/ballerina/tests/jwt_validator_test.bal index e90306c6..c6bc9d3b 100644 --- a/ballerina/tests/jwt_validator_test.bal +++ b/ballerina/tests/jwt_validator_test.bal @@ -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? { @@ -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 = {