| 525 | } |
| 526 | |
| 527 | TEST(JwtUtilTest, LoadJwksFile) { |
| 528 | // Load JWKS from file. |
| 529 | TempTestDataFile jwks_file(Substitute(jwks_rsa_file_format, kid_1, "RS256", |
| 530 | rsa_pub_key_jwk_n, rsa_pub_key_jwk_e, kid_2, "RS256", rsa_invalid_pub_key_jwk_n, |
| 531 | rsa_pub_key_jwk_e)); |
| 532 | JWTHelper jwt_helper; |
| 533 | Status status = jwt_helper.Init(jwks_file.Filename()); |
| 534 | EXPECT_OK(status); |
| 535 | JWKSSnapshotPtr jwks = jwt_helper.GetJWKS(); |
| 536 | ASSERT_FALSE(jwks->IsEmpty()); |
| 537 | ASSERT_EQ(2, jwks->GetRSAPublicKeyNum()); |
| 538 | |
| 539 | const JWTPublicKey* key1 = jwks->LookupRSAPublicKey(kid_1); |
| 540 | ASSERT_TRUE(key1 != nullptr); |
| 541 | ASSERT_EQ("rs256", key1->get_algorithm()); |
| 542 | ASSERT_EQ(rsa_pub_key_pem, key1->get_key()); |
| 543 | |
| 544 | std::string non_existing_kid("public:c424b67b-fe28-45d7-b015-f79da5-xxxxx"); |
| 545 | const JWTPublicKey* key3 = jwks->LookupRSAPublicKey(non_existing_kid); |
| 546 | ASSERT_FALSE(key3 != nullptr); |
| 547 | } |
| 548 | |
| 549 | TEST(JwtUtilTest, LoadInvalidJwksFiles) { |
| 550 | // JWK without kid. |
nothing calls this directly
no test coverage detected