Skip to content

Commit

Permalink
master: test-auth-master - Add support for retrying passdb lookups.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanbosch committed Mar 8, 2019
1 parent e45f726 commit 37a5be8
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/master/test-auth-master.c
Expand Up @@ -74,7 +74,8 @@ static void server_connection_deinit(struct server_connection **_conn);
static void test_client_deinit(void);

static int
test_client_passdb_lookup_simple(const char *user, const char **error_r);
test_client_passdb_lookup_simple(const char *user, bool retry,
const char **error_r);
static int
test_client_userdb_lookup_simple(const char *user, const char **error_r);
static int test_client_user_list_simple(void);
Expand Down Expand Up @@ -104,7 +105,7 @@ test_client_connection_refused(void)
const char *error;
int ret;

ret = test_client_passdb_lookup_simple("harrie", &error);
ret = test_client_passdb_lookup_simple("harrie", FALSE, &error);
test_out_reason("run (ret == -1)", ret == -1, error);

return FALSE;
Expand Down Expand Up @@ -152,7 +153,7 @@ test_client_connection_timed_out(void)
io_loop_time_refresh();
time = ioloop_time;

ret = test_client_passdb_lookup_simple("harrie", &error);
ret = test_client_passdb_lookup_simple("harrie", FALSE, &error);
test_out_reason("run (ret == -1)", ret == -1, error);

io_loop_time_refresh();
Expand Down Expand Up @@ -207,7 +208,7 @@ test_client_bad_version(void)
const char *error;
int ret;

ret = test_client_passdb_lookup_simple("harrie", &error);
ret = test_client_passdb_lookup_simple("harrie", FALSE, &error);
test_out_reason("run (ret == -1)", ret == -1, error);
return FALSE;
}
Expand Down Expand Up @@ -267,7 +268,7 @@ test_client_disconnect_version(void)
const char *error;
int ret;

ret = test_client_passdb_lookup_simple("harrie", &error);
ret = test_client_passdb_lookup_simple("harrie", FALSE, &error);
test_out_reason("run (ret == -1)", ret == -1, error);
return FALSE;
}
Expand Down Expand Up @@ -381,7 +382,7 @@ test_client_passdb_fail(void)
const char *error;
int ret;

ret = test_client_passdb_lookup_simple("harrie", &error);
ret = test_client_passdb_lookup_simple("harrie", FALSE, &error);
test_out("run (ret == -2)", ret == -2);
test_assert(error != NULL &&
strcmp(error, "You shall not pass!!") == 0);
Expand All @@ -395,7 +396,7 @@ test_client_passdb_notfound(void)
const char *error;
int ret;

ret = test_client_passdb_lookup_simple("henk", &error);
ret = test_client_passdb_lookup_simple("henk", FALSE, &error);
test_out("run (ret == 0)", ret == 0);
test_assert(error == NULL);

Expand All @@ -408,7 +409,7 @@ test_client_passdb_timeout(void)
const char *error;
int ret;

ret = test_client_passdb_lookup_simple("holger", &error);
ret = test_client_passdb_lookup_simple("holger", FALSE, &error);
test_out("run (ret == -1)", ret == -1);
test_assert(error == NULL);

Expand Down Expand Up @@ -779,7 +780,7 @@ test_client_passdb_lookup(void)
const char *error;
int ret;

ret = test_client_passdb_lookup_simple("harrie", &error);
ret = test_client_passdb_lookup_simple("harrie", FALSE, &error);
test_out("run (ret > 0)", ret > 0);

return FALSE;
Expand Down Expand Up @@ -1035,7 +1036,8 @@ static void test_client_deinit(void)
}

static int
test_client_passdb_lookup_simple(const char *username, const char **error_r)
test_client_passdb_lookup_simple(const char *username, bool retry,
const char **error_r)
{
struct auth_master_connection *auth_conn;
enum auth_master_flags flags = 0;
Expand All @@ -1057,6 +1059,10 @@ test_client_passdb_lookup_simple(const char *username, const char **error_r)
auth_master_set_timeout(auth_conn, 1000);
ret = auth_master_pass_lookup(auth_conn, username, &info,
pool, &fields);
if (ret < 0 && retry) {
ret = auth_master_pass_lookup(auth_conn, username, &info,
pool, &fields);
}
auth_master_deinit(&auth_conn);

*error_r = (ret < 0 ? t_strdup(fields[0]) : NULL);
Expand Down

0 comments on commit 37a5be8

Please sign in to comment.