mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Tidied cmd_otr, added check-unit target to Makefile
This commit is contained in:
parent
6097a5bade
commit
fb0e065902
@ -174,3 +174,6 @@ $(git_include): $(git_include).in
|
||||
clean-local:
|
||||
rm -f $(git_include) $(git_include).in
|
||||
endif
|
||||
|
||||
check-unit: tests/unittests/unittests
|
||||
tests/unittests/unittests
|
||||
|
@ -4200,29 +4200,34 @@ cmd_otr(gchar **args, struct cmd_help_t help)
|
||||
} else if (strcmp(args[0], "myfp") == 0) {
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
if (win_type != WIN_CHAT) {
|
||||
ui_current_print_line("You must be in a regular chat window to view a recipient's fingerprint.");
|
||||
} else if (!ui_current_win_is_otr()) {
|
||||
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
||||
} else {
|
||||
ProfChatWin *chatwin = wins_get_current_chat();
|
||||
char *fingerprint = otr_get_their_fingerprint(chatwin->barejid);
|
||||
ui_current_print_formatted_line('!', 0, "%s's OTR fingerprint: %s", chatwin->barejid, fingerprint);
|
||||
free(fingerprint);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_current_chat();
|
||||
if (chatwin->enc_mode != PROF_ENC_OTR) {
|
||||
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char *fingerprint = otr_get_their_fingerprint(chatwin->barejid);
|
||||
ui_current_print_formatted_line('!', 0, "%s's OTR fingerprint: %s", chatwin->barejid, fingerprint);
|
||||
free(fingerprint);
|
||||
return TRUE;
|
||||
|
||||
} else if (strcmp(args[0], "start") == 0) {
|
||||
// recipient supplied
|
||||
if (args[1]) {
|
||||
char *contact = args[1];
|
||||
char *barejid = roster_barejid_from_name(contact);
|
||||
@ -4236,131 +4241,165 @@ cmd_otr(gchar **args, struct cmd_help_t help)
|
||||
}
|
||||
ui_ev_focus_win((ProfWin*)chatwin);
|
||||
|
||||
if (ui_current_win_is_otr()) {
|
||||
if (chatwin->enc_mode == PROF_ENC_OTR) {
|
||||
ui_current_print_formatted_line('!', 0, "You are already in an OTR session.");
|
||||
} else {
|
||||
if (!otr_key_loaded()) {
|
||||
ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
|
||||
} else if (!otr_is_secure(barejid)) {
|
||||
char *otr_query_message = otr_start_query();
|
||||
message_send_chat_encrypted(barejid, otr_query_message);
|
||||
} else {
|
||||
ui_gone_secure(barejid, otr_is_trusted(barejid));
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!otr_key_loaded()) {
|
||||
ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!otr_is_secure(barejid)) {
|
||||
char *otr_query_message = otr_start_query();
|
||||
message_send_chat_encrypted(barejid, otr_query_message);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ui_gone_secure(barejid, otr_is_trusted(barejid));
|
||||
return TRUE;
|
||||
|
||||
// no recipient, use current chat
|
||||
} else {
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
|
||||
if (win_type != WIN_CHAT) {
|
||||
ui_current_print_line("You must be in a regular chat window to start an OTR session.");
|
||||
} else if (ui_current_win_is_otr()) {
|
||||
ui_current_print_formatted_line('!', 0, "You are already in an OTR session.");
|
||||
} else {
|
||||
if (!otr_key_loaded()) {
|
||||
ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
|
||||
} else {
|
||||
ProfChatWin *chatwin = wins_get_current_chat();
|
||||
char *otr_query_message = otr_start_query();
|
||||
message_send_chat_encrypted(chatwin->barejid, otr_query_message);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_current_chat();
|
||||
if (chatwin->enc_mode == PROF_ENC_OTR) {
|
||||
ui_current_print_formatted_line('!', 0, "You are already in an OTR session.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!otr_key_loaded()) {
|
||||
ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char *otr_query_message = otr_start_query();
|
||||
message_send_chat_encrypted(chatwin->barejid, otr_query_message);
|
||||
return TRUE;
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
} else if (strcmp(args[0], "end") == 0) {
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
|
||||
if (win_type != WIN_CHAT) {
|
||||
ui_current_print_line("You must be in a regular chat window to use OTR.");
|
||||
} else if (!ui_current_win_is_otr()) {
|
||||
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
||||
} else {
|
||||
ProfChatWin *chatwin = wins_get_current_chat();
|
||||
ui_gone_insecure(chatwin->barejid);
|
||||
otr_end_session(chatwin->barejid);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_current_chat();
|
||||
if (chatwin->enc_mode != PROF_ENC_OTR) {
|
||||
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ui_gone_insecure(chatwin->barejid);
|
||||
otr_end_session(chatwin->barejid);
|
||||
return TRUE;
|
||||
|
||||
} else if (strcmp(args[0], "trust") == 0) {
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
|
||||
if (win_type != WIN_CHAT) {
|
||||
ui_current_print_line("You must be in an OTR session to trust a recipient.");
|
||||
} else if (!ui_current_win_is_otr()) {
|
||||
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
||||
} else {
|
||||
ProfChatWin *chatwin = wins_get_current_chat();
|
||||
ui_trust(chatwin->barejid);
|
||||
otr_trust(chatwin->barejid);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_current_chat();
|
||||
if (chatwin->enc_mode != PROF_ENC_OTR) {
|
||||
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ui_trust(chatwin->barejid);
|
||||
otr_trust(chatwin->barejid);
|
||||
return TRUE;
|
||||
|
||||
} else if (strcmp(args[0], "untrust") == 0) {
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
|
||||
if (win_type != WIN_CHAT) {
|
||||
ui_current_print_line("You must be in an OTR session to untrust a recipient.");
|
||||
} else if (!ui_current_win_is_otr()) {
|
||||
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
||||
} else {
|
||||
ProfChatWin *chatwin = wins_get_current_chat();
|
||||
ui_untrust(chatwin->barejid);
|
||||
otr_untrust(chatwin->barejid);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_current_chat();
|
||||
if (chatwin->enc_mode != PROF_ENC_OTR) {
|
||||
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ui_untrust(chatwin->barejid);
|
||||
otr_untrust(chatwin->barejid);
|
||||
return TRUE;
|
||||
|
||||
} else if (strcmp(args[0], "secret") == 0) {
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
if (win_type != WIN_CHAT) {
|
||||
ui_current_print_line("You must be in an OTR session to trust a recipient.");
|
||||
} else if (!ui_current_win_is_otr()) {
|
||||
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
||||
} else {
|
||||
char *secret = args[1];
|
||||
if (secret == NULL) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
} else {
|
||||
ProfChatWin *chatwin = wins_get_current_chat();
|
||||
otr_smp_secret(chatwin->barejid, secret);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_current_chat();
|
||||
if (chatwin->enc_mode != PROF_ENC_OTR) {
|
||||
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char *secret = args[1];
|
||||
if (secret == NULL) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
otr_smp_secret(chatwin->barejid, secret);
|
||||
return TRUE;
|
||||
|
||||
} else if (strcmp(args[0], "question") == 0) {
|
||||
char *question = args[1];
|
||||
char *answer = args[2];
|
||||
|
||||
if (question == NULL || answer == NULL) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
return TRUE;
|
||||
} else {
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
if (win_type != WIN_CHAT) {
|
||||
ui_current_print_line("You must be in an OTR session to trust a recipient.");
|
||||
} else if (!ui_current_win_is_otr()) {
|
||||
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
||||
} else {
|
||||
ProfChatWin *chatwin = wins_get_current_chat();
|
||||
otr_smp_question(chatwin->barejid, question, answer);
|
||||
}
|
||||
}
|
||||
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
if (win_type != WIN_CHAT) {
|
||||
ui_current_print_line("You must be in an OTR session to trust a recipient.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_current_chat();
|
||||
if (chatwin->enc_mode != PROF_ENC_OTR) {
|
||||
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
otr_smp_question(chatwin->barejid, question, answer);
|
||||
return TRUE;
|
||||
|
||||
} else if (strcmp(args[0], "answer") == 0) {
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
if (win_type != WIN_CHAT) {
|
||||
ui_current_print_line("You must be in an OTR session to trust a recipient.");
|
||||
} else if (!ui_current_win_is_otr()) {
|
||||
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
||||
} else {
|
||||
char *answer = args[1];
|
||||
if (answer == NULL) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
} else {
|
||||
ProfChatWin *chatwin = wins_get_current_chat();
|
||||
otr_smp_answer(chatwin->barejid, answer);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = wins_get_current_chat();
|
||||
if (chatwin->enc_mode != PROF_ENC_OTR) {
|
||||
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char *answer = args[1];
|
||||
if (answer == NULL) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
otr_smp_answer(chatwin->barejid, answer);
|
||||
return TRUE;
|
||||
|
||||
} else {
|
||||
|
@ -1151,19 +1151,6 @@ ui_current_win_type(void)
|
||||
return current->type;
|
||||
}
|
||||
|
||||
gboolean
|
||||
ui_current_win_is_otr(void)
|
||||
{
|
||||
ProfWin *current = wins_get_current();
|
||||
if (current->type == WIN_CHAT) {
|
||||
ProfChatWin *chatwin = (ProfChatWin*)current;
|
||||
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
||||
return chatwin->enc_mode == PROF_ENC_OTR;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
win_type_t
|
||||
ui_win_type(int index)
|
||||
{
|
||||
|
@ -194,7 +194,6 @@ int ui_close_read_wins(void);
|
||||
|
||||
// current window actions
|
||||
win_type_t ui_current_win_type(void);
|
||||
gboolean ui_current_win_is_otr(void);
|
||||
|
||||
void ui_current_print_line(const char * const msg, ...);
|
||||
void ui_current_print_formatted_line(const char show_char, int attrs, const char * const msg, ...);
|
||||
|
@ -422,12 +422,21 @@ void cmd_otr_theirfp_shows_message_when_in_private(void **state)
|
||||
|
||||
void cmd_otr_theirfp_shows_message_when_non_otr_chat_window(void **state)
|
||||
{
|
||||
char *recipient = "someuser@someserver.com";
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "theirfp", NULL };
|
||||
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
will_return(ui_current_win_type, WIN_CHAT);
|
||||
will_return(ui_current_win_is_otr, FALSE);
|
||||
|
||||
ProfChatWin *chatwin = malloc(sizeof(ProfChatWin));
|
||||
chatwin->barejid = strdup(recipient);
|
||||
chatwin->memcheck = PROFCHATWIN_MEMCHECK;
|
||||
will_return(win_create_chat, &chatwin->window);
|
||||
|
||||
wins_init();
|
||||
wins_new_chat(recipient);
|
||||
wins_set_current_by_num(2);
|
||||
|
||||
expect_ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
|
||||
|
||||
@ -435,6 +444,7 @@ void cmd_otr_theirfp_shows_message_when_non_otr_chat_window(void **state)
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
wins_close_current();
|
||||
}
|
||||
|
||||
void cmd_otr_theirfp_shows_fingerprint(void **state)
|
||||
@ -450,6 +460,7 @@ void cmd_otr_theirfp_shows_fingerprint(void **state)
|
||||
ProfChatWin *chatwin = malloc(sizeof(ProfChatWin));
|
||||
chatwin->barejid = strdup(recipient);
|
||||
chatwin->memcheck = PROFCHATWIN_MEMCHECK;
|
||||
chatwin->enc_mode = PROF_ENC_OTR;
|
||||
will_return(win_create_chat, &chatwin->window);
|
||||
|
||||
wins_init();
|
||||
@ -458,7 +469,6 @@ void cmd_otr_theirfp_shows_fingerprint(void **state)
|
||||
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
will_return(ui_current_win_type, WIN_CHAT);
|
||||
will_return(ui_current_win_is_otr, TRUE);
|
||||
|
||||
expect_string(otr_get_their_fingerprint, recipient, chatwin->barejid);
|
||||
will_return(otr_get_their_fingerprint, strdup(fingerprint));
|
||||
@ -507,12 +517,22 @@ void cmd_otr_start_shows_message_when_in_private(void **state)
|
||||
|
||||
void cmd_otr_start_shows_message_when_already_started(void **state)
|
||||
{
|
||||
char *recipient = "someone@server.org";
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "start", NULL };
|
||||
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
will_return(ui_current_win_type, WIN_CHAT);
|
||||
will_return(ui_current_win_is_otr, TRUE);
|
||||
|
||||
ProfChatWin *chatwin = malloc(sizeof(ProfChatWin));
|
||||
chatwin->barejid = strdup(recipient);
|
||||
chatwin->memcheck = PROFCHATWIN_MEMCHECK;
|
||||
chatwin->enc_mode = PROF_ENC_OTR;
|
||||
will_return(win_create_chat, &chatwin->window);
|
||||
|
||||
wins_init();
|
||||
wins_new_chat(recipient);
|
||||
wins_set_current_by_num(2);
|
||||
|
||||
expect_ui_current_print_formatted_line('!', 0, "You are already in an OTR session.");
|
||||
|
||||
@ -520,24 +540,36 @@ void cmd_otr_start_shows_message_when_already_started(void **state)
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
wins_close_current();
|
||||
}
|
||||
|
||||
void cmd_otr_start_shows_message_when_no_key(void **state)
|
||||
{
|
||||
char *recipient = "someone@server.org";
|
||||
CommandHelp *help = malloc(sizeof(CommandHelp));
|
||||
gchar *args[] = { "start", NULL };
|
||||
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
will_return(ui_current_win_type, WIN_CHAT);
|
||||
will_return(ui_current_win_is_otr, FALSE);
|
||||
will_return(otr_key_loaded, FALSE);
|
||||
|
||||
ProfChatWin *chatwin = malloc(sizeof(ProfChatWin));
|
||||
chatwin->barejid = strdup(recipient);
|
||||
chatwin->memcheck = PROFCHATWIN_MEMCHECK;
|
||||
chatwin->enc_mode = PROF_ENC_NONE;
|
||||
will_return(win_create_chat, &chatwin->window);
|
||||
|
||||
wins_init();
|
||||
wins_new_chat(recipient);
|
||||
wins_set_current_by_num(2);
|
||||
|
||||
expect_ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
|
||||
|
||||
gboolean result = cmd_otr(args, *help);
|
||||
assert_true(result);
|
||||
|
||||
free(help);
|
||||
wins_close_current();
|
||||
}
|
||||
|
||||
void
|
||||
@ -559,7 +591,6 @@ cmd_otr_start_sends_otr_query_message_to_current_recipeint(void **state)
|
||||
|
||||
will_return(jabber_get_connection_status, JABBER_CONNECTED);
|
||||
will_return(ui_current_win_type, WIN_CHAT);
|
||||
will_return(ui_current_win_is_otr, FALSE);
|
||||
will_return(otr_key_loaded, TRUE);
|
||||
will_return(otr_start_query, query_message);
|
||||
|
||||
|
@ -126,11 +126,6 @@ win_type_t ui_current_win_type(void)
|
||||
return (win_type_t)mock();
|
||||
}
|
||||
|
||||
gboolean ui_current_win_is_otr(void)
|
||||
{
|
||||
return (gboolean)mock();
|
||||
}
|
||||
|
||||
void ui_current_print_line(const char * const msg, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
Loading…
Reference in New Issue
Block a user