From: Aki Tuomi Date: Wed, 27 Sep 2023 07:26:07 +0000 (+0300) Subject: lib-oauth2: test-oauth2-json - Check that callback actually got called X-Git-Tag: 2.4.0~2572 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6edd1b7199b24ba15fa001e57e219f6eda0ffdc;p=thirdparty%2Fdovecot%2Fcore.git lib-oauth2: test-oauth2-json - Check that callback actually got called --- diff --git a/src/lib-oauth2/test-oauth2-json.c b/src/lib-oauth2/test-oauth2-json.c index 3a2ca1788f..121b8a1065 100644 --- a/src/lib-oauth2/test-oauth2-json.c +++ b/src/lib-oauth2/test-oauth2-json.c @@ -7,11 +7,14 @@ #include "oauth2-private.h" #include "test-common.h" +static bool cb_got_called = FALSE; + static void test_oauth_json_valid_parsed(struct oauth2_request *req ATTR_UNUSED, const char *error) { test_assert(error == NULL); + cb_got_called = TRUE; } static void test_oauth2_json_valid(void) @@ -69,6 +72,7 @@ static void test_oauth2_json_valid(void) req->is = test_istream_create_data(test_input, strlen(test_input)); req->parser = json_parser_init(req->is); req->json_parsed_cb = test_oauth_json_valid_parsed; + cb_got_called = FALSE; /* Parse the JSON response */ for (pos = 0; pos <= strlen(test_input); pos +=2) { @@ -78,6 +82,7 @@ static void test_oauth2_json_valid(void) break; } + test_assert(cb_got_called); /* Verify the parsed fields */ pfields = array_get(&req->fields, &count); test_assert(count == fields_count); @@ -101,6 +106,7 @@ test_oauth_json_has_error(struct oauth2_request *req, const char *expected_error = req->req_context; test_assert(error != NULL); test_assert_strcmp(expected_error, error); + cb_got_called = TRUE; } static void test_oauth2_json_error(void) @@ -121,6 +127,7 @@ static void test_oauth2_json_error(void) req->parser = json_parser_init(req->is); req->req_context = "invalid_request"; req->json_parsed_cb = test_oauth_json_has_error; + cb_got_called = FALSE; /* Parse the JSON response */ for (size_t pos = 0; pos <= strlen(test_input_1); pos +=2) { @@ -130,7 +137,7 @@ static void test_oauth2_json_error(void) break; } - + test_assert(cb_got_called); pool_unref(&pool); pool = pool_alloconly_create_clean("oauth2 json test", 1024); @@ -141,6 +148,7 @@ static void test_oauth2_json_error(void) req->parser = json_parser_init(req->is); req->req_context = "Access denied"; req->json_parsed_cb = test_oauth_json_has_error; + cb_got_called = FALSE; /* Parse the JSON response */ for (size_t pos = 0; pos <= strlen(test_input_2); pos +=2) { @@ -150,6 +158,7 @@ static void test_oauth2_json_error(void) break; } + test_assert(cb_got_called); pool_unref(&pool); test_end();