Skip to content

Commit 43e84e2

Browse files
Edward Thomsonethomson
authored andcommitted
tests: validate host and port for ssh tests when non-standard
1 parent f68b40c commit 43e84e2

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

tests/libgit2/online/clone.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,10 +787,19 @@ static int ssh_certificate_check(git_cert *cert, int valid, const char *host, vo
787787
{
788788
git_cert_hostkey *key;
789789
git_oid expected = GIT_OID_SHA1_ZERO, actual = GIT_OID_SHA1_ZERO;
790+
git_str expected_host = GIT_STR_INIT;
791+
git_net_url parsed_url = GIT_NET_URL_INIT;
790792

791793
GIT_UNUSED(valid);
792794
GIT_UNUSED(payload);
793795

796+
cl_git_pass(git_net_url_parse_standard_or_scp(&parsed_url, _remote_url));
797+
cl_git_pass(git_str_printf(&expected_host, "%s%s%s",
798+
parsed_url.host,
799+
git_net_url_is_default_port(&parsed_url) ? "" : ":",
800+
git_net_url_is_default_port(&parsed_url) ? "" : parsed_url.port));
801+
cl_assert_equal_s(expected_host.ptr, host);
802+
794803
cl_assert(_remote_ssh_fingerprint);
795804

796805
cl_git_pass(git_oid__fromstrp(&expected, _remote_ssh_fingerprint, GIT_OID_SHA1));
@@ -812,7 +821,8 @@ static int ssh_certificate_check(git_cert *cert, int valid, const char *host, vo
812821

813822
cl_assert(!memcmp(&expected, &actual, 20));
814823

815-
cl_assert_equal_s("localhost", host);
824+
git_net_url_dispose(&parsed_url);
825+
git_str_dispose(&expected_host);
816826

817827
return GIT_EUSER;
818828
}

0 commit comments

Comments
 (0)