Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Build tests with flags -Wall -Werror -Wextra
Browse files Browse the repository at this point in the history
  • Loading branch information
babelouest committed Mar 1, 2024
1 parent 022d4ad commit 33f3331
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 19 deletions.
2 changes: 1 addition & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ IDDAWC_LOCATION=../src
IDDAWC_LIBRARY=$(IDDAWC_LOCATION)/libiddawc.so
CC=gcc
CFLAGS+=-Wall -D_REENTRANT -I$(IDDAWC_INCLUDE) -DDEBUG -g -O0 $(CPPFLAGS)
LDFLAGS=-lc -liddawc -L$(IDDAWC_LOCATION) $(shell pkg-config --libs liborcania) $(shell pkg-config --libs libyder) $(shell pkg-config --libs libulfius) $(shell pkg-config --libs librhonabwy) $(shell pkg-config --libs jansson) $(shell pkg-config --libs check) $(shell pkg-config --libs gnutls)
LDFLAGS=-lc -Wall -Werror -Wextra -liddawc -L$(IDDAWC_LOCATION) $(shell pkg-config --libs liborcania) $(shell pkg-config --libs libyder) $(shell pkg-config --libs libulfius) $(shell pkg-config --libs librhonabwy) $(shell pkg-config --libs jansson) $(shell pkg-config --libs check) $(shell pkg-config --libs gnutls)
VALGRIND_COMMAND=valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all
TARGET=core implicit id_token token load_config load_userinfo flow introspection revocation registration dpop api_request device par ciba session rar
TARGET_TEST=test_core test_implicit test_id_token test_token test_load_config test_load_userinfo test_flow test_introspection test_revocation test_registration test_dpop test_api_request test_device test_par test_ciba test_session test_rar
Expand Down
17 changes: 14 additions & 3 deletions test/api_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <yder.h>
#include <iddawc.h>

#define UNUSED(x) (void)(x)

const char jwk_privkey_str[] = "{\"kty\":\"RSA\",\"n\":\"ANgV1GxZbGBMIqqX5QsNrQQnPLk8UpkqH_60EuaHsI8YnUkPmPVXJ_4z_ziqZizvvjp_RhhXX2DnHEQuYwI-SZaBlK1VJiiWH9E"\
"XrUeazcpEryFUR0I5iBROcgRJfHSvRvC7D83-xg9xC-NGVvIQ2llduYzmaK8rfuiHWlGqow3O2m5os9NTortdQf7BeTniStDokFvZy-I4i24UFkemoNPWZ9MCN0"\
"WTea8n_TQmq9sVHGQtLIFqfblLxbSz_7m4g7_o3WfqlwXkVmCIu1wdzAjZV5BspBGrL0ed5Whpk9-bX69nUDvpcMAaPhuRwZ43e9koVRbVwXCNkne98VAs0_U\""\
Expand Down Expand Up @@ -41,6 +43,7 @@ const char resource_object[] = "{\"Hello\":\"World\"}";

static int callback_resource_service_object_at_header (const struct _u_request * request, struct _u_response * response, void * user_data) {
json_t * j_response = json_loads(resource_object, JSON_DECODE_ANY, NULL);
UNUSED(user_data);
if (u_map_get(request->map_header, I_HEADER_AUTHORIZATION) != NULL) {
ulfius_set_json_body_response(response, 200, j_response);
} else {
Expand All @@ -52,6 +55,7 @@ static int callback_resource_service_object_at_header (const struct _u_request *

static int callback_resource_service_object_at_body (const struct _u_request * request, struct _u_response * response, void * user_data) {
json_t * j_response = json_loads(resource_object, JSON_DECODE_ANY, NULL);
UNUSED(user_data);
if (u_map_get(request->map_post_body, I_BODY_URL_PARAMETER) != NULL) {
ulfius_set_json_body_response(response, 200, j_response);
} else {
Expand All @@ -63,6 +67,7 @@ static int callback_resource_service_object_at_body (const struct _u_request * r

static int callback_resource_service_object_at_url (const struct _u_request * request, struct _u_response * response, void * user_data) {
json_t * j_response = json_loads(resource_object, JSON_DECODE_ANY, NULL);
UNUSED(user_data);
if (u_map_get(request->map_url, I_BODY_URL_PARAMETER) != NULL) {
ulfius_set_json_body_response(response, 200, j_response);
} else {
Expand All @@ -72,9 +77,10 @@ static int callback_resource_service_object_at_url (const struct _u_request * re
return U_CALLBACK_CONTINUE;
}

int callback_resource_service_object_with_dpop (const struct _u_request * request, struct _u_response * response, void * user_data) {
static int callback_resource_service_object_with_dpop (const struct _u_request * request, struct _u_response * response, void * user_data) {
json_t * j_response = json_loads(resource_object, JSON_DECODE_ANY, NULL);
jwt_t * jwt;
UNUSED(user_data);

if (0 == o_strcmp("DPoP "ACCESS_TOKEN, u_map_get(request->map_header, "Authorization")) && u_map_get(request->map_header, "DPoP") != NULL) {
jwt = r_jwt_quick_parse(u_map_get(request->map_header, "DPoP"), R_PARSE_HEADER_JWK, 0);
Expand All @@ -91,8 +97,9 @@ int callback_resource_service_object_with_dpop (const struct _u_request * reques
return U_CALLBACK_CONTINUE;
}

int callback_resource_service_object_with_dpop_nonce (const struct _u_request * request, struct _u_response * response, void * user_data) {
static int callback_resource_service_object_with_dpop_nonce (const struct _u_request * request, struct _u_response * response, void * user_data) {
json_t * j_response = json_loads(resource_object, JSON_DECODE_ANY, NULL);
UNUSED(user_data);
if (0 == o_strcmp("DPoP "ACCESS_TOKEN, u_map_get(request->map_header, "Authorization")) && u_map_get(request->map_header, "DPoP") != NULL) {
jwt_t * jwt = r_jwt_quick_parse(u_map_get(request->map_header, I_HEADER_DPOP), R_PARSE_HEADER_JWK, 0);
if (0 != o_strcmp(DPOP_NONCE, r_jwt_get_claim_str_value(jwt, "nonce"))) {
Expand All @@ -111,6 +118,8 @@ int callback_resource_service_object_with_dpop_nonce (const struct _u_request *
}

static int callback_refresh_token_invalid (const struct _u_request * request, struct _u_response * response, void * user_data) {
UNUSED(request);
UNUSED(user_data);
response->status = 403;
return U_CALLBACK_CONTINUE;
}
Expand All @@ -120,6 +129,8 @@ static int callback_refresh_token_valid (const struct _u_request * request, stru
"access_token", ACCESS_TOKEN_2,
"token_type", TOKEN_TYPE,
"expires_in", EXPIRES_IN);
UNUSED(request);
UNUSED(user_data);
ulfius_set_json_body_response(response, 200, result);
json_decref(result);
return U_CALLBACK_CONTINUE;
Expand Down Expand Up @@ -576,7 +587,7 @@ static Suite *iddawc_suite(void)
return s;
}

int main(int argc, char *argv[])
int main(void)
{
int number_failed;
Suite *s;
Expand Down
25 changes: 24 additions & 1 deletion test/ciba.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <iddawc.h>
#include <rhonabwy.h>

#define UNUSED(x) (void)(x)

#define CIBA_ERROR "invalid_request"
#define CIBA_ERROR_DESCRIPTION "invalid_request description"
#define CIBA_ERROR_URI "https://as.tld/#error"
Expand Down Expand Up @@ -63,6 +65,7 @@ const char jwk_key_128[] = "{\"kty\":\"oct\",\"alg\":\"HS256\",\"k\":\"GawgguFyG

int callback_ciba_login_hint_valid (const struct _u_request * request, struct _u_response * response, void * user_data) {
json_t * j_response = json_pack("{sssisi}", "auth_req_id", CIBA_AUTH_REQ_ID, "expires_in", CIBA_AUTH_REQ_EXPIRES_IN, "interval", CIBA_AUTH_REQ_INTERVAL);
UNUSED(user_data);
ck_assert_str_eq(CIBA_LOGIN_HINT, u_map_get(request->map_post_body, "login_hint"));
ck_assert_str_eq(CIBA_REQUESTED_EXPIRY_STR, u_map_get(request->map_post_body, "requested_expiry"));
ck_assert_str_eq(CIBA_BINDING_MESSAGE, u_map_get(request->map_post_body, "binding_message"));
Expand All @@ -74,6 +77,7 @@ int callback_ciba_login_hint_valid (const struct _u_request * request, struct _u

int callback_ciba_jwt_sign_secret_valid (const struct _u_request * request, struct _u_response * response, void * user_data) {
jwt_t * jwt = NULL;
UNUSED(user_data);
ck_assert_ptr_ne(NULL, jwt = r_jwt_quick_parse(u_map_get(request->map_post_body, "request"), R_PARSE_NONE, 0));
ck_assert_int_eq(R_JWT_TYPE_SIGN, r_jwt_get_type(jwt));
ck_assert_int_eq(R_JWA_ALG_HS256, r_jwt_get_sign_alg(jwt));
Expand All @@ -90,6 +94,7 @@ int callback_ciba_jwt_sign_secret_valid (const struct _u_request * request, stru

int callback_ciba_jwt_sign_pubkey_valid (const struct _u_request * request, struct _u_response * response, void * user_data) {
jwt_t * jwt = NULL;
UNUSED(user_data);
ck_assert_ptr_ne(NULL, jwt = r_jwt_quick_parse(u_map_get(request->map_post_body, "request"), R_PARSE_NONE, 0));
ck_assert_int_eq(R_JWT_TYPE_SIGN, r_jwt_get_type(jwt));
ck_assert_int_eq(R_JWA_ALG_RS256, r_jwt_get_sign_alg(jwt));
Expand All @@ -106,6 +111,7 @@ int callback_ciba_jwt_sign_pubkey_valid (const struct _u_request * request, stru

int callback_ciba_jwt_encrypt_secret_valid (const struct _u_request * request, struct _u_response * response, void * user_data) {
jwt_t * jwt = NULL;
UNUSED(user_data);
ck_assert_ptr_ne(NULL, jwt = r_jwt_quick_parse(u_map_get(request->map_post_body, "request"), R_PARSE_NONE, 0));
ck_assert_int_eq(R_JWT_TYPE_ENCRYPT, r_jwt_get_type(jwt));
ck_assert_int_eq(R_JWA_ALG_A128GCMKW, r_jwt_get_enc_alg(jwt));
Expand All @@ -118,6 +124,7 @@ int callback_ciba_jwt_encrypt_secret_valid (const struct _u_request * request, s

int callback_ciba_jwt_encrypt_pubkey_valid (const struct _u_request * request, struct _u_response * response, void * user_data) {
jwt_t * jwt = NULL;
UNUSED(user_data);
ck_assert_ptr_ne(NULL, jwt = r_jwt_quick_parse(u_map_get(request->map_post_body, "request"), R_PARSE_NONE, 0));
ck_assert_int_eq(R_JWT_TYPE_NESTED_SIGN_THEN_ENCRYPT, r_jwt_get_type(jwt));
ck_assert_int_eq(R_JWA_ALG_RSA_OAEP_256, r_jwt_get_enc_alg(jwt));
Expand All @@ -130,6 +137,7 @@ int callback_ciba_jwt_encrypt_pubkey_valid (const struct _u_request * request, s

int callback_ciba_id_token_hint_valid (const struct _u_request * request, struct _u_response * response, void * user_data) {
json_t * j_response = json_pack("{sssisi}", "auth_req_id", CIBA_AUTH_REQ_ID, "expires_in", CIBA_AUTH_REQ_EXPIRES_IN, "interval", CIBA_AUTH_REQ_INTERVAL);
UNUSED(user_data);
ck_assert_str_eq(CIBA_ID_TOKEN_HINT, u_map_get(request->map_post_body, "id_token_hint"));
ck_assert_str_eq(CIBA_REQUESTED_EXPIRY_STR, u_map_get(request->map_post_body, "requested_expiry"));
ck_assert_str_eq(CIBA_BINDING_MESSAGE, u_map_get(request->map_post_body, "binding_message"));
Expand All @@ -140,6 +148,7 @@ int callback_ciba_id_token_hint_valid (const struct _u_request * request, struct
}

int callback_ciba_login_hint_token_valid (const struct _u_request * request, struct _u_response * response, void * user_data) {
UNUSED(user_data);
jwt_t * jwt = NULL;
ck_assert_ptr_ne(NULL, jwt = r_jwt_quick_parse(u_map_get(request->map_post_body, "login_hint_token"), R_PARSE_NONE, 0));
ck_assert_str_eq(CIBA_REQUESTED_EXPIRY_STR, u_map_get(request->map_post_body, "requested_expiry"));
Expand All @@ -153,6 +162,7 @@ int callback_ciba_login_hint_token_valid (const struct _u_request * request, str
}

int callback_ciba_token_valid (const struct _u_request * request, struct _u_response * response, void * user_data) {
UNUSED(user_data);
ck_assert_str_eq("urn:openid:params:grant-type:ciba", u_map_get(request->map_post_body, "grant_type"));
ck_assert_str_eq(CIBA_AUTH_REQ_ID, u_map_get(request->map_post_body, "auth_req_id"));
json_t * result = json_pack("{sssssiss}",
Expand All @@ -167,46 +177,59 @@ int callback_ciba_token_valid (const struct _u_request * request, struct _u_resp

int callback_ciba_token_auth_pending (const struct _u_request * request, struct _u_response * response, void * user_data) {
json_t * result = json_pack("{ss}", "error", ERROR_AUTH_PENDING);
UNUSED(request);
UNUSED(user_data);
ulfius_set_json_body_response(response, 400, result);
json_decref(result);
return U_CALLBACK_CONTINUE;
}

int callback_ciba_token_slow_down (const struct _u_request * request, struct _u_response * response, void * user_data) {
json_t * result = json_pack("{ss}", "error", ERROR_SLOW_DOWN);
UNUSED(request);
UNUSED(user_data);
ulfius_set_json_body_response(response, 400, result);
json_decref(result);
return U_CALLBACK_CONTINUE;
}

int callback_ciba_token_expired_token (const struct _u_request * request, struct _u_response * response, void * user_data) {
json_t * result = json_pack("{ss}", "error", ERROR_EXPIRED_TOKEN);
UNUSED(request);
UNUSED(user_data);
ulfius_set_json_body_response(response, 400, result);
json_decref(result);
return U_CALLBACK_CONTINUE;
}

int callback_ciba_token_access_denied (const struct _u_request * request, struct _u_response * response, void * user_data) {
json_t * result = json_pack("{ss}", "error", ERROR_ACCESS_DENIED);
UNUSED(request);
UNUSED(user_data);
ulfius_set_json_body_response(response, 400, result);
json_decref(result);
return U_CALLBACK_CONTINUE;
}

int callback_ciba_invalid (const struct _u_request * request, struct _u_response * response, void * user_data) {
json_t * j_error = json_pack("{ssssss}", "error", CIBA_ERROR, "error_description", CIBA_ERROR_DESCRIPTION, "error_uri", CIBA_ERROR_URI);
UNUSED(request);
UNUSED(user_data);
ulfius_set_json_body_response(response, 400, j_error);
json_decref(j_error);
return U_CALLBACK_CONTINUE;
}

int callback_ciba_unauthorized (const struct _u_request * request, struct _u_response * response, void * user_data) {
UNUSED(request);
UNUSED(user_data);
response->status = 403;
return U_CALLBACK_CONTINUE;
}

int callback_ciba_jwt_auth_code_ok (const struct _u_request * request, struct _u_response * response, void * user_data) {
json_t * j_response = json_pack("{sssisi}", "auth_req_id", CIBA_AUTH_REQ_ID, "expires_in", CIBA_AUTH_REQ_EXPIRES_IN, "interval", CIBA_AUTH_REQ_INTERVAL);
UNUSED(user_data);

if (0 == o_strcmp(u_map_get(request->map_post_body, "client_assertion_type"), "urn:ietf:params:oauth:client-assertion-type:jwt-bearer") && o_strlen(u_map_get(request->map_post_body, "client_assertion"))) {
jwt_t * jwt;
Expand Down Expand Up @@ -1089,7 +1112,7 @@ static Suite *iddawc_suite(void)
return s;
}

int main(int argc, char *argv[])
int main(void)
{
int number_failed;
Suite *s;
Expand Down
2 changes: 1 addition & 1 deletion test/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3033,7 +3033,7 @@ static Suite *iddawc_suite(void)
return s;
}

int main(int argc, char *argv[])
int main(void)
{
int number_failed;
Suite *s;
Expand Down
18 changes: 17 additions & 1 deletion test/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <yder.h>
#include <iddawc.h>

#define UNUSED(x) (void)(x)

#define DEVICE_ERROR "invalid_request"
#define DEVICE_ERROR_DESCRIPTION "invalid_request description"
#define DEVICE_ERROR_URI "https://as.tld/#error"
Expand Down Expand Up @@ -59,6 +61,8 @@ int callback_device_token_valid (const struct _u_request * request, struct _u_re
"token_type", TOKEN_TYPE,
"expires_in", EXPIRES_IN,
"refresh_token", REFRESH_TOKEN);
UNUSED(request);
UNUSED(user_data);
ulfius_set_json_body_response(response, 200, result);
json_decref(result);
return U_CALLBACK_CONTINUE;
Expand All @@ -68,6 +72,8 @@ int callback_device_token_encrypted_valid (const struct _u_request * request, st
jwe_t * jwe_at, * jwe_rt;
jwk_t * jwk;
char * at_t, * rt_t;
UNUSED(request);
UNUSED(user_data);
ck_assert_int_eq(r_jwe_init(&jwe_at), RHN_OK);
ck_assert_int_eq(r_jwe_init(&jwe_rt), RHN_OK);
ck_assert_int_eq(r_jwk_init(&jwk), RHN_OK);
Expand Down Expand Up @@ -102,6 +108,8 @@ int callback_device_token_encrypted_valid (const struct _u_request * request, st

int callback_device_token_invalid (const struct _u_request * request, struct _u_response * response, void * user_data) {
json_t * j_error = json_pack("{ssssss}", "error", DEVICE_ERROR, "error_description", DEVICE_ERROR_DESCRIPTION, "error_uri", DEVICE_ERROR_URI);
UNUSED(request);
UNUSED(user_data);
ulfius_set_json_body_response(response, 400, j_error);
json_decref(j_error);
return U_CALLBACK_CONTINUE;
Expand All @@ -115,6 +123,8 @@ int callback_device_valid (const struct _u_request * request, struct _u_response
"verification_uri_complete", DEVICE_AUTH_VERIFICATION_URI_COMPLETE,
"expires_in", DEVICE_AUTH_EXPIRES_IN,
"interval", DEVICE_AUTH_INTERVAL);
UNUSED(request);
UNUSED(user_data);
ulfius_set_json_body_response(response, 200, j_error);
json_decref(j_error);
return U_CALLBACK_CONTINUE;
Expand All @@ -129,6 +139,8 @@ int callback_device_claims_resource_valid (const struct _u_request * request, st
"expires_in", DEVICE_AUTH_EXPIRES_IN,
"interval", DEVICE_AUTH_INTERVAL), * j_claims = json_pack("{s{so}s{s{so}}}", "userinfo", CLAIM1, json_loads(CLAIM1_CONTENT, JSON_DECODE_ANY, NULL), "id_token", CLAIM2, "essential", json_false());
char * str_claims = json_dumps(j_claims, JSON_COMPACT);
UNUSED(request);
UNUSED(user_data);
ck_assert_str_eq(u_map_get(request->map_post_body, "claims"), str_claims);
ck_assert_str_eq(u_map_get(request->map_post_body, "resource"), RESOURCE_INDICATOR);
ulfius_set_json_body_response(response, 200, j_error);
Expand All @@ -140,12 +152,16 @@ int callback_device_claims_resource_valid (const struct _u_request * request, st

int callback_device_invalid (const struct _u_request * request, struct _u_response * response, void * user_data) {
json_t * j_error = json_pack("{ssssss}", "error", DEVICE_ERROR, "error_description", DEVICE_ERROR_DESCRIPTION, "error_uri", DEVICE_ERROR_URI);
UNUSED(request);
UNUSED(user_data);
ulfius_set_json_body_response(response, 400, j_error);
json_decref(j_error);
return U_CALLBACK_CONTINUE;
}

int callback_device_unauthorized (const struct _u_request * request, struct _u_response * response, void * user_data) {
UNUSED(request);
UNUSED(user_data);
response->status = 403;
return U_CALLBACK_CONTINUE;
}
Expand Down Expand Up @@ -493,7 +509,7 @@ static Suite *iddawc_suite(void)
return s;
}

int main(int argc, char *argv[])
int main(void)
{
int number_failed;
Suite *s;
Expand Down
2 changes: 1 addition & 1 deletion test/dpop.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ static Suite *iddawc_suite(void)
return s;
}

int main(int argc, char *argv[])
int main(void)
{
int number_failed;
Suite *s;
Expand Down
12 changes: 11 additions & 1 deletion test/flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <rhonabwy.h>
#include <iddawc.h>

#define UNUSED(x) (void)(x)

#define SCOPE_LIST "openid g_profile"
#define STATE "stateXyz1234"
#define REDIRECT_URI "https://iddawc.tld"
Expand Down Expand Up @@ -183,6 +185,8 @@ int callback_oauth2_redirect_external_auth (const struct _u_request * request, s

int callback_userinfo_valid_json (const struct _u_request * request, struct _u_response * response, void * user_data) {
json_t * j_response = json_loads(userinfo_json, JSON_DECODE_ANY, NULL);
UNUSED(request);
UNUSED(user_data);
ulfius_set_json_body_response(response, 200, j_response);
json_decref(j_response);
return U_CALLBACK_CONTINUE;
Expand Down Expand Up @@ -217,6 +221,8 @@ int callback_oauth2_token_code_id_token_ok (const struct _u_request * request, s
char * grants = NULL, * jwt_str;
time_t now;
json_t * result;
UNUSED(request);
UNUSED(user_data);

r_jwt_init(&jwt);
r_jwk_init(&jwk);
Expand Down Expand Up @@ -247,6 +253,8 @@ int callback_oauth2_token_code_id_token_ok (const struct _u_request * request, s

int callback_openid_configuration_valid (const struct _u_request * request, struct _u_response * response, void * user_data) {
json_t * j_response = json_loads(openid_configuration_valid, JSON_DECODE_ANY, NULL);
UNUSED(request);
UNUSED(user_data);
ulfius_set_json_body_response(response, 200, j_response);
json_decref(j_response);
return U_CALLBACK_CONTINUE;
Expand All @@ -256,6 +264,8 @@ int callback_openid_jwks_valid (const struct _u_request * request, struct _u_res
jwk_t * jwk;
jwks_t * jwks;
json_t * j_response;
UNUSED(request);
UNUSED(user_data);

r_jwk_init(&jwk);
r_jwks_init(&jwks);
Expand Down Expand Up @@ -791,7 +801,7 @@ static Suite *iddawc_suite(void)
return s;
}

int main(int argc, char *argv[])
int main(void)
{
int number_failed;
Suite *s;
Expand Down
Loading

0 comments on commit 33f3331

Please sign in to comment.