Skip to content

Commit 76f8e22

Browse files
committed
debug jwt test
1 parent 60eedfd commit 76f8e22

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

library/credentials.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ int zt_jwt_parse(const char *jwt_str, zt_jwt *jwt) {
5757
if (sodium_base642bin((uint8_t *)buf, jwt_len, jwt_str, jwt_len, NULL,
5858
&len, &b64_end, sodium_base64_VARIANT_URLSAFE_NO_PADDING) != 0 ||
5959
*b64_end != '.') {
60+
ZITI_LOG(TRACE, "failed to decode JWT header");
6061
goto error;
6162
}
6263
header = json_tokener_parse_verbose(buf, &json_err);
@@ -68,10 +69,12 @@ int zt_jwt_parse(const char *jwt_str, zt_jwt *jwt) {
6869
NULL,
6970
&len, &b64_end, sodium_base64_VARIANT_URLSAFE_NO_PADDING) != 0 ||
7071
*b64_end != '.') {
72+
ZITI_LOG(TRACE, "failed to decode JWT claims");
7173
goto error;
7274
}
7375
payload = json_tokener_parse_verbose(buf, &json_err);
7476
if (!payload) {
77+
ZITI_LOG(TRACE, "failed to parse JWT claims: %s", json_tokener_error_desc(json_err));
7578
goto error;
7679
}
7780

@@ -108,6 +111,7 @@ int ziti_credential_from_jwt(const char *jwt, ziti_credential_t **cred) {
108111

109112
if (zt_jwt_parse(jwt, &c->jwt) != 0) {
110113
free(c);
114+
*cred = NULL;
111115
return ZITI_JWT_INVALID;
112116
}
113117
c->type = ZITI_CRED_TYPE_JWT;

tests/test_jwt.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
// Copyright (c) 2023. NetFoundry Inc.
1+
// Copyright (c) 2023-2026. NetFoundry Inc
22
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
66
//
7-
// https://www.apache.org/licenses/LICENSE-2.0
7+
// https://www.apache.org/licenses/LICENSE-2.0
88
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
1414

1515
#include "catch2/catch_test_macros.hpp"
1616
#include "catch2/matchers/catch_matchers_string.hpp"
@@ -95,10 +95,11 @@ TEST_CASE("zt_jwt_parse","[model]") {
9595
}
9696

9797
TEST_CASE("jwt cred", "[model]") {
98-
ziti_credential_t *cred;
98+
ziti_log_init(uv_default_loop(), TRACE, NULL);
99+
ziti_credential_t *cred = nullptr;
99100
int rc = ziti_credential_from_jwt(jwt, &cred);
100101
CHECK(rc == 0);
101-
CHECK(cred != nullptr);
102+
REQUIRE(cred != nullptr);
102103
CHECK(cred->type == ZITI_CRED_TYPE_JWT);
103104
CHECK(cstr_equals(&cred->jwt.issuer, "https://fd200fd3-a2d9-457f-bc0b-f9b8ee7d2898.production.netfoundry.io:443"));
104105
ziti_credential_drop(cred);

0 commit comments

Comments
 (0)