Updated tests and README for RFC Fixes

This commit is contained in:
Andrew Wiik 2020-01-16 00:56:41 -05:00
parent 9624da5e59
commit 92cac1ecbd
12 changed files with 123 additions and 123 deletions

View file

@ -9,28 +9,28 @@ TEST (DecodeVerifyExp, BeforeExpiryTest)
{
using namespace jwt::params;
jwt::jwt_object obj{algorithm("hs256"), secret("secret")};
jwt::jwt_object obj{algorithm("HS256"), secret("secret")};
obj.add_claim("iss", "arun.muralidharan")
.add_claim("exp", std::chrono::system_clock::now() + std::chrono::seconds{10})
;
auto enc_str = obj.signature();
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), secret("secret"), verify(true));
auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), secret("secret"), verify(true));
}
TEST (DecodeVerifyExp, AfterExpiryTest)
{
using namespace jwt::params;
jwt::jwt_object obj{algorithm("hs256"), secret("secret")};
jwt::jwt_object obj{algorithm("HS256"), secret("secret")};
obj.add_claim("iss", "arun.muralidharan")
.add_claim("exp", std::chrono::system_clock::now() - std::chrono::seconds{1})
;
auto enc_str = obj.signature();
EXPECT_THROW (jwt::decode(enc_str, algorithms({"hs256"}), secret("secret"), verify(true)),
EXPECT_THROW (jwt::decode(enc_str, algorithms({"HS256"}), secret("secret"), verify(true)),
jwt::TokenExpiredError);
}
@ -39,13 +39,13 @@ TEST (DecodeVerifyExp, AfterExpiryWithLeeway)
{
using namespace jwt::params;
jwt::jwt_object obj{algorithm("hs256"), secret("secret")};
jwt::jwt_object obj{algorithm("HS256"), secret("secret")};
obj.add_claim("iss", "arun.muralidharan")
.add_claim("exp", std::chrono::system_clock::now() - std::chrono::seconds{1})
;
auto enc_str = obj.signature();
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), secret("secret"), verify(true), leeway(2));
auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), secret("secret"), verify(true), leeway(2));
(void)dec_obj;
}
@ -53,14 +53,14 @@ TEST (DecodeVerifyExp, ValidIssuerTest)
{
using namespace jwt::params;
jwt::jwt_object obj{algorithm("hs256"), secret("secret")};
jwt::jwt_object obj{algorithm("HS256"), secret("secret")};
obj.add_claim("iss", "arun.muralidharan")
.add_claim("sub", "test")
;
auto enc_str = obj.signature();
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), secret("secret"), issuer("arun.muralidharan"));
auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), secret("secret"), issuer("arun.muralidharan"));
(void)dec_obj;
}
@ -68,10 +68,10 @@ TEST (DecodeVerifyExp, InvalidIssuerTest_1)
{
using namespace jwt::params;
jwt::jwt_object obj{algorithm("hs256"), secret("secret"), payload({{"sub", "test"}})};
jwt::jwt_object obj{algorithm("HS256"), secret("secret"), payload({{"sub", "test"}})};
auto enc_str = obj.signature();
EXPECT_THROW (jwt::decode(enc_str, algorithms({"hs256"}), secret("secret"), issuer("arun.muralidharan")),
EXPECT_THROW (jwt::decode(enc_str, algorithms({"HS256"}), secret("secret"), issuer("arun.muralidharan")),
jwt::InvalidIssuerError);
}
@ -80,12 +80,12 @@ TEST (DecodeVerifyExp, InvalidIssuerTest_2)
{
using namespace jwt::params;
jwt::jwt_object obj{algorithm("hs256"), secret("secret"), payload({{"sub", "test"}})};
jwt::jwt_object obj{algorithm("HS256"), secret("secret"), payload({{"sub", "test"}})};
obj.add_claim("iss", "arun.muralidharan");
auto enc_str = obj.signature();
EXPECT_THROW (jwt::decode(enc_str, algorithms({"hs256"}), secret("secret"), issuer("arun.murali")),
EXPECT_THROW (jwt::decode(enc_str, algorithms({"HS256"}), secret("secret"), issuer("arun.murali")),
jwt::InvalidIssuerError);
}
@ -93,12 +93,12 @@ TEST (DecodeVerifyExp, NotImmatureSignatureTest)
{
using namespace jwt::params;
jwt::jwt_object obj{algorithm("hs256"), secret("secret"), payload({{"sub", "test"}})};
jwt::jwt_object obj{algorithm("HS256"), secret("secret"), payload({{"sub", "test"}})};
obj.add_claim(jwt::registered_claims::not_before, std::chrono::system_clock::now() - std::chrono::seconds{10});
auto enc_str = obj.signature();
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), secret("secret"));
auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), secret("secret"));
(void)dec_obj;
}
@ -106,12 +106,12 @@ TEST (DecodeVerifyExp, ImmatureSignatureTest)
{
using namespace jwt::params;
jwt::jwt_object obj{algorithm("hs256"), secret("secret"), payload({{"sub", "test"}})};
jwt::jwt_object obj{algorithm("HS256"), secret("secret"), payload({{"sub", "test"}})};
obj.add_claim(jwt::registered_claims::not_before, std::chrono::system_clock::now() + std::chrono::seconds{10});
auto enc_str = obj.signature();
EXPECT_THROW (jwt::decode(enc_str, algorithms({"hs256"}), secret("secret")),
EXPECT_THROW (jwt::decode(enc_str, algorithms({"HS256"}), secret("secret")),
jwt::ImmatureSignatureError);
}
@ -119,12 +119,12 @@ TEST (DecodeVerifyExp, ImmatureSignatureTestWithLeeway)
{
using namespace jwt::params;
jwt::jwt_object obj{algorithm("hs256"), secret("secret"), payload({{"sub", "test"}})};
jwt::jwt_object obj{algorithm("HS256"), secret("secret"), payload({{"sub", "test"}})};
obj.add_claim(jwt::registered_claims::not_before, std::chrono::system_clock::now() + std::chrono::seconds{10});
auto enc_str = obj.signature();
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), secret("secret"), leeway(10));
auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), secret("secret"), leeway(10));
(void)dec_obj;
}
@ -132,11 +132,11 @@ TEST (DecodeVerifyExp, InvalidAudienceTest)
{
using namespace jwt::params;
jwt::jwt_object obj{algorithm("hs256"), secret("secret"), payload({{"sub", "test"}, {"aud", "www"}})};
jwt::jwt_object obj{algorithm("HS256"), secret("secret"), payload({{"sub", "test"}, {"aud", "www"}})};
auto enc_str = obj.signature();
EXPECT_THROW (jwt::decode(enc_str, algorithms({"hs256"}), secret("secret"), aud("ww")),
EXPECT_THROW (jwt::decode(enc_str, algorithms({"HS256"}), secret("secret"), aud("ww")),
jwt::InvalidAudienceError);
}
@ -147,7 +147,7 @@ TEST (DecodeVerifyExp, InvalidSignatureTest)
const char* inv_enc_str =
"eyJhbGciOiJOT05FIiwidHlwIjoiSldUIn0.eyJhdWQiOiJyaWZ0LmlvIiwiZXhwIjoxNTEzODYzMzcxLCJzdWIiOiJub3RoaW5nIG11Y2gifQ";
EXPECT_THROW (jwt::decode(inv_enc_str, algorithms({"none", "hs256"})),
EXPECT_THROW (jwt::decode(inv_enc_str, algorithms({"none", "HS256"})),
jwt::SignatureFormatError);
}
@ -160,7 +160,7 @@ TEST (DecodeVerifyExp, KeyNotPresentTest)
"eyJpYXQiOjE1MTM4NjIzNzEsImlkIjoiYS1iLWMtZC1lLWYtMS0yLTMiLCJpc3MiOiJhcnVuLm11cmFsaWRoYXJhbiIsInN1YiI6ImFkbWluIn0."
"jk7bRQKTLvs1RcuvMc2B_rt6WBYPoVPirYi_QRBPiuk";
EXPECT_THROW (jwt::decode(enc_str, algorithms({"none", "hs256"}), verify(true)),
EXPECT_THROW (jwt::decode(enc_str, algorithms({"none", "HS256"}), verify(true)),
jwt::KeyNotPresentError);
}
@ -168,11 +168,11 @@ TEST (DecodeVerifyExp, InvalidSubjectTest)
{
using namespace jwt::params;
jwt::jwt_object obj{algorithm("hs256"), secret("secret"), payload({{"sub", "test"}, {"aud", "www"}})};
jwt::jwt_object obj{algorithm("HS256"), secret("secret"), payload({{"sub", "test"}, {"aud", "www"}})};
auto enc_str = obj.signature();
EXPECT_THROW (jwt::decode(enc_str, algorithms({"hs256"}), secret("secret"), sub("TEST")),
EXPECT_THROW (jwt::decode(enc_str, algorithms({"HS256"}), secret("secret"), sub("TEST")),
jwt::InvalidSubjectError);
}