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

Fixed issue with /otr myfp when no key loaded

This commit is contained in:
James Booth 2014-02-23 20:34:27 +00:00
parent d25245a286
commit 18e0884f5f
6 changed files with 40 additions and 3 deletions

View File

@ -2618,9 +2618,13 @@ cmd_otr(gchar **args, struct cmd_help_t help)
otr_keygen(account);
return TRUE;
} else if (strcmp(args[0], "myfp") == 0) {
char *fingerprint = otr_get_my_fingerprint();
ui_current_print_formatted_line('!', 0, "Your OTR fingerprint: %s", fingerprint);
free(fingerprint);
if (!otr_key_loaded()) {
ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
} else {
char *fingerprint = otr_get_my_fingerprint();
ui_current_print_formatted_line('!', 0, "Your OTR fingerprint: %s", fingerprint);
free(fingerprint);
}
return TRUE;
} else if (strcmp(args[0], "theirfp") == 0) {
win_type_t win_type = ui_current_win_type();

View File

@ -34,6 +34,12 @@ _mock_otr_get_their_fingerprint(const char * const recipient)
return (char *)mock();
}
static gboolean
_mock_otr_key_loaded(void)
{
return (gboolean)mock();
}
void
otr_keygen_expect(ProfAccount *account)
{
@ -62,3 +68,10 @@ otr_get_their_fingerprint_expect_and_return(char *recipient, char *fingerprint)
expect_string(_mock_otr_get_their_fingerprint, recipient, recipient);
will_return(_mock_otr_get_their_fingerprint, fingerprint);
}
void
otr_key_loaded_returns(gboolean loaded)
{
otr_key_loaded = _mock_otr_key_loaded;
will_return(_mock_otr_key_loaded, loaded);
}

View File

@ -4,6 +4,7 @@
#include "config/account.h"
void otr_keygen_expect(ProfAccount *account);
void otr_key_loaded_returns(gboolean loaded);
void otr_libotr_version_returns(char *version);

View File

@ -366,12 +366,29 @@ void cmd_otr_myfp_shows_message_when_disconnecting(void **state)
test_with_command_and_connection_status("myfp", JABBER_DISCONNECTING);
}
void cmd_otr_myfp_shows_message_when_no_key(void **state)
{
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "myfp", NULL };
mock_connection_status(JABBER_CONNECTED);
otr_key_loaded_returns(FALSE);
mock_ui_current_print_formatted_line();
ui_current_print_formatted_line_expect('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
gboolean result = cmd_otr(args, *help);
assert_true(result);
free(help);
}
void cmd_otr_myfp_shows_my_fingerprint(void **state)
{
char *fingerprint = "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE";
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "myfp", NULL };
mock_connection_status(JABBER_CONNECTED);
otr_key_loaded_returns(TRUE);
otr_get_my_fingerprint_returns(strdup(fingerprint));
mock_ui_current_print_formatted_line();

View File

@ -27,6 +27,7 @@ void cmd_otr_myfp_shows_message_when_undefined(void **state);
void cmd_otr_myfp_shows_message_when_started(void **state);
void cmd_otr_myfp_shows_message_when_connecting(void **state);
void cmd_otr_myfp_shows_message_when_disconnecting(void **state);
void cmd_otr_myfp_shows_message_when_no_key(void **state);
void cmd_otr_myfp_shows_my_fingerprint(void **state);
void cmd_otr_theirfp_shows_message_when_in_console(void **state);
void cmd_otr_theirfp_shows_message_when_in_muc(void **state);

View File

@ -468,6 +468,7 @@ int main(int argc, char* argv[]) {
unit_test(cmd_otr_myfp_shows_message_when_started),
unit_test(cmd_otr_myfp_shows_message_when_connecting),
unit_test(cmd_otr_myfp_shows_message_when_disconnecting),
unit_test(cmd_otr_myfp_shows_message_when_no_key),
unit_test(cmd_otr_myfp_shows_my_fingerprint),
unit_test(cmd_otr_theirfp_shows_message_when_in_console),
unit_test(cmd_otr_theirfp_shows_message_when_in_muc),