aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2019-05-27 17:31:22 +0200
committerAndreas Schneider <asn@cryptomilk.org>2019-06-12 11:15:20 +0200
commit9f7f5dee18dea225d94655ea61db33ef51bf1e94 (patch)
tree53e5cb7c443e978ac68fea3e0faad59da929f962 /tests
parent5f01ed027817996d53cdef60b8e145899fd5ec6a (diff)
downloadlibssh-9f7f5dee18dea225d94655ea61db33ef51bf1e94.tar.gz
libssh-9f7f5dee18dea225d94655ea61db33ef51bf1e94.tar.xz
libssh-9f7f5dee18dea225d94655ea61db33ef51bf1e94.zip
tests: Verify duplicate items are removed from knownhosts entries list
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/torture_knownhosts_parsing.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/unittests/torture_knownhosts_parsing.c b/tests/unittests/torture_knownhosts_parsing.c
index d07c3f4b..c80bdbca 100644
--- a/tests/unittests/torture_knownhosts_parsing.c
+++ b/tests/unittests/torture_knownhosts_parsing.c
@@ -73,6 +73,75 @@ close_fp:
return rc;
}
+static int setup_knownhosts_file_duplicate(void **state)
+{
+ char *tmp_file = NULL;
+ size_t nwritten;
+ FILE *fp = NULL;
+ int rc = 0;
+
+ tmp_file = torture_create_temp_file(TMP_FILE_NAME);
+ assert_non_null(tmp_file);
+
+ *state = tmp_file;
+
+ fp = fopen(tmp_file, "w");
+ assert_non_null(fp);
+
+ /* ed25519 key */
+ nwritten = fwrite(LOCALHOST_PATTERN_ED25519,
+ sizeof(char),
+ strlen(LOCALHOST_PATTERN_ED25519),
+ fp);
+ if (nwritten != strlen(LOCALHOST_PATTERN_ED25519)) {
+ rc = -1;
+ goto close_fp;
+ }
+
+ nwritten = fwrite("\n", sizeof(char), 1, fp);
+ if (nwritten != 1) {
+ rc = -1;
+ goto close_fp;
+ }
+
+ /* RSA key */
+ nwritten = fwrite(LOCALHOST_RSA_LINE,
+ sizeof(char),
+ strlen(LOCALHOST_RSA_LINE),
+ fp);
+ if (nwritten != strlen(LOCALHOST_RSA_LINE)) {
+ rc = -1;
+ goto close_fp;
+ }
+
+ nwritten = fwrite("\n", sizeof(char), 1, fp);
+ if (nwritten != 1) {
+ rc = -1;
+ goto close_fp;
+ }
+
+ /* ed25519 key again */
+ nwritten = fwrite(LOCALHOST_PATTERN_ED25519,
+ sizeof(char),
+ strlen(LOCALHOST_PATTERN_ED25519),
+ fp);
+ if (nwritten != strlen(LOCALHOST_PATTERN_ED25519)) {
+ rc = -1;
+ goto close_fp;
+ }
+
+ nwritten = fwrite("\n", sizeof(char), 1, fp);
+ if (nwritten != 1) {
+ rc = -1;
+ goto close_fp;
+ }
+
+close_fp:
+ fclose(fp);
+
+ return rc;
+}
+
static int teardown_knownhosts_file(void **state)
{
char *tmp_file = *state;
@@ -279,6 +348,7 @@ static void torture_knownhosts_read_file(void **state)
assert_string_equal(entry->hostname, "localhost");
type = ssh_key_type(entry->publickey);
assert_int_equal(type, SSH_KEYTYPE_ED25519);
+ assert_non_null(it->next);
it = it->next;
@@ -289,6 +359,7 @@ static void torture_knownhosts_read_file(void **state)
assert_string_equal(entry->hostname, "localhost");
type = ssh_key_type(entry->publickey);
assert_int_equal(type, SSH_KEYTYPE_RSA);
+ assert_null(it->next);
it = ssh_list_get_iterator(entry_list);
for (;it != NULL; it = it->next) {
@@ -424,6 +495,9 @@ int torture_run_tests(void) {
cmocka_unit_test_setup_teardown(torture_knownhosts_read_file,
setup_knownhosts_file,
teardown_knownhosts_file),
+ cmocka_unit_test_setup_teardown(torture_knownhosts_read_file,
+ setup_knownhosts_file_duplicate,
+ teardown_knownhosts_file),
#ifndef _WIN32
cmocka_unit_test_setup_teardown(torture_knownhosts_host_exists,
setup_knownhosts_file,