diff --git a/tests/unittests/torture_misc.c b/tests/unittests/torture_misc.c index 662a7638..34327ead 100644 --- a/tests/unittests/torture_misc.c +++ b/tests/unittests/torture_misc.c @@ -1127,6 +1127,9 @@ static void torture_ssh_check_hostname_syntax(void **state) assert_int_equal(rc, SSH_OK); rc = ssh_check_hostname_syntax("libssh."); assert_int_equal(rc, SSH_OK); + // IDN + rc = ssh_check_hostname_syntax("xn--bcher-kva.tld"); + assert_int_equal(rc, SSH_OK); rc = ssh_check_hostname_syntax(NULL); assert_int_equal(rc, SSH_ERROR); @@ -1170,6 +1173,9 @@ static void torture_ssh_check_hostname_syntax(void **state) assert_int_equal(rc, SSH_ERROR); rc = ssh_check_hostname_syntax(".."); assert_int_equal(rc, SSH_ERROR); + // IDN non-encoded + rc = ssh_check_hostname_syntax("bücher.tld"); + assert_int_equal(rc, SSH_ERROR); } static void torture_ssh_check_username_syntax(void **state) { diff --git a/tests/unittests/torture_options.c b/tests/unittests/torture_options.c index 2acc5971..7a08b2e1 100644 --- a/tests/unittests/torture_options.c +++ b/tests/unittests/torture_options.c @@ -8,6 +8,7 @@ #endif #include +#include #include "torture.h" #include "torture_key.h" #include @@ -91,6 +92,40 @@ static void torture_options_set_host(void **state) { assert_string_equal(ssh_get_error(session), "Invalid argument in ssh_options_set"); assert_ssh_return_code_equal(session, rc, SSH_ERROR); + + /* IPv6 hostnames should work without square braces */ + SAFE_FREE(session->opts.username); + rc = ssh_options_set(session, + SSH_OPTIONS_HOST, + "fd4d:5449:7400:111:626d:3cff:fedf:4d39"); + assert_return_code(rc, errno); + assert_non_null(session->opts.host); + assert_string_equal(session->opts.host, + "fd4d:5449:7400:111:626d:3cff:fedf:4d39"); + assert_null(session->opts.username); + + /* IPv6 hostnames should work also with square braces */ + rc = ssh_options_set(session, + SSH_OPTIONS_HOST, + "[fd4d:5449:7400:111:626d:3cff:fedf:4d39]"); + assert_return_code(rc, errno); + assert_non_null(session->opts.host); + assert_string_equal(session->opts.host, + "fd4d:5449:7400:111:626d:3cff:fedf:4d39"); + assert_null(session->opts.username); + + /* IDN need to be in punycode format */ + rc = ssh_options_set(session, SSH_OPTIONS_HOST, "xn--bcher-kva.tld"); + assert_return_code(rc, errno); + assert_non_null(session->opts.host); + assert_string_equal(session->opts.host, "xn--bcher-kva.tld"); + assert_null(session->opts.username); + + /* IDN in UTF8 wont work */ + rc = ssh_options_set(session, SSH_OPTIONS_HOST, "bücher.tld"); + assert_string_equal(ssh_get_error(session), + "Invalid argument in ssh_options_set"); + assert_ssh_return_code_equal(session, rc, SSH_ERROR); } static void torture_options_set_ciphers(void **state)