Skip to content

Commit

Permalink
master: test-auth-client - Add progress timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanbosch committed Feb 14, 2019
1 parent 01631cd commit dbd53af
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/master/test-auth-client.c
Expand Up @@ -28,6 +28,7 @@
#include <fcntl.h>

#define TEST_SOCKET "./auth-client-test"
#define CLIENT_PROGRESS_TIMEOUT 30

/*
* Types
Expand Down Expand Up @@ -685,6 +686,8 @@ static void (*const test_functions[])(void) = {
* Test client
*/

struct timeout *to_client_progress = NULL;

static void test_client_deinit(void)
{
}
Expand All @@ -710,6 +713,9 @@ test_client_auth_callback(struct auth_client_request *request,
string_t *resp_b64;
const char *errormsg = NULL;

if (to_client_progress != NULL)
timeout_reset(to_client_progress);

switch (status) {
case AUTH_REQUEST_STATUS_ABORT:
errormsg = "Abort";
Expand Down Expand Up @@ -751,6 +757,9 @@ test_client_auth_connected(struct auth_client *client ATTR_UNUSED,
{
struct login_request *login_req = context;

if (to_client_progress != NULL)
timeout_reset(to_client_progress);

if (login_req->status == 0 && !connected) {
i_assert(login_req->error == NULL);
login_req->error = i_strdup("Connection failed");
Expand All @@ -759,6 +768,15 @@ test_client_auth_connected(struct auth_client *client ATTR_UNUSED,
io_loop_stop(login_req->ioloop);
}

static void
test_client_progress_timeout(void *context ATTR_UNUSED)
{
/* Terminate test due to lack of progress */
test_assert(FALSE);
timeout_remove(&to_client_progress);
io_loop_stop(current_ioloop);
}

static int
test_client_auth_simple(const char *mech, const char *username,
const char *password, const char **error_r)
Expand Down Expand Up @@ -810,6 +828,9 @@ test_client_auth_simple(const char *mech, const char *username,
login_req.username = username;
login_req.password = password;

to_client_progress = timeout_add(CLIENT_PROGRESS_TIMEOUT*1000,
test_client_progress_timeout, NULL);

auth_client = auth_client_init(TEST_SOCKET, 2234, debug);
auth_client_set_connect_timeout(auth_client, 1000);
auth_client_connect(auth_client);
Expand All @@ -835,6 +856,7 @@ test_client_auth_simple(const char *mech, const char *username,
*error_r = t_strdup(login_req.error);

auth_client_deinit(&auth_client);
timeout_remove(&to_client_progress);
io_loop_destroy(&ioloop);
i_free(login_req.error);

Expand Down

0 comments on commit dbd53af

Please sign in to comment.