about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-02-23 20:34:27 +0000
committerJames Booth <boothj5@gmail.com>2014-02-23 20:34:27 +0000
commit18e0884f5ff16f5209fd1cba7f57e10c1d9d91e6 (patch)
tree708299a6bebbe6d508b0b2d2ee5347de51621375
parentd25245a286ecad1ba2ca8bd6883db629ec86825f (diff)
downloadprofani-tty-18e0884f5ff16f5209fd1cba7f57e10c1d9d91e6.tar.gz
Fixed issue with /otr myfp when no key loaded
-rw-r--r--src/command/commands.c10
-rw-r--r--tests/otr/mock_otr.c13
-rw-r--r--tests/otr/mock_otr.h1
-rw-r--r--tests/test_cmd_otr.c17
-rw-r--r--tests/test_cmd_otr.h1
-rw-r--r--tests/testsuite.c1
6 files changed, 40 insertions, 3 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index d8eaa28a..da360da8 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -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();
diff --git a/tests/otr/mock_otr.c b/tests/otr/mock_otr.c
index a259c156..64ec1166 100644
--- a/tests/otr/mock_otr.c
+++ b/tests/otr/mock_otr.c
@@ -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);
+}
diff --git a/tests/otr/mock_otr.h b/tests/otr/mock_otr.h
index 3296c145..742fb215 100644
--- a/tests/otr/mock_otr.h
+++ b/tests/otr/mock_otr.h
@@ -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);
 
diff --git a/tests/test_cmd_otr.c b/tests/test_cmd_otr.c
index 65403094..c1e25a79 100644
--- a/tests/test_cmd_otr.c
+++ b/tests/test_cmd_otr.c
@@ -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();
 
diff --git a/tests/test_cmd_otr.h b/tests/test_cmd_otr.h
index 4b3d09b8..d18c4f5d 100644
--- a/tests/test_cmd_otr.h
+++ b/tests/test_cmd_otr.h
@@ -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);
diff --git a/tests/testsuite.c b/tests/testsuite.c
index 39872923..decfb37e 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -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),