mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-24 13:39:15 +00:00
Change signature for has_claim_with_value API
This commit is contained in:
parent
c62a9498d9
commit
d7e4add937
4 changed files with 47 additions and 4 deletions
tests
|
@ -64,6 +64,41 @@ TEST (DecodeTest, DecodeInvalidHeader)
|
|||
|
||||
}
|
||||
|
||||
TEST (DecodeTest, DecodeInvalidPayload)
|
||||
{
|
||||
using namespace jwt::params;
|
||||
|
||||
const char* enc_str =
|
||||
"eyJhbGciOiJOT05FIiwidHlwIjoiSldUIn0.eyfhuWcikiJyaWZ0LmlvIiwiZXhwIsexNTEzODYzMzcxLCJzdWIiOiJub3RoaW5nIG11Y2gifQ.";
|
||||
|
||||
std::error_code ec;
|
||||
auto obj = jwt::decode(enc_str, "", algorithms({"none"}), ec, verify(true));
|
||||
ASSERT_TRUE (ec);
|
||||
|
||||
EXPECT_EQ (ec.value(), static_cast<int>(jwt::DecodeErrc::JsonParseError));
|
||||
}
|
||||
|
||||
TEST (DecodeTest, DecodeHS256)
|
||||
{
|
||||
using namespace jwt::params;
|
||||
|
||||
const char* enc_str =
|
||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9."
|
||||
"eyJpYXQiOjE1MTM4NjIzNzEsImlkIjoiYS1iLWMtZC1lLWYtMS0yLTMiLCJpc3MiOiJhcnVuLm11cmFsaWRoYXJhbiIsInN1YiI6ImFkbWluIn0."
|
||||
"jk7bRQKTLvs1RcuvMc2B_rt6WBYPoVPirYi_QRBPiuk";
|
||||
|
||||
std::error_code ec;
|
||||
auto obj = jwt::decode(enc_str, "secret", algorithms({"none", "hs256"}), ec, verify(false));
|
||||
ASSERT_FALSE (ec);
|
||||
|
||||
EXPECT_TRUE (obj.has_claim("iss"));
|
||||
EXPECT_TRUE (obj.payload().has_claim_with_value("iss", "arun.muralidharan"));
|
||||
EXPECT_TRUE (obj.has_claim("IAT"));
|
||||
EXPECT_TRUE (obj.payload().has_claim_with_value(jwt::registered_claims::issued_at, 1513862371));
|
||||
|
||||
EXPECT_FALSE (obj.payload().has_claim_with_value(jwt::registered_claims::issued_at, 1513862372));
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue