diff --git a/include/jwt/impl/jwt.ipp b/include/jwt/impl/jwt.ipp index 153074d..500e282 100644 --- a/include/jwt/impl/jwt.ipp +++ b/include/jwt/impl/jwt.ipp @@ -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 std::string to_json_str(const T& obj, bool pretty) diff --git a/tests/compile.txt b/tests/compile.txt new file mode 100644 index 0000000..d70f51f --- /dev/null +++ b/tests/compile.txt @@ -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 diff --git a/tests/test_jwt_encode b/tests/test_jwt_encode new file mode 100755 index 0000000..0125cd9 Binary files /dev/null and b/tests/test_jwt_encode differ diff --git a/tests/test_jwt_encode.cc b/tests/test_jwt_encode.cc new file mode 100644 index 0000000..9af8df1 --- /dev/null +++ b/tests/test_jwt_encode.cc @@ -0,0 +1,36 @@ +#include +#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(); +}