From 2241473ee62b7d5d60d20ef0c264e6080cbba8db Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 24 May 2015 00:56:13 +0100 Subject: [PATCH] Added bad password test --- src/otr/otr.c | 5 ++++- stabbertests/proftest.c | 18 ++++++++++++++++++ stabbertests/test_connect.c | 25 +++++++++++++++++++------ stabbertests/test_connect.h | 3 ++- stabbertests/testsuite.c | 5 ++++- 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/otr/otr.c b/src/otr/otr.c index e568af56..4d97cfb9 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -163,6 +163,8 @@ otr_init(void) log_info("Initialising OTR"); OTRL_INIT; + jid = NULL; + ops.policy = cb_policy; ops.is_logged_in = cb_is_logged_in; ops.inject_message = cb_inject_message; @@ -181,6 +183,7 @@ otr_shutdown(void) { if (jid) { free(jid); + jid = NULL; } } @@ -747,4 +750,4 @@ void otr_free_message(char *message) { otrl_message_free(message); -} \ No newline at end of file +} diff --git a/stabbertests/proftest.c b/stabbertests/proftest.c index 6c44a6ee..e8409907 100644 --- a/stabbertests/proftest.c +++ b/stabbertests/proftest.c @@ -10,6 +10,8 @@ #include #include +#include + #include "config.h" #include "config/preferences.h" @@ -29,6 +31,9 @@ #define XDG_CONFIG_HOME "./stabbertests/files/xdg_config_home" #define XDG_DATA_HOME "./stabbertests/files/xdg_data_home" +char *config_orig; +char *data_orig; + void prof_process_xmpp(void) { @@ -141,6 +146,14 @@ _cleanup_dirs(void) void init_prof_test(void **state) { + if (stbbr_start(5230) != 0) { + assert_true(FALSE); + return; + } + + config_orig = getenv("XDG_CONFIG_HOME"); + data_orig = getenv("XDG_DATA_HOME"); + setenv("XDG_CONFIG_HOME", XDG_CONFIG_HOME, 1); setenv("XDG_DATA_HOME", XDG_DATA_HOME, 1); @@ -196,4 +209,9 @@ close_prof_test(void **state) log_close(); _cleanup_dirs(); + + setenv("XDG_CONFIG_HOME", config_orig, 1); + setenv("XDG_DATA_HOME", data_orig, 1); + + stbbr_stop(); } diff --git a/stabbertests/test_connect.c b/stabbertests/test_connect.c index 5f4027bf..bc145da8 100644 --- a/stabbertests/test_connect.c +++ b/stabbertests/test_connect.c @@ -14,16 +14,11 @@ #include "command/command.h" void -connect_with_jid(void **state) +connect_jid(void **state) { char *connect = "/connect stabber@localhost port 5230"; char *password = "password"; - if (stbbr_start(5230) != 0) { - assert_true(FALSE); - return; - } - stbbr_auth_passwd(password); will_return(ui_ask_password, strdup(password)); @@ -35,3 +30,21 @@ connect_with_jid(void **state) jabber_conn_status_t status = jabber_get_connection_status(); assert_true(status == JABBER_CONNECTED); } + +void +connect_bad_password(void **state) +{ + char *connect = "/connect stabber@localhost port 5230"; + + stbbr_auth_passwd("password"); + will_return(ui_ask_password, strdup("badpassword")); + + expect_cons_show("Connecting as stabber@localhost"); + expect_cons_show_error("Login failed."); + + cmd_process_input(strdup(connect)); + prof_process_xmpp(); + + jabber_conn_status_t status = jabber_get_connection_status(); + assert_true(status == JABBER_DISCONNECTED); +} diff --git a/stabbertests/test_connect.h b/stabbertests/test_connect.h index 9716c6a9..999d9d08 100644 --- a/stabbertests/test_connect.h +++ b/stabbertests/test_connect.h @@ -1 +1,2 @@ -void connect_with_jid(void **state); +void connect_jid(void **state); +void connect_bad_password(void **state); diff --git a/stabbertests/testsuite.c b/stabbertests/testsuite.c index 467884ff..bde4eacf 100644 --- a/stabbertests/testsuite.c +++ b/stabbertests/testsuite.c @@ -15,7 +15,10 @@ int main(int argc, char* argv[]) { const UnitTest all_tests[] = { - unit_test_setup_teardown(connect_with_jid, + unit_test_setup_teardown(connect_jid, + init_prof_test, + close_prof_test), + unit_test_setup_teardown(connect_bad_password, init_prof_test, close_prof_test), };