| 2 | #include <gtest/gtest.h> |
| 3 | |
| 4 | TEST(ClaimTest, AudienceAsString) { |
| 5 | std::string const token = |
| 6 | "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0.WZnM3SIiSRHsbO3O7Z2bmIzTJ4EC32HRBKfLznHhrh4"; |
| 7 | auto decoded = jwt::decode(token); |
| 8 | |
| 9 | ASSERT_TRUE(decoded.has_algorithm()); |
| 10 | ASSERT_TRUE(decoded.has_type()); |
| 11 | ASSERT_FALSE(decoded.has_content_type()); |
| 12 | ASSERT_FALSE(decoded.has_key_id()); |
| 13 | ASSERT_FALSE(decoded.has_issuer()); |
| 14 | ASSERT_FALSE(decoded.has_subject()); |
| 15 | ASSERT_TRUE(decoded.has_audience()); |
| 16 | ASSERT_FALSE(decoded.has_expires_at()); |
| 17 | ASSERT_FALSE(decoded.has_not_before()); |
| 18 | ASSERT_FALSE(decoded.has_issued_at()); |
| 19 | ASSERT_FALSE(decoded.has_id()); |
| 20 | |
| 21 | ASSERT_EQ("HS256", decoded.get_algorithm()); |
| 22 | ASSERT_EQ("JWT", decoded.get_type()); |
| 23 | auto aud = decoded.get_audience(); |
| 24 | ASSERT_EQ(1, aud.size()); |
| 25 | ASSERT_EQ("test", *aud.begin()); |
| 26 | } |
| 27 | |
| 28 | TEST(ClaimTest, SetAudienceAsString) { |
| 29 | auto token = jwt::create().set_type("JWT").set_audience("test").sign(jwt::algorithm::hs256("test")); |
nothing calls this directly
no test coverage detected