aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAnderson Toshiyuki Sasaki <ansasaki@redhat.com>2019-07-02 13:48:17 +0200
committerAnderson Toshiyuki Sasaki <ansasaki@redhat.com>2019-07-04 10:29:20 +0200
commit65a38759ca872e8bec0158ab3676e74b6afd336f (patch)
tree44a6060c5ecea9d686c1777a7a38fb7ed794cc92 /tests
parent548753b3389518ebce98a7ddbf0640db3ad72de8 (diff)
downloadlibssh-65a38759ca872e8bec0158ab3676e74b6afd336f.tar.gz
libssh-65a38759ca872e8bec0158ab3676e74b6afd336f.tar.xz
libssh-65a38759ca872e8bec0158ab3676e74b6afd336f.zip
knownhosts: Introduced ssh_known_hosts_get_algorithms_names()
The added internal function obtain a newly allocated string containing a list of the signature types that can be generated by the keys present in the known_hosts files, separated by commas. Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/torture_knownhosts_parsing.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/unittests/torture_knownhosts_parsing.c b/tests/unittests/torture_knownhosts_parsing.c
index a087caef..6952e858 100644
--- a/tests/unittests/torture_knownhosts_parsing.c
+++ b/tests/unittests/torture_knownhosts_parsing.c
@@ -369,6 +369,31 @@ static void torture_knownhosts_read_file(void **state)
ssh_list_free(entry_list);
}
+static void torture_knownhosts_get_algorithms_names(void **state)
+{
+ const char *knownhosts_file = *state;
+ ssh_session session;
+ const char *expect = "ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa";
+ char *names = NULL;
+ bool process_config = false;
+
+ session = ssh_new();
+ assert_non_null(session);
+
+ /* This makes sure the global configuration file is not processed */
+ ssh_options_set(session, SSH_OPTIONS_PROCESS_CONFIG, &process_config);
+
+ ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
+ ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, knownhosts_file);
+
+ names = ssh_known_hosts_get_algorithms_names(session);
+ assert_non_null(names);
+ assert_string_equal(names, expect);
+
+ SAFE_FREE(names);
+ ssh_free(session);
+}
+
#ifndef _WIN32 /* There is no /dev/null on Windows */
static void torture_knownhosts_host_exists(void **state)
{
@@ -510,6 +535,9 @@ int torture_run_tests(void) {
cmocka_unit_test_setup_teardown(torture_knownhosts_read_file,
setup_knownhosts_file_duplicate,
teardown_knownhosts_file),
+ cmocka_unit_test_setup_teardown(torture_knownhosts_get_algorithms_names,
+ setup_knownhosts_file,
+ teardown_knownhosts_file),
#ifndef _WIN32
cmocka_unit_test_setup_teardown(torture_knownhosts_host_exists,
setup_knownhosts_file,