mirror of
https://github.com/allankoechke/jwt-cpp.git
synced 2026-11-30 10:18:40 +00:00
🧰 Adding clang-tidy, cmake-format, and ASAN tests (#168)
* adding clang-tidy and asan tests Playing with clang-tidy, we already had the rule removed in #166... running the static analyzer from CMake reproduced the report in many places... I suspect the macro and `new`/`delete` separation clang-tidy is just unable to understand. Running the problematic examples + tests with the ASAN enabled reported no problems * Apply suggestions from code review * Update lint.yml * applying linting rules * fix bad rename * formating * clang-tidy on jsoncons tests * and cmake-format to lint * cmake format improve change detection * Update lint.yml * apply linting
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <jwt-cpp/jwt.h>
|
||||
|
||||
int main(int argc, const char** argv) {
|
||||
int main() {
|
||||
// openssl ecparam -name secp256k1 -genkey -noout -out ec-secp256k1-priv-key.pem
|
||||
std::string es256k_priv_key = R"(-----BEGIN EC PRIVATE KEY-----
|
||||
MHQCAQEEIArnQWnspKtjiVuZuzuZ/l1Uqqq8gb2unLJ/6U/Saf4ioAcGBSuBBAAK
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#include <iostream>
|
||||
#include <jwt-cpp/jwt.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::string publicKey = R"({"keys": [{
|
||||
int main() {
|
||||
std::string raw_jwks = R"({"keys": [{
|
||||
"kid":"internal-gateway-jwt.api.sc.net",
|
||||
"alg": "RS256",
|
||||
"kty": "RSA",
|
||||
@@ -27,22 +26,31 @@ int main()
|
||||
}
|
||||
]})";
|
||||
|
||||
std::string token = "eyJraWQiOiJpbnRlcm5hbC1nYXRld2F5LWp3dC5hcGkuc2MubmV0IiwiYWxnIjoiUlMyNTYiLCJ0eXAiOiJKV1QifQ.eyJuYmYiOjE1Mzk3NjcwMTUsImlhdCI6MTUzOTc2Njk5MiwiaXNzIjoia29uZyIsImh0dHA6XC9cL3dzbzIub3JnXC9nYXRld2F5XC9zdWJzY3JpYmVyIjoidXZ0dXNlcjJAY2FyYm9uLnN1cGVyI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VwZXIiLCJodHRwOlwvXC93c28yLm9yZ1wvZ2F0ZXdheVwvZW5kdXNlciI6InV2dHVzZXIyQGNhcmJvbi5zdXBlci"
|
||||
"IsImp0aSI6IjI0NmJkZTlhLWQ4OGQtNGRlZC1hODhmLTRhMTNhOWJmODQ4ZiIsImh0dHA6XC9cL3dzbzIub3JnXC9nYXRld2F5XC9hcHBsaWNh"
|
||||
"dGlvbm5hbWUiOiJ1dnR1c2VyMl9hcHBfMSIsImV4cCI6MTUzOTc2NzkxNX0.foxbo6C30yr_wkF-5EkgtYUMG-4SXNfRsmewdT6MbE-"
|
||||
"RXVkIPkVk8kDP41yRXmnk4OxburCqawiGlzzEhfHoFf0qv0qZEmwEXSdcyRw-czZTs6ACjWYe8kejOCVmpvUrq01NgOhTwgVg6pv93BlcmNY--"
|
||||
"zytjx_9hlVm5SS1lZ0I21n45BIWu5JvBD51TZXEURb_XhL7RcF9I8mfzrRpB2fSHW38gj-nogsdOPA_y3S-hJKylmmaqmaQgTF-jP-"
|
||||
"gYr6eqKyGPVwc6fLZ5zqAup59SefdPEY23-WWmHzj968jlsDSEiCp_YiYTnF3tHVLFWDsrprYKwNb0_p95tBmPA";
|
||||
|
||||
auto decoded_jwt = jwt::decode(token);
|
||||
auto jwks = jwt::parse_jwks(publicKey);
|
||||
auto jwks = jwt::parse_jwks(raw_jwks);
|
||||
auto jwk = jwks.get_jwk(decoded_jwt.get_key_id());
|
||||
|
||||
auto issuer = decoded_jwt.get_issuer();
|
||||
auto x5c = jwk.get_x5c_key_value();
|
||||
|
||||
if (!x5c.empty() && !issuer.empty()) {
|
||||
auto verifier = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::rs256(jwt::helper::convert_base64_der_to_pem(x5c), "", "", ""))
|
||||
.with_issuer(issuer)
|
||||
.leeway(60UL); // value in seconds, add some to compensate timeout
|
||||
auto verifier =
|
||||
jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::rs256(jwt::helper::convert_base64_der_to_pem(x5c), "", "", ""))
|
||||
.with_issuer(issuer)
|
||||
.leeway(60UL); // value in seconds, add some to compensate timeout
|
||||
|
||||
verifier.verify(decoded_jwt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <jwt-cpp/jwt.h>
|
||||
|
||||
int main(int argc, const char** argv) {
|
||||
int main() {
|
||||
std::string token =
|
||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
auto decoded = jwt::decode(token);
|
||||
|
||||
@@ -14,7 +14,7 @@ std::string make_pico_token() {
|
||||
|
||||
jwt::claim::set_t list{"once", "twice"};
|
||||
|
||||
std::vector<int64_t> big_numbers{727663072ull, 770979831ull, 427239169ull, 525936436ull};
|
||||
std::vector<int64_t> big_numbers{727663072ULL, 770979831ULL, 427239169ULL, 525936436ULL};
|
||||
|
||||
const auto time = jwt::date::clock::now();
|
||||
|
||||
@@ -48,22 +48,15 @@ std::string make_nlohmann_token() {
|
||||
static jwt::json::type get_type(const json& val) {
|
||||
using jwt::json::type;
|
||||
|
||||
if (val.type() == json::value_t::boolean)
|
||||
return type::boolean;
|
||||
else if (val.type() == json::value_t::number_integer)
|
||||
return type::integer;
|
||||
else if (val.type() == json::value_t::number_unsigned) // nlohmann internally tracks two types of integers
|
||||
return type::integer;
|
||||
else if (val.type() == json::value_t::number_float)
|
||||
return type::number;
|
||||
else if (val.type() == json::value_t::string)
|
||||
return type::string;
|
||||
else if (val.type() == json::value_t::array)
|
||||
return type::array;
|
||||
else if (val.type() == json::value_t::object)
|
||||
return type::object;
|
||||
else
|
||||
throw std::logic_error("invalid type");
|
||||
if (val.type() == json::value_t::boolean) return type::boolean;
|
||||
if (val.type() == json::value_t::number_integer) return type::integer;
|
||||
// nlohmann internally tracks two types of integers
|
||||
if (val.type() == json::value_t::number_unsigned) return type::integer;
|
||||
if (val.type() == json::value_t::number_float) return type::number;
|
||||
if (val.type() == json::value_t::string) return type::string;
|
||||
if (val.type() == json::value_t::array) return type::array;
|
||||
if (val.type() == json::value_t::object) return type::object;
|
||||
throw std::logic_error("invalid type");
|
||||
}
|
||||
|
||||
static json::object_t as_object(const json& val) {
|
||||
@@ -115,7 +108,7 @@ std::string make_nlohmann_token() {
|
||||
|
||||
claim::set_t list{"once", "twice"};
|
||||
|
||||
std::vector<int64_t> big_numbers{727663072ull, 770979831ull, 427239169ull, 525936436ull};
|
||||
std::vector<int64_t> big_numbers{727663072ULL, 770979831ULL, 427239169ULL, 525936436ULL};
|
||||
|
||||
const auto time = jwt::date::clock::now();
|
||||
|
||||
@@ -135,7 +128,7 @@ std::string make_nlohmann_token() {
|
||||
.sign(jwt::algorithm::none{});
|
||||
}
|
||||
|
||||
int main(int argc, const char** argv) {
|
||||
int main() {
|
||||
const auto token = make_pico_token();
|
||||
auto decoded = jwt::decode(token);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <jwt-cpp/jwt.h>
|
||||
|
||||
int main(int argc, const char** argv) {
|
||||
int main() {
|
||||
std::string rsa_priv_key = R"(-----BEGIN PRIVATE KEY-----
|
||||
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC4ZtdaIrd1BPIJ
|
||||
tfnF0TjIK5inQAXZ3XlCrUlJdP+XHwIRxdv1FsN12XyMYO/6ymLmo9ryoQeIrsXB
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <jwt-cpp/jwt.h>
|
||||
|
||||
int main(int argc, const char** argv) {
|
||||
int main() {
|
||||
std::string rsa_priv_key = R"(-----BEGIN PRIVATE KEY-----
|
||||
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC4ZtdaIrd1BPIJ
|
||||
tfnF0TjIK5inQAXZ3XlCrUlJdP+XHwIRxdv1FsN12XyMYO/6ymLmo9ryoQeIrsXB
|
||||
|
||||
Reference in New Issue
Block a user