mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-04 12:20:42 +09: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>
(cherry picked from commit 6f6e453d7b)
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#define LIBSSH_STATIC
|
#define LIBSSH_STATIC
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include "torture.h"
|
#include "torture.h"
|
||||||
#include "libssh/options.h"
|
#include "libssh/options.h"
|
||||||
#include "libssh/session.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 torture_run_tests(void) {
|
||||||
int rc;
|
int rc;
|
||||||
@@ -1012,6 +1060,7 @@ int torture_run_tests(void) {
|
|||||||
cmocka_unit_test(torture_config_rekey),
|
cmocka_unit_test(torture_config_rekey),
|
||||||
cmocka_unit_test(torture_config_pubkeyacceptedkeytypes),
|
cmocka_unit_test(torture_config_pubkeyacceptedkeytypes),
|
||||||
cmocka_unit_test(torture_config_match_pattern),
|
cmocka_unit_test(torture_config_match_pattern),
|
||||||
|
cmocka_unit_test(torture_config_parse_uri),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -59,12 +59,34 @@ static void torture_options_set_host(void **state) {
|
|||||||
assert_non_null(session->opts.host);
|
assert_non_null(session->opts.host);
|
||||||
assert_string_equal(session->opts.host, "localhost");
|
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");
|
rc = ssh_options_set(session, SSH_OPTIONS_HOST, "guru@meditation");
|
||||||
assert_true(rc == 0);
|
assert_true(rc == 0);
|
||||||
assert_non_null(session->opts.host);
|
assert_non_null(session->opts.host);
|
||||||
assert_string_equal(session->opts.host, "meditation");
|
assert_string_equal(session->opts.host, "meditation");
|
||||||
assert_non_null(session->opts.username);
|
assert_non_null(session->opts.username);
|
||||||
assert_string_equal(session->opts.username, "guru");
|
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) {
|
static void torture_options_set_ciphers(void **state) {
|
||||||
|
|||||||
Reference in New Issue
Block a user