mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Moved _ask_password to UI module
This commit is contained in:
parent
eff2ef3859
commit
079ea5304b
@ -44,7 +44,6 @@
|
|||||||
#include "xmpp/xmpp.h"
|
#include "xmpp/xmpp.h"
|
||||||
#include "xmpp/bookmark.h"
|
#include "xmpp/bookmark.h"
|
||||||
|
|
||||||
static char * _ask_password(void);
|
|
||||||
static void _update_presence(const resource_presence_t presence,
|
static void _update_presence(const resource_presence_t presence,
|
||||||
const char * const show, gchar **args);
|
const char * const show, gchar **args);
|
||||||
static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help,
|
static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help,
|
||||||
@ -80,12 +79,12 @@ cmd_connect(gchar **args, struct cmd_help_t help)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (account->password == NULL) {
|
if (account->password == NULL) {
|
||||||
account->password = _ask_password();
|
account->password = ui_ask_password();
|
||||||
}
|
}
|
||||||
cons_show("Connecting with account %s as %s", account->name, jid);
|
cons_show("Connecting with account %s as %s", account->name, jid);
|
||||||
conn_status = jabber_connect_with_account(account);
|
conn_status = jabber_connect_with_account(account);
|
||||||
} else {
|
} else {
|
||||||
char *passwd = _ask_password();
|
char *passwd = ui_ask_password();
|
||||||
jid = strdup(lower);
|
jid = strdup(lower);
|
||||||
cons_show("Connecting as %s", jid);
|
cons_show("Connecting as %s", jid);
|
||||||
conn_status = jabber_connect_with_details(jid, passwd, altdomain);
|
conn_status = jabber_connect_with_details(jid, passwd, altdomain);
|
||||||
@ -2243,19 +2242,6 @@ cmd_xa(gchar **args, struct cmd_help_t help)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function that asks the user for a password and saves it in passwd
|
|
||||||
static char *
|
|
||||||
_ask_password(void) {
|
|
||||||
char *passwd = malloc(sizeof(char) * (MAX_PASSWORD_SIZE + 1));
|
|
||||||
status_bar_get_password();
|
|
||||||
status_bar_refresh();
|
|
||||||
inp_block();
|
|
||||||
inp_get_password(passwd);
|
|
||||||
inp_non_block();
|
|
||||||
|
|
||||||
return passwd;
|
|
||||||
}
|
|
||||||
|
|
||||||
// helper function for status change commands
|
// helper function for status change commands
|
||||||
static void
|
static void
|
||||||
_update_presence(const resource_presence_t resource_presence,
|
_update_presence(const resource_presence_t resource_presence,
|
||||||
|
@ -1330,6 +1330,19 @@ ui_win_unread(int index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
ui_ask_password(void)
|
||||||
|
{
|
||||||
|
char *passwd = malloc(sizeof(char) * (MAX_PASSWORD_SIZE + 1));
|
||||||
|
status_bar_get_password();
|
||||||
|
status_bar_refresh();
|
||||||
|
inp_block();
|
||||||
|
inp_get_password(passwd);
|
||||||
|
inp_non_block();
|
||||||
|
|
||||||
|
return passwd;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_ui_draw_win_title(void)
|
_ui_draw_win_title(void)
|
||||||
{
|
{
|
||||||
|
@ -80,6 +80,7 @@ char * ui_recipient(int index);
|
|||||||
void ui_close_win(int index);
|
void ui_close_win(int index);
|
||||||
gboolean ui_win_exists(int index);
|
gboolean ui_win_exists(int index);
|
||||||
int ui_win_unread(int index);
|
int ui_win_unread(int index);
|
||||||
|
char * ui_ask_password(void);
|
||||||
|
|
||||||
// ui events
|
// ui events
|
||||||
void ui_contact_typing(const char * const from);
|
void ui_contact_typing(const char * const from);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <cmocka.h>
|
#include <cmocka.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#include "xmpp/xmpp.h"
|
#include "xmpp/xmpp.h"
|
||||||
@ -14,7 +15,7 @@ static void test_with_connection_status(jabber_conn_status_t status)
|
|||||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
|
|
||||||
will_return(jabber_get_connection_status, status);
|
will_return(jabber_get_connection_status, status);
|
||||||
expect_string(cons_show, msg, "You are either connected already, or a login is in process.");
|
expect_string(cons_show, output, "You are either connected already, or a login is in process.");
|
||||||
|
|
||||||
gboolean result = cmd_connect(NULL, *help);
|
gboolean result = cmd_connect(NULL, *help);
|
||||||
assert_true(result);
|
assert_true(result);
|
||||||
@ -41,39 +42,28 @@ void cmd_connect_shows_message_when_undefined(void **state)
|
|||||||
{
|
{
|
||||||
test_with_connection_status(JABBER_UNDEFINED);
|
test_with_connection_status(JABBER_UNDEFINED);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
void cmd_rooms_uses_account_default_when_no_arg(void **state)
|
void cmd_connect_when_no_account(void **state)
|
||||||
{
|
{
|
||||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
ProfAccount *account = malloc(sizeof(ProfAccount));
|
gchar *args[] = { "user@server.org", NULL };
|
||||||
account->muc_service = "default_conf_server";
|
|
||||||
gchar *args[] = { NULL };
|
|
||||||
|
|
||||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
will_return(jabber_get_connection_status, JABBER_DISCONNECTED);
|
||||||
will_return(jabber_get_account_name, "account_name");
|
|
||||||
will_return(accounts_get_account, account);
|
|
||||||
expect_string(iq_room_list_request, conferencejid, "default_conf_server");
|
|
||||||
|
|
||||||
gboolean result = cmd_rooms(args, *help);
|
expect_string(accounts_get_account, name, "user@server.org");
|
||||||
|
will_return(accounts_get_account, NULL);
|
||||||
|
|
||||||
assert_true(result);
|
will_return(ui_ask_password, strdup("password"));
|
||||||
|
|
||||||
free(help);
|
expect_string(cons_show, output, "Connecting as user@server.org");
|
||||||
free(account);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cmd_rooms_arg_used_when_passed(void **state)
|
expect_string(jabber_connect_with_details, jid, "user@server.org");
|
||||||
{
|
expect_string(jabber_connect_with_details, passwd, "password");
|
||||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
expect_any(jabber_connect_with_details, altdomain);
|
||||||
gchar *args[] = { "conf_server_arg" };
|
will_return(jabber_connect_with_details, JABBER_CONNECTING);
|
||||||
|
|
||||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
|
||||||
expect_string(iq_room_list_request, conferencejid, "conf_server_arg");
|
|
||||||
|
|
||||||
gboolean result = cmd_rooms(args, *help);
|
|
||||||
|
|
||||||
|
gboolean result = cmd_connect(args, *help);
|
||||||
assert_true(result);
|
assert_true(result);
|
||||||
|
|
||||||
free(help);
|
free(help);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
@ -2,3 +2,4 @@ void cmd_connect_shows_message_when_disconnecting(void **state);
|
|||||||
void cmd_connect_shows_message_when_connecting(void **state);
|
void cmd_connect_shows_message_when_connecting(void **state);
|
||||||
void cmd_connect_shows_message_when_connected(void **state);
|
void cmd_connect_shows_message_when_connected(void **state);
|
||||||
void cmd_connect_shows_message_when_undefined(void **state);
|
void cmd_connect_shows_message_when_undefined(void **state);
|
||||||
|
void cmd_connect_when_no_account(void **state);
|
||||||
|
@ -14,7 +14,7 @@ static void test_with_connection_status(jabber_conn_status_t status)
|
|||||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
|
|
||||||
will_return(jabber_get_connection_status, status);
|
will_return(jabber_get_connection_status, status);
|
||||||
expect_string(cons_show, msg, "You are not currently connected.");
|
expect_string(cons_show, output, "You are not currently connected.");
|
||||||
|
|
||||||
gboolean result = cmd_rooms(NULL, *help);
|
gboolean result = cmd_rooms(NULL, *help);
|
||||||
assert_true(result);
|
assert_true(result);
|
||||||
|
@ -18,6 +18,7 @@ int main(int argc, char* argv[]) {
|
|||||||
unit_test(cmd_connect_shows_message_when_connecting),
|
unit_test(cmd_connect_shows_message_when_connecting),
|
||||||
unit_test(cmd_connect_shows_message_when_connected),
|
unit_test(cmd_connect_shows_message_when_connected),
|
||||||
unit_test(cmd_connect_shows_message_when_undefined),
|
unit_test(cmd_connect_shows_message_when_undefined),
|
||||||
|
unit_test(cmd_connect_when_no_account),
|
||||||
|
|
||||||
unit_test(cmd_rooms_shows_message_when_disconnected),
|
unit_test(cmd_rooms_shows_message_when_disconnected),
|
||||||
unit_test(cmd_rooms_shows_message_when_disconnecting),
|
unit_test(cmd_rooms_shows_message_when_disconnecting),
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
|
|
||||||
|
char output[256];
|
||||||
|
|
||||||
// ui startup and control
|
// ui startup and control
|
||||||
void ui_init(void) {}
|
void ui_init(void) {}
|
||||||
void ui_load_colours(void) {}
|
void ui_load_colours(void) {}
|
||||||
@ -173,6 +175,11 @@ gboolean ui_duck_exists(void)
|
|||||||
void ui_tidy_wins(void) {}
|
void ui_tidy_wins(void) {}
|
||||||
void ui_prune_wins(void) {}
|
void ui_prune_wins(void) {}
|
||||||
|
|
||||||
|
char * ui_ask_password(void)
|
||||||
|
{
|
||||||
|
return (char *)mock();
|
||||||
|
}
|
||||||
|
|
||||||
// create windows
|
// create windows
|
||||||
void create_title_bar(void) {}
|
void create_title_bar(void) {}
|
||||||
void create_status_bar(void) {}
|
void create_status_bar(void) {}
|
||||||
@ -191,7 +198,11 @@ void title_bar_draw(void) {}
|
|||||||
// console window actions
|
// console window actions
|
||||||
void cons_show(const char * const msg, ...)
|
void cons_show(const char * const msg, ...)
|
||||||
{
|
{
|
||||||
check_expected(msg);
|
va_list args;
|
||||||
|
va_start(args, msg);
|
||||||
|
vsnprintf(output, sizeof(output), msg, args);
|
||||||
|
check_expected(output);
|
||||||
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cons_about(void) {}
|
void cons_about(void) {}
|
||||||
|
@ -32,6 +32,9 @@ void jabber_init(const int disable_tls) {}
|
|||||||
jabber_conn_status_t jabber_connect_with_details(const char * const jid,
|
jabber_conn_status_t jabber_connect_with_details(const char * const jid,
|
||||||
const char * const passwd, const char * const altdomain)
|
const char * const passwd, const char * const altdomain)
|
||||||
{
|
{
|
||||||
|
check_expected(jid);
|
||||||
|
check_expected(passwd);
|
||||||
|
check_expected(altdomain);
|
||||||
return (jabber_conn_status_t)mock();
|
return (jabber_conn_status_t)mock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user