Unverified Commit 12832bab by Edward Thomson Committed by GitHub

Merge pull request #6326 from libgit2/ethomson/url_parse

URL parsing for google-compatible URLs
parents d0203b64 1ee9b1fb
......@@ -15,6 +15,7 @@ typedef struct git_net_url {
char *port;
char *path;
char *query;
char *fragment;
char *username;
char *password;
} git_net_url;
......
......@@ -4,19 +4,19 @@
static git_net_url source, target;
void test_network_url_joinpath__initialize(void)
void test_url_joinpath__initialize(void)
{
memset(&source, 0, sizeof(source));
memset(&target, 0, sizeof(target));
}
void test_network_url_joinpath__cleanup(void)
void test_url_joinpath__cleanup(void)
{
git_net_url_dispose(&source);
git_net_url_dispose(&target);
}
void test_network_url_joinpath__target_paths_and_queries(void)
void test_url_joinpath__target_paths_and_queries(void)
{
cl_git_pass(git_net_url_parse(&source, "http://example.com/a/b"));
......@@ -31,7 +31,7 @@ void test_network_url_joinpath__target_paths_and_queries(void)
git_net_url_dispose(&target);
}
void test_network_url_joinpath__source_query_removed(void)
void test_url_joinpath__source_query_removed(void)
{
cl_git_pass(git_net_url_parse(&source, "http://example.com/a/b?query&one&two"));
......@@ -46,7 +46,7 @@ void test_network_url_joinpath__source_query_removed(void)
git_net_url_dispose(&target);
}
void test_network_url_joinpath__source_lacks_path(void)
void test_url_joinpath__source_lacks_path(void)
{
cl_git_pass(git_net_url_parse(&source, "http://example.com"));
......@@ -91,7 +91,7 @@ void test_network_url_joinpath__source_lacks_path(void)
git_net_url_dispose(&target);
}
void test_network_url_joinpath__source_is_slash(void)
void test_url_joinpath__source_is_slash(void)
{
cl_git_pass(git_net_url_parse(&source, "http://example.com/"));
......@@ -137,7 +137,7 @@ void test_network_url_joinpath__source_is_slash(void)
}
void test_network_url_joinpath__source_has_query(void)
void test_url_joinpath__source_has_query(void)
{
cl_git_pass(git_net_url_parse(&source, "http://example.com?query"));
......@@ -183,7 +183,7 @@ void test_network_url_joinpath__source_has_query(void)
}
void test_network_url_joinpath__empty_query_ignored(void)
void test_url_joinpath__empty_query_ignored(void)
{
cl_git_pass(git_net_url_parse(&source, "http://example.com/foo"));
......
......@@ -7,7 +7,7 @@ struct url_pattern {
bool matches;
};
void test_network_url_pattern__single(void)
void test_url_pattern__single(void)
{
git_net_url url;
size_t i;
......@@ -53,7 +53,7 @@ void test_network_url_pattern__single(void)
}
}
void test_network_url_pattern__list(void)
void test_url_pattern__list(void)
{
git_net_url url;
size_t i;
......
......@@ -4,17 +4,17 @@
static git_net_url conndata;
void test_network_url_redirect__initialize(void)
void test_url_redirect__initialize(void)
{
memset(&conndata, 0, sizeof(conndata));
}
void test_network_url_redirect__cleanup(void)
void test_url_redirect__cleanup(void)
{
git_net_url_dispose(&conndata);
}
void test_network_url_redirect__redirect_http(void)
void test_url_redirect__redirect_http(void)
{
cl_git_pass(git_net_url_parse(&conndata,
"http://example.com/foo/bar/baz"));
......@@ -28,7 +28,7 @@ void test_network_url_redirect__redirect_http(void)
cl_assert_equal_p(conndata.password, NULL);
}
void test_network_url_redirect__redirect_ssl(void)
void test_url_redirect__redirect_ssl(void)
{
cl_git_pass(git_net_url_parse(&conndata,
"https://example.com/foo/bar/baz"));
......@@ -42,7 +42,7 @@ void test_network_url_redirect__redirect_ssl(void)
cl_assert_equal_p(conndata.password, NULL);
}
void test_network_url_redirect__redirect_leaves_root_path(void)
void test_url_redirect__redirect_leaves_root_path(void)
{
cl_git_pass(git_net_url_parse(&conndata,
"https://example.com/foo/bar/baz"));
......@@ -56,7 +56,7 @@ void test_network_url_redirect__redirect_leaves_root_path(void)
cl_assert_equal_p(conndata.password, NULL);
}
void test_network_url_redirect__redirect_encoded_username_password(void)
void test_url_redirect__redirect_encoded_username_password(void)
{
cl_git_pass(git_net_url_parse(&conndata,
"https://user%2fname:pass%40word%zyx%v@example.com/foo/bar/baz"));
......@@ -70,7 +70,7 @@ void test_network_url_redirect__redirect_encoded_username_password(void)
cl_assert_equal_s(conndata.password, "pass@word%zyx%v");
}
void test_network_url_redirect__redirect_cross_host_allowed(void)
void test_url_redirect__redirect_cross_host_allowed(void)
{
cl_git_pass(git_net_url_parse(&conndata,
"https://bar.com/bar/baz"));
......@@ -84,7 +84,7 @@ void test_network_url_redirect__redirect_cross_host_allowed(void)
cl_assert_equal_p(conndata.password, NULL);
}
void test_network_url_redirect__redirect_cross_host_denied(void)
void test_url_redirect__redirect_cross_host_denied(void)
{
cl_git_pass(git_net_url_parse(&conndata,
"https://bar.com/bar/baz"));
......@@ -92,7 +92,7 @@ void test_network_url_redirect__redirect_cross_host_denied(void)
"https://foo.com/bar/baz", false, NULL), -1);
}
void test_network_url_redirect__redirect_http_downgrade_denied(void)
void test_url_redirect__redirect_http_downgrade_denied(void)
{
cl_git_pass(git_net_url_parse(&conndata,
"https://foo.com/bar/baz"));
......@@ -100,7 +100,7 @@ void test_network_url_redirect__redirect_http_downgrade_denied(void)
"http://foo.com/bar/baz", true, NULL), -1);
}
void test_network_url_redirect__redirect_relative(void)
void test_url_redirect__redirect_relative(void)
{
cl_git_pass(git_net_url_parse(&conndata,
"http://foo.com/bar/baz/biff"));
......@@ -114,7 +114,7 @@ void test_network_url_redirect__redirect_relative(void)
cl_assert_equal_p(conndata.password, NULL);
}
void test_network_url_redirect__redirect_relative_ssl(void)
void test_url_redirect__redirect_relative_ssl(void)
{
cl_git_pass(git_net_url_parse(&conndata,
"https://foo.com/bar/baz/biff"));
......@@ -128,7 +128,7 @@ void test_network_url_redirect__redirect_relative_ssl(void)
cl_assert_equal_p(conndata.password, NULL);
}
void test_network_url_redirect__service_query_no_query_params_in_location(void)
void test_url_redirect__service_query_no_query_params_in_location(void)
{
cl_git_pass(git_net_url_parse(&conndata,
"https://foo.com/bar/info/refs?service=git-upload-pack"));
......@@ -137,7 +137,7 @@ void test_network_url_redirect__service_query_no_query_params_in_location(void)
cl_assert_equal_s(conndata.path, "/baz");
}
void test_network_url_redirect__service_query_with_query_params_in_location(void)
void test_url_redirect__service_query_with_query_params_in_location(void)
{
cl_git_pass(git_net_url_parse(&conndata,
"https://foo.com/bar/info/refs?service=git-upload-pack"));
......
......@@ -3,19 +3,19 @@
static git_net_url conndata;
void test_network_url_scp__initialize(void)
void test_url_scp__initialize(void)
{
memset(&conndata, 0, sizeof(conndata));
}
void test_network_url_scp__cleanup(void)
void test_url_scp__cleanup(void)
{
git_net_url_dispose(&conndata);
}
/* Hostname */
void test_network_url_scp__hostname_trivial(void)
void test_url_scp__hostname_trivial(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "example.com:/resource"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -27,7 +27,7 @@ void test_network_url_scp__hostname_trivial(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_url_scp__hostname_bracketed(void)
void test_url_scp__hostname_bracketed(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "[example.com]:/resource"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -39,7 +39,7 @@ void test_network_url_scp__hostname_bracketed(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_url_scp__hostname_root(void)
void test_url_scp__hostname_root(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "example.com:/"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -51,7 +51,7 @@ void test_network_url_scp__hostname_root(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_url_scp__hostname_user(void)
void test_url_scp__hostname_user(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "git@example.com:/resource"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -63,7 +63,7 @@ void test_network_url_scp__hostname_user(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_url_scp__hostname_user_bracketed(void)
void test_url_scp__hostname_user_bracketed(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "[git@example.com]:/resource"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -75,7 +75,7 @@ void test_network_url_scp__hostname_user_bracketed(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_url_scp__hostname_port(void)
void test_url_scp__hostname_port(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "[example.com:42]:/resource"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -87,7 +87,7 @@ void test_network_url_scp__hostname_port(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
}
void test_network_url_scp__hostname_user_port(void)
void test_url_scp__hostname_user_port(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "[git@example.com:42]:/resource"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -99,7 +99,7 @@ void test_network_url_scp__hostname_user_port(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
}
void test_network_url_scp__ipv4_trivial(void)
void test_url_scp__ipv4_trivial(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "192.168.99.88:/resource/a/b/c"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -111,7 +111,7 @@ void test_network_url_scp__ipv4_trivial(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_url_scp__ipv4_bracketed(void)
void test_url_scp__ipv4_bracketed(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "[192.168.99.88]:/resource/a/b/c"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -123,7 +123,7 @@ void test_network_url_scp__ipv4_bracketed(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_url_scp__ipv4_user(void)
void test_url_scp__ipv4_user(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "git@192.168.99.88:/resource/a/b/c"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -135,7 +135,7 @@ void test_network_url_scp__ipv4_user(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_url_scp__ipv4_port(void)
void test_url_scp__ipv4_port(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "[192.168.99.88:1111]:/resource/a/b/c"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -147,7 +147,7 @@ void test_network_url_scp__ipv4_port(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
}
void test_network_url_scp__ipv4_user_port(void)
void test_url_scp__ipv4_user_port(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "[git@192.168.99.88:1111]:/resource/a/b/c"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -159,7 +159,7 @@ void test_network_url_scp__ipv4_user_port(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
}
void test_network_url_scp__ipv6_trivial(void)
void test_url_scp__ipv6_trivial(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "[fe80::dcad:beff:fe00:0001]:/resource/foo"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -171,7 +171,7 @@ void test_network_url_scp__ipv6_trivial(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_url_scp__ipv6_user(void)
void test_url_scp__ipv6_user(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "git@[fe80::dcad:beff:fe00:0001]:/resource/foo"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -183,7 +183,7 @@ void test_network_url_scp__ipv6_user(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_url_scp__ipv6_port(void)
void test_url_scp__ipv6_port(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "[[fe80::dcad:beff:fe00:0001]:99]:/resource/foo"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -195,7 +195,7 @@ void test_network_url_scp__ipv6_port(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
}
void test_network_url_scp__ipv6_user_port(void)
void test_url_scp__ipv6_user_port(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "[git@[fe80::dcad:beff:fe00:0001]:99]:/resource/foo"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -207,7 +207,7 @@ void test_network_url_scp__ipv6_user_port(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
}
void test_network_url_scp__hexhost_and_port(void)
void test_url_scp__hexhost_and_port(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "[fe:22]:/resource/foo"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -219,7 +219,7 @@ void test_network_url_scp__hexhost_and_port(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_url_scp__malformed_ipv6_one(void)
void test_url_scp__malformed_ipv6_one(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "fe80::dcad:beff:fe00:0001]:/resource"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -231,7 +231,7 @@ void test_network_url_scp__malformed_ipv6_one(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_url_scp__malformed_ipv6_two(void)
void test_url_scp__malformed_ipv6_two(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "[fe80::dcad:beff:fe00:0001]:42]:/resource"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -243,7 +243,7 @@ void test_network_url_scp__malformed_ipv6_two(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_url_scp__malformed_ipv6_with_user(void)
void test_url_scp__malformed_ipv6_with_user(void)
{
cl_git_pass(git_net_url_parse_scp(&conndata, "git@[fe80::dcad:beff:fe00:0001]:42]:/resource"));
cl_assert_equal_s(conndata.scheme, "ssh");
......@@ -255,7 +255,7 @@ void test_network_url_scp__malformed_ipv6_with_user(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_url_scp__invalid_addresses(void)
void test_url_scp__invalid_addresses(void)
{
/* Path is required */
cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
......@@ -314,8 +314,4 @@ void test_network_url_scp__invalid_addresses(void)
"[git@[fe80::dcad:beff:fe00:0001]:42:/resource"));
cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata,
"[git@[fe80::dcad:beff:fe00:0001:42]:/resource"));
/* Invalid character inside address */
cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata,
"[fe8o::dcad:beff:fe00:0001]:/resource"));
}
#include "clar_libgit2.h"
#include "net.h"
void test_network_url_valid__test(void)
void test_url_valid__test(void)
{
cl_assert(git_net_str_is_url("http://example.com/"));
cl_assert(git_net_str_is_url("file://localhost/tmp/foo/"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment