mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Fixed issue with /otr myfp when no key loaded
This commit is contained in:
parent
d25245a286
commit
18e0884f5f
@ -2618,9 +2618,13 @@ cmd_otr(gchar **args, struct cmd_help_t help)
|
|||||||
otr_keygen(account);
|
otr_keygen(account);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else if (strcmp(args[0], "myfp") == 0) {
|
} else if (strcmp(args[0], "myfp") == 0) {
|
||||||
char *fingerprint = otr_get_my_fingerprint();
|
if (!otr_key_loaded()) {
|
||||||
ui_current_print_formatted_line('!', 0, "Your OTR fingerprint: %s", fingerprint);
|
ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
|
||||||
free(fingerprint);
|
} else {
|
||||||
|
char *fingerprint = otr_get_my_fingerprint();
|
||||||
|
ui_current_print_formatted_line('!', 0, "Your OTR fingerprint: %s", fingerprint);
|
||||||
|
free(fingerprint);
|
||||||
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else if (strcmp(args[0], "theirfp") == 0) {
|
} else if (strcmp(args[0], "theirfp") == 0) {
|
||||||
win_type_t win_type = ui_current_win_type();
|
win_type_t win_type = ui_current_win_type();
|
||||||
|
@ -34,6 +34,12 @@ _mock_otr_get_their_fingerprint(const char * const recipient)
|
|||||||
return (char *)mock();
|
return (char *)mock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_mock_otr_key_loaded(void)
|
||||||
|
{
|
||||||
|
return (gboolean)mock();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
otr_keygen_expect(ProfAccount *account)
|
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);
|
expect_string(_mock_otr_get_their_fingerprint, recipient, recipient);
|
||||||
will_return(_mock_otr_get_their_fingerprint, fingerprint);
|
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);
|
||||||
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "config/account.h"
|
#include "config/account.h"
|
||||||
|
|
||||||
void otr_keygen_expect(ProfAccount *account);
|
void otr_keygen_expect(ProfAccount *account);
|
||||||
|
void otr_key_loaded_returns(gboolean loaded);
|
||||||
|
|
||||||
void otr_libotr_version_returns(char *version);
|
void otr_libotr_version_returns(char *version);
|
||||||
|
|
||||||
|
@ -366,12 +366,29 @@ void cmd_otr_myfp_shows_message_when_disconnecting(void **state)
|
|||||||
test_with_command_and_connection_status("myfp", JABBER_DISCONNECTING);
|
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)
|
void cmd_otr_myfp_shows_my_fingerprint(void **state)
|
||||||
{
|
{
|
||||||
char *fingerprint = "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE";
|
char *fingerprint = "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE";
|
||||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||||
gchar *args[] = { "myfp", NULL };
|
gchar *args[] = { "myfp", NULL };
|
||||||
mock_connection_status(JABBER_CONNECTED);
|
mock_connection_status(JABBER_CONNECTED);
|
||||||
|
otr_key_loaded_returns(TRUE);
|
||||||
otr_get_my_fingerprint_returns(strdup(fingerprint));
|
otr_get_my_fingerprint_returns(strdup(fingerprint));
|
||||||
mock_ui_current_print_formatted_line();
|
mock_ui_current_print_formatted_line();
|
||||||
|
|
||||||
|
@ -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_started(void **state);
|
||||||
void cmd_otr_myfp_shows_message_when_connecting(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_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_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_console(void **state);
|
||||||
void cmd_otr_theirfp_shows_message_when_in_muc(void **state);
|
void cmd_otr_theirfp_shows_message_when_in_muc(void **state);
|
||||||
|
@ -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_started),
|
||||||
unit_test(cmd_otr_myfp_shows_message_when_connecting),
|
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_disconnecting),
|
||||||
|
unit_test(cmd_otr_myfp_shows_message_when_no_key),
|
||||||
unit_test(cmd_otr_myfp_shows_my_fingerprint),
|
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_console),
|
||||||
unit_test(cmd_otr_theirfp_shows_message_when_in_muc),
|
unit_test(cmd_otr_theirfp_shows_message_when_in_muc),
|
||||||
|
Loading…
Reference in New Issue
Block a user