Files
neuron/tests/jwt_test.cc
T
fengzero db914268be the basic info(plugin name, type, kind...) of the plugin is read from the dynamic library
add dynamic library search path configuration, install to
/etc/ld.so.conf.d/

dynamic library search path priority:
  1. driver.path in neuron.yaml
  2. os path
2022-01-19 16:56:10 +08:00

57 lines
1.5 KiB
C++

#include <sys/time.h>
#include <gtest/gtest.h>
#include "config.h"
#include "jwt.h"
#include "neu_jwt.h"
#include "neu_log.h"
TEST(JsonTest, SetJwt)
{
char * token = NULL;
unsigned char public_key[4096] = { 0 };
size_t pub_key_len = 0;
neu_config_init((char *) "./neuron.yaml");
char *public_key_path =
neu_config_get_value(2, (char *) "api", (char *) "public_key");
char *private_key_path =
neu_config_get_value(2, (char *) "api", (char *) "private_key");
EXPECT_EQ(0, neu_jwt_init(public_key_path, private_key_path));
EXPECT_EQ(0, neu_jwt_new(&token));
EXPECT_GE(strlen(token), 400);
jwt_free_str(token);
free(public_key_path);
free(private_key_path);
}
TEST(JsonTest, JwtValidate)
{
char * token = NULL;
char b_token[1024] = { 0 };
unsigned char public_key[4096] = { 0 };
size_t pub_key_len = 0;
struct timeval expire_tv = { 0 };
neu_config_init((char *) "./neuron.yaml");
char *private_key_path =
neu_config_get_value(2, (char *) "api", (char *) "private_key");
char *public_key_path =
neu_config_get_value(2, (char *) "api", (char *) "public_key");
EXPECT_EQ(0, neu_jwt_init(public_key_path, private_key_path));
EXPECT_EQ(0, neu_jwt_new(&token));
snprintf(b_token, sizeof(b_token), "Bearer %s", token);
EXPECT_EQ(0, neu_jwt_validate(b_token));
jwt_free_str(token);
free(public_key_path);
free(private_key_path);
}