Added tests and gtest support
This commit is contained in:
parent
e666406d53
commit
9a7925cca5
4 changed files with 38 additions and 1 deletions
|
@ -8,7 +8,7 @@ namespace jwt {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
static void jwt_throw_exception(const std::error_code& ec);
|
static inline void jwt_throw_exception(const std::error_code& ec);
|
||||||
|
|
||||||
template <typename T, typename Cond>
|
template <typename T, typename Cond>
|
||||||
std::string to_json_str(const T& obj, bool pretty)
|
std::string to_json_str(const T& obj, bool pretty)
|
||||||
|
|
1
tests/compile.txt
Normal file
1
tests/compile.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
g++ -std=c++14 -I /usr/local/Cellar/openssl/1.0.2j/include/ -I /Users/amuralid/dev_test/cpp-jwt/include/ -o test_jwt_encode test_jwt_encode.cc -L /usr/local/Cellar//openssl/1.0.2j/lib/ -lssl -lcrypto -lgtest
|
BIN
tests/test_jwt_encode
Executable file
BIN
tests/test_jwt_encode
Executable file
Binary file not shown.
36
tests/test_jwt_encode.cc
Normal file
36
tests/test_jwt_encode.cc
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "jwt/jwt.hpp"
|
||||||
|
|
||||||
|
TEST (EncodeTest, Mytest1)
|
||||||
|
{
|
||||||
|
using namespace jwt::params;
|
||||||
|
|
||||||
|
const std::string expected_sign =
|
||||||
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9."
|
||||||
|
"eyJpYXQiOjE1MTM4NjIzNzEsImlkIjoiYS1iLWMtZC1lLWYtMS0yLTMiLCJpc3MiOiJhcnVuLm11cmFsaWRoYXJhbiIsInN1YiI6ImFkbWluIn0."
|
||||||
|
"jk7bRQKTLvs1RcuvMc2B_rt6WBYPoVPirYi_QRBPiuk";
|
||||||
|
|
||||||
|
jwt::jwt_object obj{algorithm("hs256"), secret("secret")};
|
||||||
|
|
||||||
|
obj.add_claim("iss", "arun.muralidharan")
|
||||||
|
.add_claim("sub", "admin")
|
||||||
|
.add_claim("id", "a-b-c-d-e-f-1-2-3")
|
||||||
|
.add_claim("iat", 1513862371)
|
||||||
|
;
|
||||||
|
|
||||||
|
std::cout << "Header: " << obj.header() << std::endl;
|
||||||
|
std::cout << "Payload: "<< obj.payload() << std::endl;
|
||||||
|
|
||||||
|
std::string enc_str = obj.signature();
|
||||||
|
|
||||||
|
std::cout << "Signature: " << enc_str << std::endl;
|
||||||
|
|
||||||
|
EXPECT_EQ (enc_str, expected_sign);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
return RUN_ALL_TESTS();
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue