Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2013-11-10 19:31:21 +0400
committerVicent Martí <vicent@github.com>2013-11-10 19:31:21 +0400
commit0df96f2b05f45e62047fc592ded37c0ef18ec27b (patch)
treeabbfd0757d065fda064f5a2276df783b7b535319 /tests-clar
parent4cb3c7abe1a56ef93d2e0078ad86d09aed0cccce (diff)
parent79c443425b1b3d67e8180663c6e80793b587c888 (diff)
Merge pull request #1936 from libgit2/better-url-parsing
Streamline url-parsing logic.
Diffstat (limited to 'tests-clar')
-rw-r--r--tests-clar/network/urlparse.c59
1 files changed, 41 insertions, 18 deletions
diff --git a/tests-clar/network/urlparse.c b/tests-clar/network/urlparse.c
index 15e841b35..31616275a 100644
--- a/tests-clar/network/urlparse.c
+++ b/tests-clar/network/urlparse.c
@@ -1,12 +1,12 @@
#include "clar_libgit2.h"
#include "netops.h"
-char *host, *port, *user, *pass;
+char *host, *port, *path, *user, *pass;
gitno_connection_data conndata;
void test_network_urlparse__initialize(void)
{
- host = port = user = pass = NULL;
+ host = port = path = user = pass = NULL;
memset(&conndata, 0, sizeof(conndata));
}
@@ -15,6 +15,7 @@ void test_network_urlparse__cleanup(void)
#define FREE_AND_NULL(x) if (x) { git__free(x); x = NULL; }
FREE_AND_NULL(host);
FREE_AND_NULL(port);
+ FREE_AND_NULL(path);
FREE_AND_NULL(user);
FREE_AND_NULL(pass);
@@ -23,27 +24,33 @@ void test_network_urlparse__cleanup(void)
void test_network_urlparse__trivial(void)
{
- cl_git_pass(gitno_extract_url_parts(&host, &port, &user, &pass,
- "example.com/resource", "8080"));
+ cl_git_pass(gitno_extract_url_parts(&host, &port, &path, &user, &pass,
+ "http://example.com/resource", "8080"));
cl_assert_equal_s(host, "example.com");
cl_assert_equal_s(port, "8080");
+ cl_assert_equal_s(path, "/resource");
cl_assert_equal_p(user, NULL);
cl_assert_equal_p(pass, NULL);
}
-void test_network_urlparse__bad_url(void)
+void test_network_urlparse__encoded_password(void)
{
- cl_git_fail_with(gitno_extract_url_parts(&host, &port, &user, &pass,
- "github.com/git://github.com/foo/bar.git.git", "443"),
- GIT_EINVALIDSPEC);
+ cl_git_pass(gitno_extract_url_parts(&host, &port, &path, &user, &pass,
+ "https://user:pass%2fis%40bad@hostname.com:1234/", "1"));
+ cl_assert_equal_s(host, "hostname.com");
+ cl_assert_equal_s(port, "1234");
+ cl_assert_equal_s(path, "/");
+ cl_assert_equal_s(user, "user");
+ cl_assert_equal_s(pass, "pass/is@bad");
}
void test_network_urlparse__user(void)
{
- cl_git_pass(gitno_extract_url_parts(&host, &port, &user, &pass,
- "user@example.com/resource", "8080"));
+ cl_git_pass(gitno_extract_url_parts(&host, &port, &path, &user, &pass,
+ "https://user@example.com/resource", "8080"));
cl_assert_equal_s(host, "example.com");
cl_assert_equal_s(port, "8080");
+ cl_assert_equal_s(path, "/resource");
cl_assert_equal_s(user, "user");
cl_assert_equal_p(pass, NULL);
}
@@ -51,10 +58,11 @@ void test_network_urlparse__user(void)
void test_network_urlparse__user_pass(void)
{
/* user:pass@hostname.tld/resource */
- cl_git_pass(gitno_extract_url_parts(&host, &port, &user, &pass,
- "user:pass@example.com/resource", "8080"));
+ cl_git_pass(gitno_extract_url_parts(&host, &port, &path, &user, &pass,
+ "https://user:pass@example.com/resource", "8080"));
cl_assert_equal_s(host, "example.com");
cl_assert_equal_s(port, "8080");
+ cl_assert_equal_s(path, "/resource");
cl_assert_equal_s(user, "user");
cl_assert_equal_s(pass, "pass");
}
@@ -62,10 +70,11 @@ void test_network_urlparse__user_pass(void)
void test_network_urlparse__port(void)
{
/* hostname.tld:port/resource */
- cl_git_pass(gitno_extract_url_parts(&host, &port, &user, &pass,
- "example.com:9191/resource", "8080"));
+ cl_git_pass(gitno_extract_url_parts(&host, &port, &path, &user, &pass,
+ "https://example.com:9191/resource", "8080"));
cl_assert_equal_s(host, "example.com");
cl_assert_equal_s(port, "9191");
+ cl_assert_equal_s(path, "/resource");
cl_assert_equal_p(user, NULL);
cl_assert_equal_p(pass, NULL);
}
@@ -73,10 +82,11 @@ void test_network_urlparse__port(void)
void test_network_urlparse__user_port(void)
{
/* user@hostname.tld:port/resource */
- cl_git_pass(gitno_extract_url_parts(&host, &port, &user, &pass,
- "user@example.com:9191/resource", "8080"));
+ cl_git_pass(gitno_extract_url_parts(&host, &port, &path, &user, &pass,
+ "https://user@example.com:9191/resource", "8080"));
cl_assert_equal_s(host, "example.com");
cl_assert_equal_s(port, "9191");
+ cl_assert_equal_s(path, "/resource");
cl_assert_equal_s(user, "user");
cl_assert_equal_p(pass, NULL);
}
@@ -84,10 +94,11 @@ void test_network_urlparse__user_port(void)
void test_network_urlparse__user_pass_port(void)
{
/* user:pass@hostname.tld:port/resource */
- cl_git_pass(gitno_extract_url_parts(&host, &port, &user, &pass,
- "user:pass@example.com:9191/resource", "8080"));
+ cl_git_pass(gitno_extract_url_parts(&host, &port, &path, &user, &pass,
+ "https://user:pass@example.com:9191/resource", "8080"));
cl_assert_equal_s(host, "example.com");
cl_assert_equal_s(port, "9191");
+ cl_assert_equal_s(path, "/resource");
cl_assert_equal_s(user, "user");
cl_assert_equal_s(pass, "pass");
}
@@ -116,6 +127,18 @@ void test_network_urlparse__connection_data_ssl(void)
cl_assert_equal_i(conndata.use_ssl, true);
}
+void test_network_urlparse__encoded_username_password(void)
+{
+ cl_git_pass(gitno_connection_data_from_url(&conndata,
+ "https://user%2fname:pass%40word%zyx%v@example.com/foo/bar/baz", "bar/baz"));
+ cl_assert_equal_s(conndata.host, "example.com");
+ cl_assert_equal_s(conndata.port, "443");
+ cl_assert_equal_s(conndata.path, "/foo/");
+ cl_assert_equal_s(conndata.user, "user/name");
+ cl_assert_equal_s(conndata.pass, "pass@word%zyx%v");
+ cl_assert_equal_i(conndata.use_ssl, true);
+}
+
void test_network_urlparse__connection_data_cross_host_redirect(void)
{
conndata.host = git__strdup("bar.com");