From 12c9530819587c194de4f3781e5c5bf279dbea77 Mon Sep 17 00:00:00 2001 From: Ben Collins Date: Wed, 8 Jan 2025 21:46:16 -0500 Subject: [PATCH] coverage: Rework some issues and add checks - 100% function coverage - Allow key_ops we don't recognize to be ignored Signed-off-by: Ben Collins --- libjwt/jwks.c | 4 ++-- tests/jwt_crypto.c | 1 + tests/jwt_jwks.c | 12 ++++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libjwt/jwks.c b/libjwt/jwks.c index f8396575..ce0135f1 100644 --- a/libjwt/jwks.c +++ b/libjwt/jwks.c @@ -18,12 +18,12 @@ static jwk_key_op_t jwk_key_op_j(json_t *j_op) const char *op; if (!j_op || !json_is_string(j_op)) - return JWK_KEY_OP_INVALID; + return JWK_KEY_OP_NONE; op = json_string_value(j_op); if (op == NULL) - return JWK_KEY_OP_INVALID; + return JWK_KEY_OP_NONE; if (!jwt_strcmp(op, "sign")) return JWK_KEY_OP_SIGN; diff --git a/tests/jwt_crypto.c b/tests/jwt_crypto.c index 4eaf71c5..3c3cf976 100644 --- a/tests/jwt_crypto.c +++ b/tests/jwt_crypto.c @@ -26,6 +26,7 @@ START_TEST(test_jwt_ops) type = jwt_get_crypto_ops_t(); ck_assert_int_eq(type, op->type); + ck_assert_int_ne(jwt_crypto_ops_supports_jwk(), 0); } /* Assert that this fails */ diff --git a/tests/jwt_jwks.c b/tests/jwt_jwks.c index e0c6a5da..ed2ca7a6 100644 --- a/tests/jwt_jwks.c +++ b/tests/jwt_jwks.c @@ -44,6 +44,12 @@ static void __jwks_check(const char *json, const char *pem) ret = strcmp(jwks_item_pem(item), test_data.key); free_key(); ck_assert_int_eq(ret, 0); + + if (jwks_item_alg(item) == JWT_ALG_ES256) { + ck_assert_str_eq(jwks_item_curve(item), "P-256"); + ck_assert_int_eq(jwks_item_kty(item), JWK_KEY_TYPE_EC); + ck_assert_int_eq(jwks_item_key_bits(item), 256); + } } /* Should only be one key in the set */ @@ -205,7 +211,6 @@ END_TEST START_TEST(test_jwks_key_op_bad_type) { const jwk_item_t *item; - const char *msg = "JWK has an invalid value in key_op"; const char *kid = "264265c2-4ef0-4751-adbd-9739550afe5b"; SET_OPS(); @@ -215,9 +220,8 @@ START_TEST(test_jwks_key_op_bad_type) item = jwks_item_get(g_jwk_set, 0); ck_assert_ptr_nonnull(item); - /* One item had a bad type (numeric). */ - ck_assert(jwks_item_error(item)); - ck_assert_str_eq(jwks_item_error_msg(item), msg); + /* The bad key_op is ignored. */ + ck_assert(!jwks_item_error(item)); /* Only these ops set. */ ck_assert_int_eq(jwks_item_key_ops(item),