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

@ -78,7 +78,7 @@ Few good resources on this material which I found useful are:
std::cout << enc_str << std::endl; std::cout << enc_str << std::endl;
//Decode //Decode
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), secret(key)); auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), secret(key));
std::cout << dec_obj.header() << std::endl; std::cout << dec_obj.header() << std::endl;
std::cout << dec_obj.payload() << std::endl; std::cout << dec_obj.payload() << std::endl;
@ -109,7 +109,7 @@ Few good resources on this material which I found useful are:
int main() { int main() {
using namespace jwt::params; using namespace jwt::params;
jwt::jwt_object obj{algorithm("hs256"), secret("secret"), payload({{"user", "admin"}})}; jwt::jwt_object obj{algorithm("HS256"), secret("secret"), payload({{"user", "admin"}})};
//Use add_claim API to add claim values which are //Use add_claim API to add claim values which are
// _not_ strings. // _not_ strings.
@ -313,17 +313,17 @@ All the parameters are basically a function which returns an instance of a type
- Takes in any type which satifies the <strong>SequenceConcept</strong> (see <code>idetail::meta::is_sequence_concept</code>) - Takes in any type which satifies the <strong>SequenceConcept</strong> (see <code>idetail::meta::is_sequence_concept</code>)
```cpp ```cpp
jwt::decode(algorithms({"none", "hs256", "rs256"}), ...); jwt::decode(algorithms({"none", "HS256", "RS256"}), ...);
OR OR
std::vector<std::string> algs{"none", "hs256", "rs256"}; std::vector<std::string> algs{"none", "HS256", "RS256"};
jwt::decode(algorithms(algs), ...); jwt::decode(algorithms(algs), ...);
``` ```
- <strong>secret</strong> - <strong>secret</strong>
Optional parameter. To be supplied only when the algorithm used is not "NONE". Else would throw/set <code>KeyNotPresentError</code> / <code>KeyNotPresent</code> exception/error. Optional parameter. To be supplied only when the algorithm used is not "none". Else would throw/set <code>KeyNotPresentError</code> / <code>KeyNotPresent</code> exception/error.
- <strong>leeway</strong> - <strong>leeway</strong>
@ -406,7 +406,7 @@ Expiration verification example (uses error_code):
int main() { int main() {
using namespace jwt::params; 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") obj.add_claim("iss", "arun.muralidharan")
.add_claim("exp", std::chrono::system_clock::now() - std::chrono::seconds{1}) .add_claim("exp", std::chrono::system_clock::now() - std::chrono::seconds{1})
; ;
@ -415,7 +415,7 @@ int main() {
auto enc_str = obj.signature(ec); auto enc_str = obj.signature(ec);
assert (!ec); assert (!ec);
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), ec, secret("secret"), verify(true)); auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), ec, secret("secret"), verify(true));
assert (ec); assert (ec);
assert (ec.value() == static_cast<int>(jwt::VerificationErrc::TokenExpired)); assert (ec.value() == static_cast<int>(jwt::VerificationErrc::TokenExpired));
@ -432,7 +432,7 @@ Expiration verification example (uses exception):
int main() { int main() {
using namespace jwt::params; 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") obj.add_claim("iss", "arun.muralidharan")
.add_claim("exp", std::chrono::system_clock::now() - std::chrono::seconds{1}) .add_claim("exp", std::chrono::system_clock::now() - std::chrono::seconds{1})
@ -441,7 +441,7 @@ int main() {
auto enc_str = obj.signature(); auto enc_str = obj.signature();
try { try {
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));
} catch (const jwt::TokenExpiredError& e) { } catch (const jwt::TokenExpiredError& e) {
//Handle Token expired exception here //Handle Token expired exception here
//... //...
@ -472,13 +472,13 @@ Invalid issuer test(uses error_code):
int main() { int main() {
using namespace jwt::params; 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"}})};
std::error_code ec; std::error_code ec;
auto enc_str = obj.signature(ec); auto enc_str = obj.signature(ec);
assert (!ec); assert (!ec);
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), ec, secret("secret"), issuer("arun.muralidharan")); auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), ec, secret("secret"), issuer("arun.muralidharan"));
assert (ec); assert (ec);
assert (ec.value() == static_cast<int>(jwt::VerificationErrc::InvalidIssuer)); assert (ec.value() == static_cast<int>(jwt::VerificationErrc::InvalidIssuer));
@ -588,7 +588,7 @@ There are exception types created for almost all the error codes above.
- KeyNotPresentError - KeyNotPresentError
Thrown if key/secret is not passed in with the decode API if the algorithm used is something other than "NONE". Thrown if key/secret is not passed in with the decode API if the algorithm used is something other than "none".
- VerificationError - VerificationError

View file

@ -6,7 +6,7 @@
int main() { int main() {
using namespace jwt::params; using namespace jwt::params;
jwt::jwt_object obj{algorithm("hs256"), secret("secret"), payload({{"user", "admin"}})}; jwt::jwt_object obj{algorithm("HS256"), secret("secret"), payload({{"user", "admin"}})};
//Use add_claim API to add claim values which are //Use add_claim API to add claim values which are
// _not_ strings. // _not_ strings.

View file

@ -44,7 +44,7 @@ int main() {
auto priv_key = read_from_file(priv_key_path); auto priv_key = read_from_file(priv_key_path);
jwt::jwt_object obj{algorithm("rs256"), secret(priv_key), payload({{"user", "admin"}})}; jwt::jwt_object obj{algorithm("RS256"), secret(priv_key), payload({{"user", "admin"}})};
//Use add_claim API to add claim values which are //Use add_claim API to add claim values which are
// _not_ strings. // _not_ strings.
@ -76,7 +76,7 @@ int main() {
return 1; return 1;
} }
auto dec_obj = jwt::decode(sign, algorithms({"rs256"}), verify(false), secret(pub_key)); auto dec_obj = jwt::decode(sign, algorithms({"RS256"}), verify(false), secret(pub_key));
return 0; return 0;
} }

View file

@ -21,7 +21,7 @@ void basic_decode_test()
using namespace jwt::params; using namespace jwt::params;
std::cout << "DECODE: \n"; std::cout << "DECODE: \n";
jwt::decode(res, algorithms({"none", "hs256"}), ec, verify(false), secret("secret")); jwt::decode(res, algorithms({"none", "HS256"}), ec, verify(false), secret("secret"));
} }
int main() { int main() {

View file

@ -43,9 +43,9 @@ void basic_jwt_object_test()
std::cout << obj3.payload() << std::endl; std::cout << obj3.payload() << std::endl;
obj3.secret("secret"); obj3.secret("secret");
obj3.header().algo("hs256"); obj3.header().algo("HS256");
auto dec_obj = jwt::decode(obj3.signature(), algorithms({"hs256"}), secret("secret")); auto dec_obj = jwt::decode(obj3.signature(), algorithms({"HS256"}), secret("secret"));
} }
void jwt_object_pem_test() void jwt_object_pem_test()
@ -82,7 +82,7 @@ MIGkAgEBBDBeLCgapjZmvTatMHaYX3A02+0Ys3Tr8kda+E9DFnmCSiCOEig519fT
std::cout << "Get claim value for exp: " << std::cout << "Get claim value for exp: " <<
obj.payload().get_claim_value<uint64_t>("exp") << std::endl; obj.payload().get_claim_value<uint64_t>("exp") << std::endl;
auto dec_obj = jwt::decode(obj.signature(), algorithms({"es256"}), secret(pub_key)); auto dec_obj = jwt::decode(obj.signature(), algorithms({"ES256"}), secret(pub_key));
std::cout << dec_obj.payload() << std::endl; std::cout << dec_obj.payload() << std::endl;
} }

View file

@ -9,7 +9,7 @@ TEST (DecodeTest, InvalidFinalDotForNoneAlg)
"eyJhbGciOiJOT05FIiwidHlwIjoiSldUIn0.eyJhdWQiOiJyaWZ0LmlvIiwiZXhwIjoxNTEzODYzMzcxLCJzdWIiOiJub3RoaW5nIG11Y2gifQ"; "eyJhbGciOiJOT05FIiwidHlwIjoiSldUIn0.eyJhdWQiOiJyaWZ0LmlvIiwiZXhwIjoxNTEzODYzMzcxLCJzdWIiOiJub3RoaW5nIG11Y2gifQ";
std::error_code ec; std::error_code ec;
auto obj = jwt::decode(inv_enc_str, algorithms({"none", "hs256"}), ec); auto obj = jwt::decode(inv_enc_str, algorithms({"none", "HS256"}), ec);
ASSERT_TRUE (ec); ASSERT_TRUE (ec);
EXPECT_EQ (ec.value(), static_cast<int>(jwt::DecodeErrc::SignatureFormatError)); EXPECT_EQ (ec.value(), static_cast<int>(jwt::DecodeErrc::SignatureFormatError));
@ -45,7 +45,7 @@ TEST (DecodeTest, DecodeWrongAlgo)
"eyJhbGciOiJOT05FIiwidHlwIjoiSldUIn0.eyJhdWQiOiJyaWZ0LmlvIiwiZXhwIjoxNTEzODYzMzcxLCJzdWIiOiJub3RoaW5nIG11Y2gifQ."; "eyJhbGciOiJOT05FIiwidHlwIjoiSldUIn0.eyJhdWQiOiJyaWZ0LmlvIiwiZXhwIjoxNTEzODYzMzcxLCJzdWIiOiJub3RoaW5nIG11Y2gifQ.";
std::error_code ec; std::error_code ec;
auto obj = jwt::decode(enc_str, algorithms({"hs256"}), ec, secret(""), verify(true)); auto obj = jwt::decode(enc_str, algorithms({"HS256"}), ec, secret(""), verify(true));
EXPECT_TRUE (ec); EXPECT_TRUE (ec);
EXPECT_EQ (ec.value(), static_cast<int>(jwt::VerificationErrc::InvalidAlgorithm)); EXPECT_EQ (ec.value(), static_cast<int>(jwt::VerificationErrc::InvalidAlgorithm));
} }
@ -58,7 +58,7 @@ TEST (DecodeTest, DecodeInvalidHeader)
"ehbGciOiJOT05FIiwidHlwIjoiSldUIn0.eyJhdWQiOiJyaWZ0LmlvIiwiZXhwIjoxNTEzODYzMzcxLCJzdWIiOiJub3RoaW5nIG11Y2gifQ."; "ehbGciOiJOT05FIiwidHlwIjoiSldUIn0.eyJhdWQiOiJyaWZ0LmlvIiwiZXhwIjoxNTEzODYzMzcxLCJzdWIiOiJub3RoaW5nIG11Y2gifQ.";
std::error_code ec; std::error_code ec;
auto obj = jwt::decode(enc_str, algorithms({"hs256"}), ec, secret(""), verify(true)); auto obj = jwt::decode(enc_str, algorithms({"HS256"}), ec, secret(""), verify(true));
ASSERT_TRUE (ec); ASSERT_TRUE (ec);
EXPECT_EQ (ec.value(), static_cast<int>(jwt::DecodeErrc::JsonParseError)); EXPECT_EQ (ec.value(), static_cast<int>(jwt::DecodeErrc::JsonParseError));
@ -72,7 +72,7 @@ TEST (DecodeTest, DecodeEmptyHeader)
".eyJhdWQiOiJyaWZ0LmlvIiwiZXhwIjoxNTEzODYzMzcxLCJzdWIiOiJub3RoaW5nIG11Y2gifQ."; ".eyJhdWQiOiJyaWZ0LmlvIiwiZXhwIjoxNTEzODYzMzcxLCJzdWIiOiJub3RoaW5nIG11Y2gifQ.";
std::error_code ec; std::error_code ec;
auto obj = jwt::decode(enc_str, algorithms({"hs256"}), ec, secret(""), verify(true)); auto obj = jwt::decode(enc_str, algorithms({"HS256"}), ec, secret(""), verify(true));
ASSERT_TRUE (ec); ASSERT_TRUE (ec);
EXPECT_EQ (ec.value(), static_cast<int>(jwt::DecodeErrc::JsonParseError)); EXPECT_EQ (ec.value(), static_cast<int>(jwt::DecodeErrc::JsonParseError));
@ -102,7 +102,7 @@ TEST (DecodeTest, DecodeHS256)
"jk7bRQKTLvs1RcuvMc2B_rt6WBYPoVPirYi_QRBPiuk"; "jk7bRQKTLvs1RcuvMc2B_rt6WBYPoVPirYi_QRBPiuk";
std::error_code ec; std::error_code ec;
auto obj = jwt::decode(enc_str, algorithms({"none", "hs256"}), ec, verify(false), secret("secret")); auto obj = jwt::decode(enc_str, algorithms({"none", "HS256"}), ec, verify(false), secret("secret"));
ASSERT_FALSE (ec); ASSERT_FALSE (ec);
EXPECT_TRUE (obj.has_claim("iss")); EXPECT_TRUE (obj.has_claim("iss"));
@ -125,7 +125,7 @@ TEST (DecodeTest, SecretKeyNotPassed)
"jk7bRQKTLvs1RcuvMc2B_rt6WBYPoVPirYi_QRBPiuk"; "jk7bRQKTLvs1RcuvMc2B_rt6WBYPoVPirYi_QRBPiuk";
std::error_code ec; std::error_code ec;
auto obj = jwt::decode(enc_str, algorithms({"none", "hs256"}), ec, verify(true)); auto obj = jwt::decode(enc_str, algorithms({"none", "HS256"}), ec, verify(true));
ASSERT_TRUE (ec); ASSERT_TRUE (ec);
EXPECT_EQ (ec.value(), static_cast<int>(jwt::DecodeErrc::KeyNotPresent)); EXPECT_EQ (ec.value(), static_cast<int>(jwt::DecodeErrc::KeyNotPresent));
@ -143,7 +143,7 @@ TEST (DecodeTest, DecodeHS384)
const jwt::string_view key = "0123456789abcdefghijklmnopqrstuvwxyz"; const jwt::string_view key = "0123456789abcdefghijklmnopqrstuvwxyz";
std::error_code ec; std::error_code ec;
auto obj = jwt::decode(enc_str, algorithms({"none", "hs384"}), ec, verify(false), secret(key)); auto obj = jwt::decode(enc_str, algorithms({"none", "HS384"}), ec, verify(false), secret(key));
ASSERT_FALSE (ec); ASSERT_FALSE (ec);
EXPECT_TRUE (obj.has_claim("sub")); EXPECT_TRUE (obj.has_claim("sub"));
@ -162,7 +162,7 @@ TEST (DecodeTest, DecodeHS512)
const jwt::string_view key = "00112233445566778899"; const jwt::string_view key = "00112233445566778899";
std::error_code ec; std::error_code ec;
auto obj = jwt::decode(enc_str, algorithms({"none", "hs384", "hs512"}), ec, verify(false), secret(key)); auto obj = jwt::decode(enc_str, algorithms({"none", "HS384", "HS512"}), ec, verify(false), secret(key));
ASSERT_FALSE (ec); ASSERT_FALSE (ec);
@ -180,7 +180,7 @@ TEST (DecodeTest, TypHeaderMiss)
"pMWBLSWl1p4V958lfe_6ZhvgFMOQv9Eq5mlndVKFKkA"; "pMWBLSWl1p4V958lfe_6ZhvgFMOQv9Eq5mlndVKFKkA";
std::error_code ec; std::error_code ec;
auto obj = jwt::decode(enc_str, algorithms({"none", "hs256"}), ec, verify(false)); auto obj = jwt::decode(enc_str, algorithms({"none", "HS256"}), ec, verify(false));
std::cout << "Decode header: " << obj.header() << std::endl; std::cout << "Decode header: " << obj.header() << std::endl;
EXPECT_FALSE (ec); EXPECT_FALSE (ec);

View file

@ -9,7 +9,7 @@ TEST (DecodeVerify, BeforeExpiryTest)
{ {
using namespace jwt::params; 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") obj.add_claim("iss", "arun.muralidharan")
.add_claim("exp", std::chrono::system_clock::now() + std::chrono::seconds{10}) .add_claim("exp", std::chrono::system_clock::now() + std::chrono::seconds{10})
; ;
@ -19,7 +19,7 @@ TEST (DecodeVerify, BeforeExpiryTest)
ASSERT_FALSE (ec); ASSERT_FALSE (ec);
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), ec, secret("secret"), verify(true)); auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), ec, secret("secret"), verify(true));
ASSERT_FALSE (ec); ASSERT_FALSE (ec);
} }
@ -27,7 +27,7 @@ TEST (DecodeVerify, AfterExpiryTest)
{ {
using namespace jwt::params; 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") obj.add_claim("iss", "arun.muralidharan")
.add_claim("exp", std::chrono::system_clock::now() - std::chrono::seconds{1}) .add_claim("exp", std::chrono::system_clock::now() - std::chrono::seconds{1})
; ;
@ -36,7 +36,7 @@ TEST (DecodeVerify, AfterExpiryTest)
auto enc_str = obj.signature(ec); auto enc_str = obj.signature(ec);
ASSERT_FALSE (ec); ASSERT_FALSE (ec);
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), ec, secret("secret"), verify(true)); auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), ec, secret("secret"), verify(true));
ASSERT_TRUE (ec); ASSERT_TRUE (ec);
EXPECT_EQ (ec.value(), static_cast<int>(jwt::VerificationErrc::TokenExpired)); EXPECT_EQ (ec.value(), static_cast<int>(jwt::VerificationErrc::TokenExpired));
} }
@ -45,7 +45,7 @@ TEST (DecodeVerify, AfterExpiryWithLeeway)
{ {
using namespace jwt::params; 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") obj.add_claim("iss", "arun.muralidharan")
.add_claim("exp", std::chrono::system_clock::now() - std::chrono::seconds{1}) .add_claim("exp", std::chrono::system_clock::now() - std::chrono::seconds{1})
; ;
@ -54,7 +54,7 @@ TEST (DecodeVerify, AfterExpiryWithLeeway)
auto enc_str = obj.signature(ec); auto enc_str = obj.signature(ec);
ASSERT_FALSE (ec); ASSERT_FALSE (ec);
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), ec, secret("secret"), verify(true), leeway(2)); auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), ec, secret("secret"), verify(true), leeway(2));
ASSERT_FALSE (ec); ASSERT_FALSE (ec);
} }
@ -62,7 +62,7 @@ TEST (DecodeVerify, ValidIssuerTest)
{ {
using namespace jwt::params; 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") obj.add_claim("iss", "arun.muralidharan")
.add_claim("sub", "test") .add_claim("sub", "test")
; ;
@ -71,7 +71,7 @@ TEST (DecodeVerify, ValidIssuerTest)
auto enc_str = obj.signature(ec); auto enc_str = obj.signature(ec);
ASSERT_FALSE (ec); ASSERT_FALSE (ec);
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), ec, secret("secret"), issuer("arun.muralidharan")); auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), ec, secret("secret"), issuer("arun.muralidharan"));
ASSERT_FALSE (ec); ASSERT_FALSE (ec);
} }
@ -79,12 +79,12 @@ TEST (DecodeVerify, InvalidIssuerTest_1)
{ {
using namespace jwt::params; 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"}})};
std::error_code ec; std::error_code ec;
auto enc_str = obj.signature(ec); auto enc_str = obj.signature(ec);
ASSERT_FALSE (ec); ASSERT_FALSE (ec);
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), ec, secret("secret"), issuer("arun.muralidharan")); auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), ec, secret("secret"), issuer("arun.muralidharan"));
ASSERT_TRUE (ec); ASSERT_TRUE (ec);
EXPECT_EQ (ec.value(), static_cast<int>(jwt::VerificationErrc::InvalidIssuer)); EXPECT_EQ (ec.value(), static_cast<int>(jwt::VerificationErrc::InvalidIssuer));
@ -94,14 +94,14 @@ TEST (DecodeVerify, InvalidIssuerTest_2)
{ {
using namespace jwt::params; 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"); obj.add_claim("iss", "arun.muralidharan");
std::error_code ec; std::error_code ec;
auto enc_str = obj.signature(ec); auto enc_str = obj.signature(ec);
ASSERT_FALSE (ec); ASSERT_FALSE (ec);
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), ec, secret("secret"), issuer("arun.murali")); auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), ec, secret("secret"), issuer("arun.murali"));
ASSERT_TRUE (ec); ASSERT_TRUE (ec);
EXPECT_EQ (ec.value(), static_cast<int>(jwt::VerificationErrc::InvalidIssuer)); EXPECT_EQ (ec.value(), static_cast<int>(jwt::VerificationErrc::InvalidIssuer));
} }
@ -110,14 +110,14 @@ TEST (DecodeVerify, NotImmatureSignatureTest)
{ {
using namespace jwt::params; 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}); obj.add_claim(jwt::registered_claims::not_before, std::chrono::system_clock::now() - std::chrono::seconds{10});
std::error_code ec; std::error_code ec;
auto enc_str = obj.signature(ec); auto enc_str = obj.signature(ec);
ASSERT_FALSE (ec); ASSERT_FALSE (ec);
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), ec, secret("secret")); auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), ec, secret("secret"));
ASSERT_FALSE (ec); ASSERT_FALSE (ec);
} }
@ -125,14 +125,14 @@ TEST (DecodeVerify, ImmatureSignatureTest)
{ {
using namespace jwt::params; 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}); obj.add_claim(jwt::registered_claims::not_before, std::chrono::system_clock::now() + std::chrono::seconds{10});
std::error_code ec; std::error_code ec;
auto enc_str = obj.signature(ec); auto enc_str = obj.signature(ec);
ASSERT_FALSE (ec); ASSERT_FALSE (ec);
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), ec, secret("secret")); auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), ec, secret("secret"));
ASSERT_TRUE (ec); ASSERT_TRUE (ec);
EXPECT_EQ (ec.value(), static_cast<int>(jwt::VerificationErrc::ImmatureSignature)); EXPECT_EQ (ec.value(), static_cast<int>(jwt::VerificationErrc::ImmatureSignature));
} }
@ -141,14 +141,14 @@ TEST (DecodeVerify, ImmatureSignatureTestWithLeeway)
{ {
using namespace jwt::params; 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}); obj.add_claim(jwt::registered_claims::not_before, std::chrono::system_clock::now() + std::chrono::seconds{10});
std::error_code ec; std::error_code ec;
auto enc_str = obj.signature(ec); auto enc_str = obj.signature(ec);
ASSERT_FALSE (ec); ASSERT_FALSE (ec);
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), ec, secret("secret"), leeway(10)); auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), ec, secret("secret"), leeway(10));
ASSERT_FALSE (ec); ASSERT_FALSE (ec);
} }
@ -156,13 +156,13 @@ TEST (DecodeVerify, InvalidAudienceTest)
{ {
using namespace jwt::params; 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"}})};
std::error_code ec; std::error_code ec;
auto enc_str = obj.signature(ec); auto enc_str = obj.signature(ec);
ASSERT_FALSE (ec); ASSERT_FALSE (ec);
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), ec, secret("secret"), aud("ww")); auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), ec, secret("secret"), aud("ww"));
ASSERT_TRUE (ec); ASSERT_TRUE (ec);
EXPECT_EQ (ec.value(), static_cast<int>(jwt::VerificationErrc::InvalidAudience)); EXPECT_EQ (ec.value(), static_cast<int>(jwt::VerificationErrc::InvalidAudience));
} }
@ -171,13 +171,13 @@ TEST (DecodeVerify, InvalidIATTest)
{ {
using namespace jwt::params; 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"}})};
obj.add_claim("iat", "what?"); obj.add_claim("iat", "what?");
auto enc_str = obj.signature(); auto enc_str = obj.signature();
std::error_code ec; std::error_code ec;
auto dec_obj = jwt::decode(enc_str, algorithms({"hs256"}), ec, secret("secret"), validate_iat(true)); auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), ec, secret("secret"), validate_iat(true));
EXPECT_EQ (ec.value(), static_cast<int>(jwt::VerificationErrc::TypeConversionError)); EXPECT_EQ (ec.value(), static_cast<int>(jwt::VerificationErrc::TypeConversionError));
} }
@ -186,11 +186,11 @@ TEST (DecodeVerify, InvalidSignatureTest)
using namespace jwt::params; using namespace jwt::params;
std::error_code ec; std::error_code ec;
auto dec_obj = jwt::decode("", algorithms({"hs256"}), ec, secret("secret"), validate_iat(true)); auto dec_obj = jwt::decode("", algorithms({"HS256"}), ec, secret("secret"), validate_iat(true));
EXPECT_EQ (ec.value(), static_cast<int>(jwt::DecodeErrc::SignatureFormatError)); EXPECT_EQ (ec.value(), static_cast<int>(jwt::DecodeErrc::SignatureFormatError));
ec.clear(); ec.clear();
dec_obj = jwt::decode("abcdsdfhbsdhjfbsdj.", algorithms({"hs256"}), ec, secret("secret"), validate_iat(true)); dec_obj = jwt::decode("abcdsdfhbsdhjfbsdj.", algorithms({"HS256"}), ec, secret("secret"), validate_iat(true));
EXPECT_EQ (ec.value(), static_cast<int>(jwt::DecodeErrc::SignatureFormatError)); EXPECT_EQ (ec.value(), static_cast<int>(jwt::DecodeErrc::SignatureFormatError));
} }

View file

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

View file

@ -8,7 +8,7 @@ TEST (EncodeTest, TestRemoveClaim)
{ {
using namespace jwt::params; 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") obj.add_claim("iss", "arun.muralidharan")
.add_claim("sub", "admin") .add_claim("sub", "admin")
@ -29,7 +29,7 @@ TEST (EncodeTest, TestRemoveTypHeader)
{ {
using namespace jwt::params; 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") obj.add_claim("iss", "arun.muralidharan")
.add_claim("sub", "admin") .add_claim("sub", "admin")
@ -54,7 +54,7 @@ TEST (EncodeTest, StrEncodeHS256_1)
"eyJpYXQiOjE1MTM4NjIzNzEsImlkIjoiYS1iLWMtZC1lLWYtMS0yLTMiLCJpc3MiOiJhcnVuLm11cmFsaWRoYXJhbiIsInN1YiI6ImFkbWluIn0." "eyJpYXQiOjE1MTM4NjIzNzEsImlkIjoiYS1iLWMtZC1lLWYtMS0yLTMiLCJpc3MiOiJhcnVuLm11cmFsaWRoYXJhbiIsInN1YiI6ImFkbWluIn0."
"jk7bRQKTLvs1RcuvMc2B_rt6WBYPoVPirYi_QRBPiuk"; "jk7bRQKTLvs1RcuvMc2B_rt6WBYPoVPirYi_QRBPiuk";
jwt::jwt_object obj{algorithm("hs256"), secret("secret")}; jwt::jwt_object obj{algorithm("HS256"), secret("secret")};
obj.add_claim("iss", "arun.muralidharan") obj.add_claim("iss", "arun.muralidharan")
.add_claim("sub", "admin") .add_claim("sub", "admin")
@ -242,7 +242,7 @@ TEST (EncodeTest, StrEncodeNoneAlgWithKey)
const jwt::string_view secret1 = "abcdefghijklmnopqrstuvwxyz"; const jwt::string_view secret1 = "abcdefghijklmnopqrstuvwxyz";
const jwt::string_view secret2 = "0123456789qwertybabe"; const jwt::string_view secret2 = "0123456789qwertybabe";
jwt::jwt_object obj{algorithm("NONE"), jwt::jwt_object obj{algorithm("none"),
payload({{"iss", "arn-ml"}}), payload({{"iss", "arn-ml"}}),
secret(secret1)}; secret(secret1)};
@ -261,7 +261,7 @@ TEST (EncodeTest, OverwriteClaimsTest)
{ {
using namespace jwt::params; using namespace jwt::params;
jwt::jwt_object obj{algorithm("NONE"), jwt::jwt_object obj{algorithm("none"),
payload({ payload({
{"iss", "arn-ml"}, {"iss", "arn-ml"},
{"x-pld1", "data1"}, {"x-pld1", "data1"},

View file

@ -53,7 +53,7 @@ TEST (ESAlgo, ES256EncodingDecodingTest)
key = read_from_file(EC384_PUB_KEY); key = read_from_file(EC384_PUB_KEY);
ASSERT_TRUE (key.length()); ASSERT_TRUE (key.length());
auto dec_obj = jwt::decode(enc_str, algorithms({"es256"}), ec, verify(false), secret(key)); auto dec_obj = jwt::decode(enc_str, algorithms({"ES256"}), ec, verify(false), secret(key));
EXPECT_FALSE (ec); EXPECT_FALSE (ec);
EXPECT_EQ (dec_obj.header().algo(), jwt::algorithm::ES256); EXPECT_EQ (dec_obj.header().algo(), jwt::algorithm::ES256);
@ -83,7 +83,7 @@ TEST (ESAlgo, ES384EncodingDecodingTest)
key = read_from_file(EC384_PUB_KEY); key = read_from_file(EC384_PUB_KEY);
ASSERT_TRUE (key.length()); ASSERT_TRUE (key.length());
auto dec_obj = jwt::decode(enc_str, algorithms({"es384"}), verify(false), secret(key)); auto dec_obj = jwt::decode(enc_str, algorithms({"ES384"}), verify(false), secret(key));
EXPECT_EQ (dec_obj.header().algo(), jwt::algorithm::ES384); EXPECT_EQ (dec_obj.header().algo(), jwt::algorithm::ES384);
} }
@ -107,7 +107,7 @@ TEST (ESAlgo, ES512EncodingDecodingTest)
key = read_from_file(EC384_PUB_KEY); key = read_from_file(EC384_PUB_KEY);
ASSERT_TRUE (key.length()); ASSERT_TRUE (key.length());
auto dec_obj = jwt::decode(enc_str, algorithms({"es512"}), verify(false), secret(key)); auto dec_obj = jwt::decode(enc_str, algorithms({"ES512"}), verify(false), secret(key));
EXPECT_EQ (dec_obj.header().algo(), jwt::algorithm::ES512); EXPECT_EQ (dec_obj.header().algo(), jwt::algorithm::ES512);
} }
@ -131,7 +131,7 @@ TEST (ESAlgo, ES384EncodingDecodingValidTest)
key = read_from_file(EC384_PUB_KEY); key = read_from_file(EC384_PUB_KEY);
ASSERT_TRUE (key.length()); ASSERT_TRUE (key.length());
auto dec_obj = jwt::decode(enc_str, algorithms({"es384"}), verify(true), secret(key)); auto dec_obj = jwt::decode(enc_str, algorithms({"ES384"}), verify(true), secret(key));
EXPECT_EQ (dec_obj.header().algo(), jwt::algorithm::ES384); EXPECT_EQ (dec_obj.header().algo(), jwt::algorithm::ES384);
EXPECT_TRUE (dec_obj.has_claim("exp")); EXPECT_TRUE (dec_obj.has_claim("exp"));
@ -143,7 +143,7 @@ TEST (ESAlgo, ES384EncodingDecodingValidTest)
auto iss = payload.get_claim_value<std::string>("iss"); auto iss = payload.get_claim_value<std::string>("iss");
return keystore[iss]; return keystore[iss];
}; };
auto dec_obj2 = jwt::decode(enc_str, algorithms({"es384"}), verify(true), secret(l)); auto dec_obj2 = jwt::decode(enc_str, algorithms({"ES384"}), verify(true), secret(l));
EXPECT_EQ (dec_obj2.header().algo(), jwt::algorithm::ES384); EXPECT_EQ (dec_obj2.header().algo(), jwt::algorithm::ES384);
} }

View file

@ -17,7 +17,7 @@ TEST (ObjectTest, MoveConstructor)
{ {
using namespace jwt::params; 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"); obj.add_claim("iss", "arun.muralidharan");

View file

@ -63,7 +63,7 @@ TEST (RSAAlgo, RSA256EncodingDecodingTest)
key = read_from_file(RSA256_PUB_KEY); key = read_from_file(RSA256_PUB_KEY);
ASSERT_TRUE (key.length()); ASSERT_TRUE (key.length());
auto dec_obj = jwt::decode(enc_str, algorithms({"rs256"}), ec, verify(false), secret(key)); auto dec_obj = jwt::decode(enc_str, algorithms({"RS256"}), ec, verify(false), secret(key));
EXPECT_FALSE (ec); EXPECT_FALSE (ec);
} }
@ -91,7 +91,7 @@ TEST (RSAAlgo, RSA384EncodingDecodingTest)
key = read_from_file(RSA384_PUB_KEY); key = read_from_file(RSA384_PUB_KEY);
ASSERT_TRUE (key.length()); ASSERT_TRUE (key.length());
auto dec_obj = jwt::decode(enc_str, algorithms({"none", "hs384", "rs384"}), verify(false), secret(key)); auto dec_obj = jwt::decode(enc_str, algorithms({"none", "HS384", "RS384"}), verify(false), secret(key));
EXPECT_EQ (dec_obj.header().algo(), jwt::algorithm::RS384); EXPECT_EQ (dec_obj.header().algo(), jwt::algorithm::RS384);
} }
@ -118,7 +118,7 @@ TEST (RSAAlgo, RSA512EncodingDecodingTest)
key = read_from_file(RSA512_PUB_KEY); key = read_from_file(RSA512_PUB_KEY);
ASSERT_TRUE (key.length()); ASSERT_TRUE (key.length());
auto dec_obj = jwt::decode(enc_str, algorithms({"none", "hs384", "rs512"}), verify(false), secret(key)); auto dec_obj = jwt::decode(enc_str, algorithms({"none", "HS384", "RS512"}), verify(false), secret(key));
EXPECT_EQ (dec_obj.header().algo(), jwt::algorithm::RS512); EXPECT_EQ (dec_obj.header().algo(), jwt::algorithm::RS512);
} }
@ -139,7 +139,7 @@ TEST (RSAAlgo, NoSpecificAlgo)
key = read_from_file(RSA512_PUB_KEY); key = read_from_file(RSA512_PUB_KEY);
ASSERT_TRUE (key.length()); ASSERT_TRUE (key.length());
EXPECT_THROW (jwt::decode(enc_str, algorithms({"none", "hs384", "rs384"}), verify(true), secret(key)), EXPECT_THROW (jwt::decode(enc_str, algorithms({"none", "HS384", "RS384"}), verify(true), secret(key)),
jwt::InvalidAlgorithmError); jwt::InvalidAlgorithmError);
} }