aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2017-08-24 15:09:08 +0200
committerAndreas Schneider <asn@cryptomilk.org>2017-08-24 15:57:19 +0200
commitefb7635162db5242053ac8ea4b3a34c068e79475 (patch)
tree29f12715e86a30c043d9997e9e68e6b0efe1eede
parent8ecd65bcdb6bf0992492046c6ce63c6949517b4d (diff)
downloadlibssh-efb7635162db5242053ac8ea4b3a34c068e79475.tar.gz
libssh-efb7635162db5242053ac8ea4b3a34c068e79475.tar.xz
libssh-efb7635162db5242053ac8ea4b3a34c068e79475.zip
tests: added unit test on including config files
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--tests/unittests/CMakeLists.txt1
-rw-r--r--tests/unittests/torture_config.c95
2 files changed, 96 insertions, 0 deletions
diff --git a/tests/unittests/CMakeLists.txt b/tests/unittests/CMakeLists.txt
index cfd723cd..e1351574 100644
--- a/tests/unittests/CMakeLists.txt
+++ b/tests/unittests/CMakeLists.txt
@@ -8,6 +8,7 @@ add_cmocka_test(torture_crypto torture_crypto.c ${TORTURE_LIBRARY})
add_cmocka_test(torture_init torture_init.c ${TORTURE_LIBRARY})
add_cmocka_test(torture_list torture_list.c ${TORTURE_LIBRARY})
add_cmocka_test(torture_misc torture_misc.c ${TORTURE_LIBRARY})
+add_cmocka_test(torture_config torture_config.c ${TORTURE_LIBRARY})
add_cmocka_test(torture_options torture_options.c ${TORTURE_LIBRARY})
add_cmocka_test(torture_isipaddr torture_isipaddr.c ${TORTURE_LIBRARY})
add_cmocka_test(torture_pki_ed25519 torture_pki_ed25519.c ${TORTURE_LIBRARY})
diff --git a/tests/unittests/torture_config.c b/tests/unittests/torture_config.c
new file mode 100644
index 00000000..8be0334c
--- /dev/null
+++ b/tests/unittests/torture_config.c
@@ -0,0 +1,95 @@
+#define LIBSSH_STATIC
+
+#include "torture.h"
+#include "libssh/options.h"
+
+#define LIBSSH_TESTCONFIG1 "libssh_testconfig1.tmp"
+#define LIBSSH_TESTCONFIG2 "libssh_testconfig2.tmp"
+#define LIBSSH_TESTCONFIG3 "libssh_testconfig3.tmp"
+
+#define USERNAME "testuser"
+#define PROXYCMD "ssh -q -W %h:%p gateway.example.com"
+#define ID_FILE "/etc/xxx"
+
+static int setup_config_files(void **state)
+{
+ ssh_session session;
+
+ unlink(LIBSSH_TESTCONFIG1);
+ unlink(LIBSSH_TESTCONFIG2);
+ unlink(LIBSSH_TESTCONFIG3);
+
+ torture_write_file(LIBSSH_TESTCONFIG1,
+ "User "USERNAME"\nInclude "LIBSSH_TESTCONFIG2"\n\n");
+ torture_write_file(LIBSSH_TESTCONFIG2,
+ "Include "LIBSSH_TESTCONFIG3"\n"
+ "ProxyCommand "PROXYCMD"\n\n");
+ torture_write_file(LIBSSH_TESTCONFIG3,
+ "\n\nIdentityFile "ID_FILE"\n");
+
+ session = ssh_new();
+ *state = session;
+
+ return 0;
+}
+
+static int teardown(void **state)
+{
+ unlink(LIBSSH_TESTCONFIG1);
+ unlink(LIBSSH_TESTCONFIG2);
+ unlink(LIBSSH_TESTCONFIG3);
+
+ ssh_free(*state);
+
+ return 0;
+}
+
+
+/**
+ * @brief tests the privatekey_from_file function with passphrase
+ */
+static void torture_config_from_file(void **state) {
+ ssh_session session = *state;
+ int ret;
+ char *v;
+
+ ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG1);
+ assert_true(ret == 0);
+
+ /* Test the variable presence */
+
+ ret = ssh_options_get(session, SSH_OPTIONS_PROXYCOMMAND, &v);
+ assert_true(ret == 0);
+
+ assert_string_equal(v, PROXYCMD);
+ ssh_string_free_char(v);
+
+ ret = ssh_options_get(session, SSH_OPTIONS_IDENTITY, &v);
+ assert_true(ret == 0);
+
+ assert_string_equal(v, ID_FILE);
+ ssh_string_free_char(v);
+
+ ret = ssh_options_get(session, SSH_OPTIONS_USER, &v);
+ assert_true(ret == 0);
+
+ assert_string_equal(v, USERNAME);
+ ssh_string_free_char(v);
+
+}
+
+int torture_run_tests(void) {
+ int rc;
+ struct CMUnitTest tests[] = {
+ cmocka_unit_test_setup_teardown(torture_config_from_file,
+ setup_config_files,
+ teardown),
+ };
+
+
+ ssh_init();
+ torture_filter_tests(tests);
+ rc = cmocka_run_group_tests(tests, NULL, NULL);
+ ssh_finalize();
+ return rc;
+}