adding verification test

This commit is contained in:
Christopher McArthur
2020-05-20 21:24:46 -04:00
parent 8ba9dc1b96
commit 474a870889
2 changed files with 17 additions and 1 deletions

View File

@@ -1582,7 +1582,12 @@ namespace jwt {
}
}
else if (c.get_type() == json::type::object) {
if( c.to_json().serialize() != jc.to_json().serialize())
auto serialize = [](const value_type& value) {
std::ostringstream oss;
oss << value;
return oss.str();
};
if( serialize(c.to_json()) != serialize(jc.to_json()))
throw token_verification_exception("claim " + key + " does not match expected");
}
else if (c.get_type() == json::type::string) {

View File

@@ -144,3 +144,14 @@ TEST(NholmannTest, SetObject) {
.sign(jwt::algorithm::hs256("test"));
ASSERT_EQ(token, "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
}
TEST(NholmannTest, VerifyTokenHS256) {
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
auto verify = jwt::verify<jwt::default_clock, JWT_NHOLMANN_CLAIM_TPL>({})
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
.with_issuer("auth0");
auto decoded_token = jwt::decode<JWT_NHOLMANN_CLAIM_TPL>(token);
verify.verify(decoded_token);
}