From 2241473ee62b7d5d60d20ef0c264e6080cbba8db Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 24 May 2015 00:56:13 +0100 Subject: Added bad password test --- stabbertests/proftest.c | 18 ++++++++++++++++++ stabbertests/test_connect.c | 25 +++++++++++++++++++------ stabbertests/test_connect.h | 3 ++- stabbertests/testsuite.c | 5 ++++- 4 files changed, 43 insertions(+), 8 deletions(-) (limited to 'stabbertests') 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), }; -- cgit 1.4.1-2-gfad0 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183