]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-oauth2: test-oauth2-json - Check that callback actually got called
authorAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 27 Sep 2023 07:26:07 +0000 (10:26 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Tue, 3 Oct 2023 08:18:23 +0000 (11:18 +0300)
src/lib-oauth2/test-oauth2-json.c

index 3a2ca1788f01cf823a17b724b468680e46c96c70..121b8a106519113304f9f28021a73ef553ddc655 100644 (file)
@@ -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();