Functions | Variables
json_token_test.cc File Reference
#include "src/core/lib/security/credentials/jwt/json_token.h"
#include <string.h>
#include <openssl/evp.h>
#include <grpc/grpc_security.h>
#include <grpc/slice.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/json/json.h"
#include "src/core/lib/security/credentials/oauth2/oauth2_credentials.h"
#include "src/core/lib/slice/b64.h"
#include "src/core/lib/slice/slice_internal.h"
#include "test/core/util/test_config.h"
Include dependency graph for json_token_test.cc:

Go to the source code of this file.

Functions

static void check_jwt_claim (const Json &claim, const char *expected_audience, const char *expected_scope)
 
static void check_jwt_header (const Json &header)
 
static void check_jwt_signature (const char *b64_signature, RSA *rsa_key, const char *signed_data, size_t signed_data_size)
 
static void jwt_creds_check_jwt_claim (const Json &claim)
 
static char * jwt_creds_jwt_encode_and_sign (const grpc_auth_json_key *key)
 
int main (int argc, char **argv)
 
static Json parse_json_part_from_jwt (const char *str, size_t len)
 
static void service_account_creds_check_jwt_claim (const Json &claim)
 
static char * service_account_creds_jwt_encode_and_sign (const grpc_auth_json_key *key)
 
static char * test_json_key_str (const char *bad_part3)
 
static void test_jwt_creds_jwt_encode_and_sign (void)
 
static void test_jwt_encode_and_sign (char *(*jwt_encode_and_sign_func)(const grpc_auth_json_key *), void(*check_jwt_claim_func)(const Json &))
 
static void test_parse_json_key_failure_bad_json (void)
 
static void test_parse_json_key_failure_no_client_email (void)
 
static void test_parse_json_key_failure_no_client_id (void)
 
static void test_parse_json_key_failure_no_private_key (void)
 
static void test_parse_json_key_failure_no_private_key_id (void)
 
static void test_parse_json_key_failure_no_type (void)
 
static void test_parse_json_key_success (void)
 
static void test_parse_refresh_token_failure_no_client_id (void)
 
static void test_parse_refresh_token_failure_no_client_secret (void)
 
static void test_parse_refresh_token_failure_no_refresh_token (void)
 
static void test_parse_refresh_token_failure_no_type (void)
 
static void test_parse_refresh_token_success (void)
 
static void test_service_account_creds_jwt_encode_and_sign (void)
 

Variables

static const char test_json_key_str_part1 []
 
static const char test_json_key_str_part2 []
 
static const char test_json_key_str_part3 []
 
static const char test_refresh_token_str []
 
static const char test_scope [] = "myperm1 myperm2"
 
static const char test_service_url [] = "https://foo.com/foo.v1"
 

Function Documentation

◆ check_jwt_claim()

static void check_jwt_claim ( const Json claim,
const char *  expected_audience,
const char *  expected_scope 
)
static

Definition at line 245 of file json_token_test.cc.

◆ check_jwt_header()

static void check_jwt_header ( const Json header)
static

Definition at line 231 of file json_token_test.cc.

◆ check_jwt_signature()

static void check_jwt_signature ( const char *  b64_signature,
RSA rsa_key,
const char *  signed_data,
size_t  signed_data_size 
)
static

Definition at line 285 of file json_token_test.cc.

◆ jwt_creds_check_jwt_claim()

static void jwt_creds_check_jwt_claim ( const Json claim)
static

Definition at line 328 of file json_token_test.cc.

◆ jwt_creds_jwt_encode_and_sign()

static char* jwt_creds_jwt_encode_and_sign ( const grpc_auth_json_key key)
static

Definition at line 319 of file json_token_test.cc.

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 435 of file json_token_test.cc.

◆ parse_json_part_from_jwt()

static Json parse_json_part_from_jwt ( const char *  str,
size_t  len 
)
static

Definition at line 211 of file json_token_test.cc.

◆ service_account_creds_check_jwt_claim()

static void service_account_creds_check_jwt_claim ( const Json claim)
static

Definition at line 324 of file json_token_test.cc.

◆ service_account_creds_jwt_encode_and_sign()

static char* service_account_creds_jwt_encode_and_sign ( const grpc_auth_json_key key)
static

Definition at line 313 of file json_token_test.cc.

◆ test_json_key_str()

static char* test_json_key_str ( const char *  bad_part3)
static

Definition at line 83 of file json_token_test.cc.

◆ test_jwt_creds_jwt_encode_and_sign()

static void test_jwt_creds_jwt_encode_and_sign ( void  )
static

Definition at line 372 of file json_token_test.cc.

◆ test_jwt_encode_and_sign()

static void test_jwt_encode_and_sign ( char *(*)(const grpc_auth_json_key *)  jwt_encode_and_sign_func,
void(*)(const Json &)  check_jwt_claim_func 
)
static

Definition at line 332 of file json_token_test.cc.

◆ test_parse_json_key_failure_bad_json()

static void test_parse_json_key_failure_bad_json ( void  )
static

Definition at line 121 of file json_token_test.cc.

◆ test_parse_json_key_failure_no_client_email()

static void test_parse_json_key_failure_no_client_email ( void  )
static

Definition at line 168 of file json_token_test.cc.

◆ test_parse_json_key_failure_no_client_id()

static void test_parse_json_key_failure_no_client_id ( void  )
static

Definition at line 153 of file json_token_test.cc.

◆ test_parse_json_key_failure_no_private_key()

static void test_parse_json_key_failure_no_private_key ( void  )
static

Definition at line 197 of file json_token_test.cc.

◆ test_parse_json_key_failure_no_private_key_id()

static void test_parse_json_key_failure_no_private_key_id ( void  )
static

Definition at line 182 of file json_token_test.cc.

◆ test_parse_json_key_failure_no_type()

static void test_parse_json_key_failure_no_type ( void  )
static

Definition at line 137 of file json_token_test.cc.

◆ test_parse_json_key_success()

static void test_parse_json_key_success ( void  )
static

Definition at line 98 of file json_token_test.cc.

◆ test_parse_refresh_token_failure_no_client_id()

static void test_parse_refresh_token_failure_no_client_id ( void  )
static

Definition at line 405 of file json_token_test.cc.

◆ test_parse_refresh_token_failure_no_client_secret()

static void test_parse_refresh_token_failure_no_client_secret ( void  )
static

Definition at line 415 of file json_token_test.cc.

◆ test_parse_refresh_token_failure_no_refresh_token()

static void test_parse_refresh_token_failure_no_refresh_token ( void  )
static

Definition at line 425 of file json_token_test.cc.

◆ test_parse_refresh_token_failure_no_type()

static void test_parse_refresh_token_failure_no_type ( void  )
static

Definition at line 395 of file json_token_test.cc.

◆ test_parse_refresh_token_success()

static void test_parse_refresh_token_success ( void  )
static

Definition at line 377 of file json_token_test.cc.

◆ test_service_account_creds_jwt_encode_and_sign()

static void test_service_account_creds_jwt_encode_and_sign ( void  )
static

Definition at line 367 of file json_token_test.cc.

Variable Documentation

◆ test_json_key_str_part1

const char test_json_key_str_part1[]
static
Initial value:
=
"{ \"private_key\": \"-----BEGIN PRIVATE KEY-----"
"\\nMIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAOEvJsnoHnyHkXcp\\n7mJE"
"qg"
"WGjiw71NfXByguekSKho65FxaGbsnSM9SMQAqVk7Q2rG+I0OpsT0LrWQtZ\\nyjSeg/"
"rWBQvS4hle4LfijkP3J5BG+"
"IXDMP8RfziNRQsenAXDNPkY4kJCvKux2xdD\\nOnVF6N7dL3nTYZg+"
"uQrNsMTz9UxVAgMBAAECgYEAzbLewe1xe9vy+2GoSsfib+28\\nDZgSE6Bu/"
"zuFoPrRc6qL9p2SsnV7txrunTyJkkOnPLND9ABAXybRTlcVKP/sGgza\\n/"
"8HpCqFYM9V8f34SBWfD4fRFT+n/"
"73cfRUtGXdXpseva2lh8RilIQfPhNZAncenU\\ngqXjDvpkypEusgXAykECQQD+"

Definition at line 41 of file json_token_test.cc.

◆ test_json_key_str_part2

const char test_json_key_str_part2[]
static
Initial value:
=
"53XxNVnxBHsYb+AYEfklR96yVi8HywjVHP34+OQZ\\nCslxoHQM8s+"
"dBnjfScLu22JqkPv04xyxmt0QAKm9+vTdAkEA4ib7YvEAn2jXzcCI\\nEkoy2L/"
"XydR1GCHoacdfdAwiL2npOdnbvi4ZmdYRPY1LSTO058tQHKVXV7NLeCa3\\nAARh2QJBAMKeDA"
"G"
"W303SQv2cZTdbeaLKJbB5drz3eo3j7dDKjrTD9JupixFbzcGw\\n8FZi5c8idxiwC36kbAL6Hz"
"A"
"ZoX+ofI0CQE6KCzPJTtYNqyShgKAZdJ8hwOcvCZtf\\n6z8RJm0+"
"6YBd38lfh5j8mZd7aHFf6I17j5AQY7oPEc47TjJj/"
"5nZ68ECQQDvYuI3\\nLyK5fS8g0SYbmPOL9TlcHDOqwG0mrX9qpg5DC2fniXNSrrZ64GTDKdzZ"
"Y"
"Ap6LI9W\\nIqv4vr6y38N79TTC\\n-----END PRIVATE KEY-----\\n\", "

Definition at line 52 of file json_token_test.cc.

◆ test_json_key_str_part3

const char test_json_key_str_part3[]
static
Initial value:
=
"\"private_key_id\": \"e6b5137873db8d2ef81e06a47289e6434ec8a165\", "
"\"client_email\": "
"\"777-abaslkan11hlb6nmim3bpspl31ud@developer.gserviceaccount."
"com\", \"client_id\": "
"\"777-abaslkan11hlb6nmim3bpspl31ud.apps.googleusercontent."
"com\", \"type\": \"service_account\" }"

Definition at line 64 of file json_token_test.cc.

◆ test_refresh_token_str

const char test_refresh_token_str[]
static
Initial value:
=
"{ \"client_id\": \"32555999999.apps.googleusercontent.com\","
" \"client_secret\": \"EmssLNjJy1332hD4KFsecret\","
" \"refresh_token\": \"1/Blahblasj424jladJDSGNf-u4Sua3HDA2ngjd42\","
" \"type\": \"authorized_user\"}"

Definition at line 73 of file json_token_test.cc.

◆ test_scope

const char test_scope[] = "myperm1 myperm2"
static

Definition at line 79 of file json_token_test.cc.

◆ test_service_url

const char test_service_url[] = "https://foo.com/foo.v1"
static

Definition at line 81 of file json_token_test.cc.



grpc
Author(s):
autogenerated on Fri May 16 2025 03:01:21