mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-14 16:58:34 +00:00
Added exception handling and test for key/secret not present
This commit is contained in:
parent
99f3c1db86
commit
a5e18cc4f4
4 changed files with 42 additions and 12 deletions
|
@ -99,6 +99,22 @@ TEST (DecodeTest, DecodeHS256)
|
|||
EXPECT_FALSE (obj.payload().has_claim_with_value(jwt::registered_claims::issued_at, 1513862372));
|
||||
}
|
||||
|
||||
TEST (DecodeTest, SecretKeyNotPassed)
|
||||
{
|
||||
using namespace jwt::params;
|
||||
|
||||
const char* enc_str =
|
||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9."
|
||||
"eyJpYXQiOjE1MTM4NjIzNzEsImlkIjoiYS1iLWMtZC1lLWYtMS0yLTMiLCJpc3MiOiJhcnVuLm11cmFsaWRoYXJhbiIsInN1YiI6ImFkbWluIn0."
|
||||
"jk7bRQKTLvs1RcuvMc2B_rt6WBYPoVPirYi_QRBPiuk";
|
||||
|
||||
std::error_code ec;
|
||||
auto obj = jwt::decode(enc_str, algorithms({"none", "hs256"}), ec, verify(false));
|
||||
|
||||
ASSERT_TRUE (ec);
|
||||
EXPECT_EQ (ec.value(), static_cast<int>(jwt::DecodeErrc::KeyNotPresent));
|
||||
}
|
||||
|
||||
TEST (DecodeTest, DecodeHS384)
|
||||
{
|
||||
using namespace jwt::params;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue