mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-12-24 19:37:48 +03:00
tests: Increase test coverage for IPv6 address parsing as hostnames
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>
This commit is contained in:
@@ -2332,6 +2332,53 @@ static void torture_config_make_absolute_no_sshdir(void **state)
|
||||
torture_config_make_absolute_int(state, 1);
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -2424,6 +2471,8 @@ int torture_run_tests(void)
|
||||
setup, teardown),
|
||||
cmocka_unit_test_setup_teardown(torture_config_make_absolute_no_sshdir,
|
||||
setup_no_sshdir, teardown),
|
||||
cmocka_unit_test_setup_teardown(torture_config_parse_uri,
|
||||
setup, teardown),
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -57,6 +57,20 @@ 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);
|
||||
@@ -64,12 +78,14 @@ static void torture_options_set_host(void **state) {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user