diff options
author | Jakub Jelen <jjelen@redhat.com> | 2023-12-22 09:52:18 +0100 |
---|---|---|
committer | Jakub Jelen <jjelen@redhat.com> | 2023-12-22 13:14:35 +0100 |
commit | 5dc10ff63ca2e8db91abfdccf1d095f5b4261b8e (patch) | |
tree | fce9f496478f3e5df6ea0fd0125cd64a9c36e3d7 | |
parent | 72f59157e6ccbd4c0bb806690931413169a0886f (diff) | |
download | libssh-stable-0.9.tar.gz libssh-stable-0.9.tar.xz libssh-stable-0.9.zip |
tests: Increase test coverage for IPv6 address parsing as hostnamesstable-0.9
This was an issue in cockpit:
https://github.com/cockpit-project/cockpit/issues/19772
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 6f6e453d7b0ad4ee6a6f6a1c96a9a6b27821410d)
-rw-r--r-- | tests/unittests/torture_config.c | 49 | ||||
-rw-r--r-- | tests/unittests/torture_options.c | 22 |
2 files changed, 71 insertions, 0 deletions
diff --git a/tests/unittests/torture_config.c b/tests/unittests/torture_config.c index 3a5a74bf..d8097e79 100644 --- a/tests/unittests/torture_config.c +++ b/tests/unittests/torture_config.c @@ -2,6 +2,7 @@ #define LIBSSH_STATIC +#include <errno.h> #include "torture.h" #include "libssh/options.h" #include "libssh/session.h" @@ -997,6 +998,53 @@ static void torture_config_match_pattern(void **state) } +static void torture_config_parse_uri(void **state) +{ + char *username = NULL; + char *hostname = NULL; + char *port = NULL; + int rc; + + (void)state; /* unused */ + + rc = ssh_config_parse_uri("localhost", &username, &hostname, &port, false); + assert_return_code(rc, errno); + assert_null(username); + assert_string_equal(hostname, "localhost"); + SAFE_FREE(hostname); + assert_null(port); + + rc = ssh_config_parse_uri("1.2.3.4", &username, &hostname, &port, false); + assert_return_code(rc, errno); + assert_null(username); + assert_string_equal(hostname, "1.2.3.4"); + SAFE_FREE(hostname); + assert_null(port); + + rc = ssh_config_parse_uri("1.2.3.4:2222", &username, &hostname, &port, false); + assert_return_code(rc, errno); + assert_null(username); + assert_string_equal(hostname, "1.2.3.4"); + SAFE_FREE(hostname); + assert_string_equal(port, "2222"); + SAFE_FREE(port); + + rc = ssh_config_parse_uri("[1:2:3::4]:2222", &username, &hostname, &port, false); + assert_return_code(rc, errno); + assert_null(username); + assert_string_equal(hostname, "1:2:3::4"); + SAFE_FREE(hostname); + assert_string_equal(port, "2222"); + SAFE_FREE(port); + + /* do not want port */ + rc = ssh_config_parse_uri("1:2:3::4", &username, &hostname, NULL, true); + assert_return_code(rc, errno); + assert_null(username); + assert_string_equal(hostname, "1:2:3::4"); + SAFE_FREE(hostname); +} + int torture_run_tests(void) { int rc; @@ -1012,6 +1060,7 @@ int torture_run_tests(void) { cmocka_unit_test(torture_config_rekey), cmocka_unit_test(torture_config_pubkeyacceptedkeytypes), cmocka_unit_test(torture_config_match_pattern), + cmocka_unit_test(torture_config_parse_uri), }; diff --git a/tests/unittests/torture_options.c b/tests/unittests/torture_options.c index d0fdaed1..576ca9cd 100644 --- a/tests/unittests/torture_options.c +++ b/tests/unittests/torture_options.c @@ -59,12 +59,34 @@ static void torture_options_set_host(void **state) { assert_non_null(session->opts.host); assert_string_equal(session->opts.host, "localhost"); + /* IPv4 address */ + rc = ssh_options_set(session, SSH_OPTIONS_HOST, "127.1.1.1"); + assert_true(rc == 0); + assert_non_null(session->opts.host); + assert_string_equal(session->opts.host, "127.1.1.1"); + assert_null(session->opts.username); + + /* IPv6 address */ + rc = ssh_options_set(session, SSH_OPTIONS_HOST, "::1"); + assert_true(rc == 0); + assert_non_null(session->opts.host); + assert_string_equal(session->opts.host, "::1"); + assert_null(session->opts.username); + rc = ssh_options_set(session, SSH_OPTIONS_HOST, "guru@meditation"); assert_true(rc == 0); assert_non_null(session->opts.host); assert_string_equal(session->opts.host, "meditation"); assert_non_null(session->opts.username); assert_string_equal(session->opts.username, "guru"); + + /* more @ in uri is OK -- it should go to the username */ + rc = ssh_options_set(session, SSH_OPTIONS_HOST, "at@login@hostname"); + assert_true(rc == 0); + assert_non_null(session->opts.host); + assert_string_equal(session->opts.host, "hostname"); + assert_non_null(session->opts.username); + assert_string_equal(session->opts.username, "at@login"); } static void torture_options_set_ciphers(void **state) { |