Skip to content

Commit

Permalink
Add token format test from #341 (#343)
Browse files Browse the repository at this point in the history
* Update TokenFormatTest.cpp

* Update TokenFormatTest.cpp

* Update TokenFormatTest.cpp

* cleanup test for issue

* clang-format
  • Loading branch information
prince-chrismc authored Apr 20, 2024
1 parent d53e013 commit e9cd684
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/TokenFormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,22 @@ TEST(TokenFormatTest, InvalidChar) {
TEST(TokenFormatTest, InvalidJSON) {
ASSERT_THROW(jwt::decode("YXsiYWxnIjoibm9uZSIsInR5cCI6IkpXUyJ9YQ.eyJpc3MiOiJhdXRoMCJ9."), std::runtime_error);
}

#include "jwt-cpp/traits/nlohmann-json/traits.h"

TEST(TokenFormatTest, GitHubIssue341) {
std::string token =
"eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJjYXV0aDAiLCJleHAiOjE3MTMzODgxNjgsInN1YiI6InRlc3RfdXNlciJ9."
"dlAk0mSWk1Clzfi1PMq7Omxun3EyEqh-AAu-fTkpabA67ZKenawAQhZO8glY93flukpJCqHLVtukaes6ZSOjGw";
auto decoded = jwt::decoded_jwt<jwt::traits::nlohmann_json>(token);

ASSERT_TRUE(decoded.has_algorithm());
ASSERT_TRUE(decoded.has_type());
ASSERT_TRUE(decoded.has_issuer());
ASSERT_TRUE(decoded.has_subject());

ASSERT_EQ("ES256", decoded.get_algorithm());
ASSERT_EQ("JWT", decoded.get_type());
ASSERT_EQ("cauth0", decoded.get_issuer());
ASSERT_EQ("test_user", decoded.get_subject());
}

0 comments on commit e9cd684

Please sign in to comment.