1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added bad password test

This commit is contained in:
James Booth 2015-05-24 00:56:13 +01:00
parent 520b2d2598
commit 2241473ee6
5 changed files with 47 additions and 9 deletions

View File

@ -163,6 +163,8 @@ otr_init(void)
log_info("Initialising OTR"); log_info("Initialising OTR");
OTRL_INIT; OTRL_INIT;
jid = NULL;
ops.policy = cb_policy; ops.policy = cb_policy;
ops.is_logged_in = cb_is_logged_in; ops.is_logged_in = cb_is_logged_in;
ops.inject_message = cb_inject_message; ops.inject_message = cb_inject_message;
@ -181,6 +183,7 @@ otr_shutdown(void)
{ {
if (jid) { if (jid) {
free(jid); free(jid);
jid = NULL;
} }
} }
@ -747,4 +750,4 @@ void
otr_free_message(char *message) otr_free_message(char *message)
{ {
otrl_message_free(message); otrl_message_free(message);
} }

View File

@ -10,6 +10,8 @@
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <stabber.h>
#include "config.h" #include "config.h"
#include "config/preferences.h" #include "config/preferences.h"
@ -29,6 +31,9 @@
#define XDG_CONFIG_HOME "./stabbertests/files/xdg_config_home" #define XDG_CONFIG_HOME "./stabbertests/files/xdg_config_home"
#define XDG_DATA_HOME "./stabbertests/files/xdg_data_home" #define XDG_DATA_HOME "./stabbertests/files/xdg_data_home"
char *config_orig;
char *data_orig;
void void
prof_process_xmpp(void) prof_process_xmpp(void)
{ {
@ -141,6 +146,14 @@ _cleanup_dirs(void)
void void
init_prof_test(void **state) 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_CONFIG_HOME", XDG_CONFIG_HOME, 1);
setenv("XDG_DATA_HOME", XDG_DATA_HOME, 1); setenv("XDG_DATA_HOME", XDG_DATA_HOME, 1);
@ -196,4 +209,9 @@ close_prof_test(void **state)
log_close(); log_close();
_cleanup_dirs(); _cleanup_dirs();
setenv("XDG_CONFIG_HOME", config_orig, 1);
setenv("XDG_DATA_HOME", data_orig, 1);
stbbr_stop();
} }

View File

@ -14,16 +14,11 @@
#include "command/command.h" #include "command/command.h"
void void
connect_with_jid(void **state) connect_jid(void **state)
{ {
char *connect = "/connect stabber@localhost port 5230"; char *connect = "/connect stabber@localhost port 5230";
char *password = "password"; char *password = "password";
if (stbbr_start(5230) != 0) {
assert_true(FALSE);
return;
}
stbbr_auth_passwd(password); stbbr_auth_passwd(password);
will_return(ui_ask_password, strdup(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(); jabber_conn_status_t status = jabber_get_connection_status();
assert_true(status == JABBER_CONNECTED); 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);
}

View File

@ -1 +1,2 @@
void connect_with_jid(void **state); void connect_jid(void **state);
void connect_bad_password(void **state);

View File

@ -15,7 +15,10 @@
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
const UnitTest all_tests[] = { 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, init_prof_test,
close_prof_test), close_prof_test),
}; };