From 92ddc6781756c6b6e9c459278a2ef3f6ac6e7b3c Mon Sep 17 00:00:00 2001 From: Christopher McArthur Date: Sat, 28 Mar 2020 17:19:15 -0400 Subject: [PATCH 1/2] Adding SetObject to ClaimTests --- tests/ClaimTest.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/ClaimTest.cpp b/tests/ClaimTest.cpp index f4f3f04e5..b9051bf22 100644 --- a/tests/ClaimTest.cpp +++ b/tests/ClaimTest.cpp @@ -44,6 +44,18 @@ TEST(ClaimTest, SetArray) { ASSERT_EQ(token, "eyJhbGciOiJub25lIn0.eyJ0ZXN0IjpbMTAwLDIwLDEwXX0."); } +TEST(ClaimTest, SetObject) { + std::istringstream iss{"{\"api-x\": [1]}"}; + jwt::claim object; + iss >> object; + ASSERT_EQ(object.get_type() , jwt::claim::type::object); + + auto token = jwt::create() + .set_payload_claim("namespace", object) + .sign(jwt::algorithm::hs256("test")); + ASSERT_EQ(token, "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.IgUI50puuP1CsyvFYiYJmUdajzUoFYdKl5TnTIIy5EA"); +} + TEST(ClaimTest, SetAlgorithm) { auto token = jwt::create() .set_algorithm("test") From 6793369939d98c3bea959d9bf7486a30dd2f785a Mon Sep 17 00:00:00 2001 From: Chris Mc Date: Sat, 28 Mar 2020 17:30:09 -0400 Subject: [PATCH 2/2] token expected as per jwt.io https://jwt.io/#debugger-io?token=eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA --- tests/ClaimTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ClaimTest.cpp b/tests/ClaimTest.cpp index b9051bf22..cb5856416 100644 --- a/tests/ClaimTest.cpp +++ b/tests/ClaimTest.cpp @@ -53,7 +53,7 @@ TEST(ClaimTest, SetObject) { auto token = jwt::create() .set_payload_claim("namespace", object) .sign(jwt::algorithm::hs256("test")); - ASSERT_EQ(token, "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.IgUI50puuP1CsyvFYiYJmUdajzUoFYdKl5TnTIIy5EA"); + ASSERT_EQ(token, "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA"); } TEST(ClaimTest, SetAlgorithm) {