SUPPORT-8592. Проверка подписи маркера доступа
This commit is contained in:
parent
9e85e4e8de
commit
4fa45a1f5e
46 changed files with 1970 additions and 250 deletions
30
tests/CMakeLists.txt
Normal file
30
tests/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
project (test-ervu-sign-module LANGUAGES C)
|
||||
|
||||
include_directories (
|
||||
../src
|
||||
${GLIB2_INCLUDE_DIRS}
|
||||
${JSONGLIB_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set (ESM_SOURCES
|
||||
../src/utils/glib_utils.c
|
||||
../src/utils/json_parser.c
|
||||
../src/utils/jwt.c
|
||||
../src/utils/logger.c
|
||||
)
|
||||
|
||||
set (HEADERS
|
||||
utils/test_jwt.h
|
||||
)
|
||||
|
||||
set (SOURCES
|
||||
main.c
|
||||
utils/test_jwt.c
|
||||
"${ESM_SOURCES}"
|
||||
)
|
||||
|
||||
add_executable(test-ervu-sign-module ${HEADERS} ${SOURCES})
|
||||
|
||||
target_link_libraries(test-ervu-sign-module cunit glib-2.0 json-glib-1.0 gobject-2.0)
|
||||
|
||||
add_test(NAME test-ervu-sign-module COMMAND test-ervu-sign-module)
|
||||
30
tests/main.c
Normal file
30
tests/main.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#include "utils/test_jwt.h"
|
||||
|
||||
#include <CUnit/Basic.h>
|
||||
|
||||
int main(int arv, char** argc)
|
||||
{
|
||||
int failures = -1;
|
||||
(void)arv;
|
||||
(void)argc;
|
||||
|
||||
if (CUE_SUCCESS != CU_initialize_registry())
|
||||
return CU_get_error();
|
||||
|
||||
CU_pSuite suite_jwt = CU_add_suite("JWTSuit", NULL, NULL);
|
||||
if (NULL == suite_jwt) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (NULL == CU_ADD_TEST(suite_jwt, test_jwt_get_header_payload_and_sign)) goto exit;
|
||||
if (NULL == CU_ADD_TEST(suite_jwt, test_jwt_get_alg_from_header)) goto exit;
|
||||
|
||||
CU_basic_set_mode(CU_BRM_NORMAL);
|
||||
CU_basic_run_tests();
|
||||
|
||||
exit:
|
||||
failures = CU_get_number_of_failures();
|
||||
CU_cleanup_registry();
|
||||
|
||||
return (failures == 0) ? 0 : -1;
|
||||
}
|
||||
68
tests/utils/test_jwt.c
Normal file
68
tests/utils/test_jwt.c
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
#include "test_jwt.h"
|
||||
#include "utils/jwt.h"
|
||||
|
||||
#include <CUnit/Basic.h>
|
||||
|
||||
#define JWT "eyJ2ZXIiOjEsInR5cCI6IkpXVCIsInNidCI6ImF1dGhvcml6YXRpb25fY29kZSIsImFsZyI6IkdP" \
|
||||
"U1QzNDEwXzIwMTJfMjU2In0.eyJuYmYiOjE2ODE3MzI4ODQsInNjb3BlIjoib3BlbmlkIiwiYXV0" \
|
||||
"aF90aW1lIjoxNjgxNzMyODc2LCJpc3MiOiJodHRwOlwvXC9lc2lhLXBvcnRhbDEudGVzdC5nb3N1" \
|
||||
"c2x1Z2kucnVcLyIsInVybjplc2lhOnNpZCI6Ijg3NWQzNDZhLTgzMTktMmM1MS05ZDYwLTYwZmRk" \
|
||||
"MzE4MGVhOSIsInVybjplc2lhOmNsaWVudDpzdGF0ZSI6Ijg5MzgzNDdhLTI0MmMtNGVhYy05NTdk" \
|
||||
"LTk4MDgzNTAzYzUwNyIsImF1dGhfbXRoZCI6IlBXRCIsInVybjplc2lhOnNiaiI6eyJ1cm46ZXNp" \
|
||||
"YTpzYmo6bHZsIjoiUCIsInVybjplc2lhOnNiajp0eXAiOiJQIiwidXJuOmVzaWE6c2JqOm9pZCI6" \
|
||||
"MTAwMDQwMDgyMywidXJuOmVzaWE6c2JqOm5hbSI6Ik9JRC4xMDAwNDAwODIzIn0sImV4cCI6MTY4" \
|
||||
"MTczMzEyNCwicGFyYW1zIjp7fSwiaWF0IjoxNjgxNzMyODg0LCJjbGllbnRfaWQiOiI1MDAyMDEi" \
|
||||
"fQ.8EBVu5Cizok66n1sIrVmS07N_4j9TuaKHlQffr98hwv9amUN5zpckH4dyJtO6IA-8UkhZ19ww" \
|
||||
"Of0F_VCmhOqmQ"
|
||||
|
||||
#define JWT_HEADER "eyJ2ZXIiOjEsInR5cCI6IkpXVCIsInNidCI6ImF1dGhvcml6YXRpb25fY29kZSIsImFsZyI6IkdP" \
|
||||
"U1QzNDEwXzIwMTJfMjU2In0"
|
||||
|
||||
#define JWT_HEADER_PAYLOAD "eyJ2ZXIiOjEsInR5cCI6IkpXVCIsInNidCI6ImF1dGhvcml6YXRpb25fY29kZSIsImFsZ" \
|
||||
"yI6IkdPU1QzNDEwXzIwMTJfMjU2In0.eyJuYmYiOjE2ODE3MzI4ODQsInNjb3BlIjoib3" \
|
||||
"BlbmlkIiwiYXV0aF90aW1lIjoxNjgxNzMyODc2LCJpc3MiOiJodHRwOlwvXC9lc2lhLXB" \
|
||||
"vcnRhbDEudGVzdC5nb3N1c2x1Z2kucnVcLyIsInVybjplc2lhOnNpZCI6Ijg3NWQzNDZh" \
|
||||
"LTgzMTktMmM1MS05ZDYwLTYwZmRkMzE4MGVhOSIsInVybjplc2lhOmNsaWVudDpzdGF0Z" \
|
||||
"SI6Ijg5MzgzNDdhLTI0MmMtNGVhYy05NTdkLTk4MDgzNTAzYzUwNyIsImF1dGhfbXRoZC" \
|
||||
"I6IlBXRCIsInVybjplc2lhOnNiaiI6eyJ1cm46ZXNpYTpzYmo6bHZsIjoiUCIsInVybjp" \
|
||||
"lc2lhOnNiajp0eXAiOiJQIiwidXJuOmVzaWE6c2JqOm9pZCI6MTAwMDQwMDgyMywidXJu" \
|
||||
"OmVzaWE6c2JqOm5hbSI6Ik9JRC4xMDAwNDAwODIzIn0sImV4cCI6MTY4MTczMzEyNCwic" \
|
||||
"GFyYW1zIjp7fSwiaWF0IjoxNjgxNzMyODg0LCJjbGllbnRfaWQiOiI1MDAyMDEifQ"
|
||||
|
||||
#define JWT_SIGN "8EBVu5Cizok66n1sIrVmS07N_4j9TuaKHlQffr98hwv9amUN5zpckH4dyJtO6IA-8UkhZ19ww" \
|
||||
"Of0F_VCmhOqmQ"
|
||||
|
||||
#define JWT_HEADER_DECODED "{\"ver\":1,\"typ\":\"JWT\",\"sbt\":\"authorization_code\"," \
|
||||
"\"alg\":\"GOST3410_2012_256\"}"
|
||||
|
||||
#define JWT_ALG "GOST3410_2012_256"
|
||||
|
||||
void test_jwt_get_header_payload_and_sign()
|
||||
{
|
||||
int rc;
|
||||
str_t jwt = str_t_const(JWT);
|
||||
str_t sign = str_t_null;
|
||||
str_t header = str_t_null;
|
||||
str_t header_payload = str_t_null;
|
||||
|
||||
rc = jwt_get_header_payload_and_sign(&jwt, &header, &header_payload, &sign);
|
||||
CU_ASSERT_EQUAL(rc, 0);
|
||||
|
||||
CU_ASSERT_NSTRING_EQUAL(header.data, JWT_HEADER, header.len);
|
||||
CU_ASSERT_NSTRING_EQUAL(header_payload.data, JWT_HEADER_PAYLOAD, header_payload.len);
|
||||
CU_ASSERT_NSTRING_EQUAL(sign.data, JWT_SIGN, sign.len);
|
||||
}
|
||||
|
||||
void test_jwt_get_alg_from_header()
|
||||
{
|
||||
int rc;
|
||||
str_t header = str_t_const(JWT_HEADER_DECODED);
|
||||
str_t alg = str_t_null;
|
||||
|
||||
rc = jwt_get_alg_from_header(&header, &alg);
|
||||
CU_ASSERT_EQUAL(rc, 0);
|
||||
|
||||
CU_ASSERT_NSTRING_EQUAL(alg.data, JWT_ALG, alg.len);
|
||||
|
||||
str_t_clear(&alg);
|
||||
}
|
||||
8
tests/utils/test_jwt.h
Normal file
8
tests/utils/test_jwt.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef TEST_JWT_H_INCLUDED
|
||||
#define TEST_JWT_H_INCLUDED
|
||||
|
||||
void test_jwt_get_header_payload_and_sign();
|
||||
|
||||
void test_jwt_get_alg_from_header();
|
||||
|
||||
#endif // TEST_JWT_H_INCLUDED
|
||||
Loading…
Add table
Add a link
Reference in a new issue