summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/generate.py43
-rw-r--r--tests/network/redirect.c113
-rw-r--r--tests/network/urlparse.c262
-rw-r--r--tests/object/cache.c125
-rw-r--r--tests/online/clone.c28
6 files changed, 315 insertions, 258 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index aaa8ed109..e39fd6f7b 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -62,4 +62,4 @@ ADD_TEST(invasive "${libgit2_BINARY_DIR}/libgit2_clar" -v -score::ftruncate -sf
ADD_TEST(online "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline)
ADD_TEST(gitdaemon "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::push)
ADD_TEST(ssh "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::push -sonline::clone::ssh_cert -sonline::clone::ssh_with_paths)
-ADD_TEST(proxy "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy_credentials_in_url -sonline::clone::proxy_credentials_request)
+ADD_TEST(proxy "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy)
diff --git a/tests/generate.py b/tests/generate.py
index 0a94d4952..572a57f86 100644
--- a/tests/generate.py
+++ b/tests/generate.py
@@ -24,8 +24,8 @@ class Module(object):
def render(self):
out = "\n".join("extern %s;" % cb['declaration'] for cb in self.module.callbacks) + "\n"
- if self.module.initialize:
- out += "extern %s;\n" % self.module.initialize['declaration']
+ for initializer in self.module.initializers:
+ out += "extern %s;\n" % initializer['declaration']
if self.module.cleanup:
out += "extern %s;\n" % self.module.cleanup['declaration']
@@ -41,7 +41,19 @@ class Module(object):
class InfoTemplate(Template):
def render(self):
- return Template(
+ templates = []
+
+ initializers = self.module.initializers
+ if len(initializers) == 0:
+ initializers = [ None ]
+
+ for initializer in initializers:
+ name = self.module.clean_name()
+ if initializer and initializer['short_name'].startswith('initialize_'):
+ variant = initializer['short_name'][len('initialize_'):]
+ name += " (%s)" % variant.replace('_', ' ')
+
+ template = Template(
r"""
{
"${clean_name}",
@@ -49,14 +61,17 @@ class Module(object):
${cleanup},
${cb_ptr}, ${cb_count}, ${enabled}
}"""
- ).substitute(
- clean_name = self.module.clean_name(),
- initialize = self._render_callback(self.module.initialize),
- cleanup = self._render_callback(self.module.cleanup),
- cb_ptr = "_clar_cb_%s" % self.module.name,
- cb_count = len(self.module.callbacks),
- enabled = int(self.module.enabled)
- )
+ ).substitute(
+ clean_name = name,
+ initialize = self._render_callback(initializer),
+ cleanup = self._render_callback(self.module.cleanup),
+ cb_ptr = "_clar_cb_%s" % self.module.name,
+ cb_count = len(self.module.callbacks),
+ enabled = int(self.module.enabled)
+ )
+ templates.append(template)
+
+ return ','.join(templates)
def __init__(self, name):
self.name = name
@@ -86,7 +101,7 @@ class Module(object):
regex = re.compile(TEST_FUNC_REGEX % self.name, re.MULTILINE)
self.callbacks = []
- self.initialize = None
+ self.initializers = []
self.cleanup = None
for (declaration, symbol, short_name) in regex.findall(contents):
@@ -96,8 +111,8 @@ class Module(object):
"symbol" : symbol
}
- if short_name == 'initialize':
- self.initialize = data
+ if short_name.startswith('initialize'):
+ self.initializers.append(data)
elif short_name == 'cleanup':
self.cleanup = data
else:
diff --git a/tests/network/redirect.c b/tests/network/redirect.c
new file mode 100644
index 000000000..3fc0b1826
--- /dev/null
+++ b/tests/network/redirect.c
@@ -0,0 +1,113 @@
+#include "clar_libgit2.h"
+#include "net.h"
+#include "netops.h"
+
+static git_net_url conndata;
+
+void test_network_redirect__initialize(void)
+{
+ memset(&conndata, 0, sizeof(conndata));
+}
+
+void test_network_redirect__cleanup(void)
+{
+ git_net_url_dispose(&conndata);
+}
+
+void test_network_redirect__redirect_http(void)
+{
+ cl_git_pass(git_net_url_parse(&conndata,
+ "http://example.com/foo/bar/baz"));
+ cl_git_pass(gitno_connection_data_handle_redirect(&conndata,
+ "http://example.com/foo/bar/baz", "bar/baz"));
+ cl_assert_equal_s(conndata.scheme, "http");
+ cl_assert_equal_s(conndata.host, "example.com");
+ cl_assert_equal_s(conndata.port, "80");
+ cl_assert_equal_s(conndata.path, "/foo/");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+}
+
+void test_network_redirect__redirect_ssl(void)
+{
+ cl_git_pass(git_net_url_parse(&conndata,
+ "https://example.com/foo/bar/baz"));
+ cl_git_pass(gitno_connection_data_handle_redirect(&conndata,
+ "https://example.com/foo/bar/baz", "bar/baz"));
+ cl_assert_equal_s(conndata.scheme, "https");
+ 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_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+}
+
+void test_network_redirect__redirect_leaves_root_path(void)
+{
+ cl_git_pass(git_net_url_parse(&conndata,
+ "https://example.com/foo/bar/baz"));
+ cl_git_pass(gitno_connection_data_handle_redirect(&conndata,
+ "https://example.com/foo/bar/baz", "/foo/bar/baz"));
+ cl_assert_equal_s(conndata.scheme, "https");
+ cl_assert_equal_s(conndata.host, "example.com");
+ cl_assert_equal_s(conndata.port, "443");
+ cl_assert_equal_s(conndata.path, "/");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+}
+
+void test_network_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"));
+ cl_git_pass(gitno_connection_data_handle_redirect(&conndata,
+ "https://user%2fname:pass%40word%zyx%v@example.com/foo/bar/baz", "bar/baz"));
+ cl_assert_equal_s(conndata.scheme, "https");
+ 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.username, "user/name");
+ cl_assert_equal_s(conndata.password, "pass@word%zyx%v");
+}
+
+void test_network_redirect__redirect_cross_host_denied(void)
+{
+ cl_git_pass(git_net_url_parse(&conndata, "https://bar.com/bar/baz"));
+ cl_git_fail_with(gitno_connection_data_handle_redirect(&conndata,
+ "https://foo.com/bar/baz", NULL),
+ -1);
+}
+
+void test_network_redirect__redirect_http_downgrade_denied(void)
+{
+ cl_git_pass(git_net_url_parse(&conndata, "https://foo.com/bar/baz"));
+ cl_git_fail_with(gitno_connection_data_handle_redirect(&conndata,
+ "http://foo.com/bar/baz", NULL),
+ -1);
+}
+
+void test_network_redirect__redirect_relative(void)
+{
+ cl_git_pass(git_net_url_parse(&conndata, "http://foo.com/bar/baz/biff"));
+ cl_git_pass(gitno_connection_data_handle_redirect(&conndata,
+ "/zap/baz/biff?bam", NULL));
+ cl_assert_equal_s(conndata.scheme, "http");
+ cl_assert_equal_s(conndata.host, "foo.com");
+ cl_assert_equal_s(conndata.port, "80");
+ cl_assert_equal_s(conndata.path, "/zap/baz/biff?bam");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+}
+
+void test_network_redirect__redirect_relative_ssl(void)
+{
+ cl_git_pass(git_net_url_parse(&conndata, "https://foo.com/bar/baz/biff"));
+ cl_git_pass(gitno_connection_data_handle_redirect(&conndata,
+ "/zap/baz/biff?bam", NULL));
+ cl_assert_equal_s(conndata.scheme, "https");
+ cl_assert_equal_s(conndata.host, "foo.com");
+ cl_assert_equal_s(conndata.port, "443");
+ cl_assert_equal_s(conndata.path, "/zap/baz/biff?bam");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+}
diff --git a/tests/network/urlparse.c b/tests/network/urlparse.c
index 4a3096baa..c2362e628 100644
--- a/tests/network/urlparse.c
+++ b/tests/network/urlparse.c
@@ -1,220 +1,144 @@
#include "clar_libgit2.h"
-#include "netops.h"
+#include "net.h"
-static char *host, *port, *path, *user, *pass;
-static gitno_connection_data conndata;
+static git_net_url conndata;
void test_network_urlparse__initialize(void)
{
- host = port = path = user = pass = NULL;
memset(&conndata, 0, sizeof(conndata));
}
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);
-
- gitno_connection_data_free_ptrs(&conndata);
+ git_net_url_dispose(&conndata);
}
void test_network_urlparse__trivial(void)
{
- 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);
+ cl_git_pass(git_net_url_parse(&conndata, "http://example.com/resource"));
+ cl_assert_equal_s(conndata.scheme, "http");
+ cl_assert_equal_s(conndata.host, "example.com");
+ cl_assert_equal_s(conndata.port, "80");
+ cl_assert_equal_s(conndata.path, "/resource");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_urlparse__root(void)
{
- cl_git_pass(gitno_extract_url_parts(&host, &port, &path, &user, &pass,
- "http://example.com/", "8080"));
- cl_assert_equal_s(host, "example.com");
- cl_assert_equal_s(port, "8080");
- cl_assert_equal_s(path, "/");
- cl_assert_equal_p(user, NULL);
- cl_assert_equal_p(pass, NULL);
+ cl_git_pass(git_net_url_parse(&conndata, "http://example.com/"));
+ cl_assert_equal_s(conndata.scheme, "http");
+ cl_assert_equal_s(conndata.host, "example.com");
+ cl_assert_equal_s(conndata.port, "80");
+ cl_assert_equal_s(conndata.path, "/");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
-void test_network_urlparse__just_hostname(void)
+void test_network_urlparse__implied_root(void)
{
- cl_git_fail_with(GIT_EINVALIDSPEC,
- gitno_extract_url_parts(&host, &port, &path, &user, &pass,
- "http://example.com", "8080"));
+ cl_git_pass(git_net_url_parse(&conndata, "http://example.com"));
+ cl_assert_equal_s(conndata.scheme, "http");
+ cl_assert_equal_s(conndata.host, "example.com");
+ cl_assert_equal_s(conndata.port, "80");
+ cl_assert_equal_s(conndata.path, "/");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
+}
+
+void test_network_urlparse__implied_root_custom_port(void)
+{
+ cl_git_pass(git_net_url_parse(&conndata, "http://example.com:42"));
+ cl_assert_equal_s(conndata.scheme, "http");
+ cl_assert_equal_s(conndata.host, "example.com");
+ cl_assert_equal_s(conndata.port, "42");
+ cl_assert_equal_s(conndata.path, "/");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
}
void test_network_urlparse__encoded_password(void)
{
- 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");
+ cl_git_pass(git_net_url_parse(&conndata,
+ "https://user:pass%2fis%40bad@hostname.com:1234/"));
+ cl_assert_equal_s(conndata.scheme, "https");
+ cl_assert_equal_s(conndata.host, "hostname.com");
+ cl_assert_equal_s(conndata.port, "1234");
+ cl_assert_equal_s(conndata.path, "/");
+ cl_assert_equal_s(conndata.username, "user");
+ cl_assert_equal_s(conndata.password, "pass/is@bad");
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
}
void test_network_urlparse__user(void)
{
- 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);
+ cl_git_pass(git_net_url_parse(&conndata,
+ "https://user@example.com/resource"));
+ cl_assert_equal_s(conndata.scheme, "https");
+ cl_assert_equal_s(conndata.host, "example.com");
+ cl_assert_equal_s(conndata.port, "443");
+ cl_assert_equal_s(conndata.path, "/resource");
+ cl_assert_equal_s(conndata.username, "user");
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_urlparse__user_pass(void)
{
/* user:pass@hostname.tld/resource */
- 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");
+ cl_git_pass(git_net_url_parse(&conndata,
+ "https://user:pass@example.com/resource"));
+ cl_assert_equal_s(conndata.scheme, "https");
+ cl_assert_equal_s(conndata.host, "example.com");
+ cl_assert_equal_s(conndata.port, "443");
+ cl_assert_equal_s(conndata.path, "/resource");
+ cl_assert_equal_s(conndata.username, "user");
+ cl_assert_equal_s(conndata.password, "pass");
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_urlparse__port(void)
{
/* hostname.tld:port/resource */
- 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);
+ cl_git_pass(git_net_url_parse(&conndata,
+ "https://example.com:9191/resource"));
+ cl_assert_equal_s(conndata.scheme, "https");
+ cl_assert_equal_s(conndata.host, "example.com");
+ cl_assert_equal_s(conndata.port, "9191");
+ cl_assert_equal_s(conndata.path, "/resource");
+ cl_assert_equal_p(conndata.username, NULL);
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
}
void test_network_urlparse__user_port(void)
{
/* user@hostname.tld:port/resource */
- 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);
+ cl_git_pass(git_net_url_parse(&conndata,
+ "https://user@example.com:9191/resource"));
+ cl_assert_equal_s(conndata.scheme, "https");
+ cl_assert_equal_s(conndata.host, "example.com");
+ cl_assert_equal_s(conndata.port, "9191");
+ cl_assert_equal_s(conndata.path, "/resource");
+ cl_assert_equal_s(conndata.username, "user");
+ cl_assert_equal_p(conndata.password, NULL);
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
}
void test_network_urlparse__user_pass_port(void)
{
/* user:pass@hostname.tld:port/resource */
- 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");
-}
-
-void test_network_urlparse__optional_path(void)
-{
- cl_git_fail(gitno_extract_url_parts(&host, &port, &path, &user, &pass,
- "https://user:pass@example.com:9191", "8080"));
-
- cl_git_pass(gitno_extract_url_parts(&host, &port, NULL, &user, &pass,
- "https://user:pass@example.com:9191", "8080"));
-}
-
-void test_network_urlparse__connection_data_http(void)
-{
- cl_git_pass(gitno_connection_data_from_url(&conndata,
- "http://example.com/foo/bar/baz", "bar/baz"));
- cl_assert_equal_s(conndata.host, "example.com");
- cl_assert_equal_s(conndata.port, "80");
- cl_assert_equal_s(conndata.path, "/foo/");
- cl_assert_equal_p(conndata.user, NULL);
- cl_assert_equal_p(conndata.pass, NULL);
- cl_assert_equal_i(conndata.use_ssl, false);
-}
-
-void test_network_urlparse__connection_data_ssl(void)
-{
- cl_git_pass(gitno_connection_data_from_url(&conndata,
- "https://example.com/foo/bar/baz", "bar/baz"));
+ cl_git_pass(git_net_url_parse(&conndata,
+ "https://user:pass@example.com:9191/resource"));
+ cl_assert_equal_s(conndata.scheme, "https");
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_p(conndata.user, NULL);
- cl_assert_equal_p(conndata.pass, NULL);
- 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");
- cl_git_fail_with(gitno_connection_data_from_url(&conndata,
- "https://foo.com/bar/baz", NULL),
- -1);
-}
-
-void test_network_urlparse__connection_data_http_downgrade(void)
-{
- conndata.use_ssl = true;
- cl_git_fail_with(gitno_connection_data_from_url(&conndata,
- "http://foo.com/bar/baz", NULL),
- -1);
-}
-
-void test_network_urlparse__connection_data_relative_redirect(void)
-{
- cl_git_pass(gitno_connection_data_from_url(&conndata,
- "http://foo.com/bar/baz/biff", NULL));
- cl_git_pass(gitno_connection_data_from_url(&conndata,
- "/zap/baz/biff?bam", NULL));
- cl_assert_equal_s(conndata.host, "foo.com");
- cl_assert_equal_s(conndata.port, "80");
- cl_assert_equal_s(conndata.path, "/zap/baz/biff?bam");
- cl_assert_equal_p(conndata.user, NULL);
- cl_assert_equal_p(conndata.pass, NULL);
- cl_assert_equal_i(conndata.use_ssl, false);
-}
-
-void test_network_urlparse__connection_data_relative_redirect_ssl(void)
-{
- cl_git_pass(gitno_connection_data_from_url(&conndata,
- "https://foo.com/bar/baz/biff", NULL));
- cl_git_pass(gitno_connection_data_from_url(&conndata,
- "/zap/baz/biff?bam", NULL));
- cl_assert_equal_s(conndata.host, "foo.com");
- cl_assert_equal_s(conndata.port, "443");
- cl_assert_equal_s(conndata.path, "/zap/baz/biff?bam");
- cl_assert_equal_p(conndata.user, NULL);
- cl_assert_equal_p(conndata.pass, NULL);
- cl_assert_equal_i(conndata.use_ssl, true);
-}
-
-/* Run this under valgrind */
-void test_network_urlparse__connection_data_cleanup(void)
-{
- cl_git_pass(gitno_connection_data_from_url(&conndata,
- "http://foo.com/bar/baz/biff", "baz/biff"));
- cl_git_pass(gitno_connection_data_from_url(&conndata,
- "https://foo.com/bar/baz/biff", "baz/biff"));
+ cl_assert_equal_s(conndata.port, "9191");
+ cl_assert_equal_s(conndata.path, "/resource");
+ cl_assert_equal_s(conndata.username, "user");
+ cl_assert_equal_s(conndata.password, "pass");
+ cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
}
diff --git a/tests/object/cache.c b/tests/object/cache.c
index d3ec53ac2..3ccc325e4 100644
--- a/tests/object/cache.c
+++ b/tests/object/cache.c
@@ -2,10 +2,35 @@
#include "repository.h"
static git_repository *g_repo;
+static size_t cache_limit;
+static int object_type;
-void test_object_cache__initialize(void)
+void test_object_cache__initialize_cache_no_blobs(void)
{
g_repo = NULL;
+ object_type = GIT_OBJECT_BLOB;
+ cache_limit = 0;
+}
+
+void test_object_cache__initialize_cache_tiny_blobs(void)
+{
+ g_repo = NULL;
+ object_type = GIT_OBJECT_BLOB;
+ cache_limit = 10;
+}
+
+void test_object_cache__initialize_cache_all_blobs(void)
+{
+ g_repo = NULL;
+ object_type = GIT_OBJECT_BLOB;
+ cache_limit = 32767;
+}
+
+void test_object_cache__initialize_cache_no_trees(void)
+{
+ g_repo = NULL;
+ object_type = GIT_OBJECT_TREE;
+ cache_limit = 0;
}
void test_object_cache__cleanup(void)
@@ -14,47 +39,49 @@ void test_object_cache__cleanup(void)
g_repo = NULL;
git_libgit2_opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, (int)GIT_OBJECT_BLOB, (size_t)0);
+ git_libgit2_opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, (int)GIT_OBJECT_TREE, (size_t)4096);
+ git_libgit2_opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, (int)GIT_OBJECT_COMMIT, (size_t)4096);
}
static struct {
git_object_t type;
const char *sha;
+ size_t size;
} g_data[] = {
/* HEAD */
- { GIT_OBJECT_BLOB, "a8233120f6ad708f843d861ce2b7228ec4e3dec6" }, /* README */
- { GIT_OBJECT_BLOB, "3697d64be941a53d4ae8f6a271e4e3fa56b022cc" }, /* branch_file.txt */
- { GIT_OBJECT_BLOB, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd" }, /* new.txt */
+ { GIT_OBJECT_BLOB, "a8233120f6ad708f843d861ce2b7228ec4e3dec6", 10 }, /* README */
+ { GIT_OBJECT_BLOB, "3697d64be941a53d4ae8f6a271e4e3fa56b022cc", 8 }, /* branch_file.txt */
+ { GIT_OBJECT_BLOB, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd", 12 }, /* new.txt */
/* refs/heads/subtrees */
- { GIT_OBJECT_BLOB, "1385f264afb75a56a5bec74243be9b367ba4ca08" }, /* README */
- { GIT_OBJECT_TREE, "f1425cef211cc08caa31e7b545ffb232acb098c3" }, /* ab */
- { GIT_OBJECT_BLOB, "d6c93164c249c8000205dd4ec5cbca1b516d487f" }, /* ab/4.txt */
- { GIT_OBJECT_TREE, "9a03079b8a8ee85a0bee58bf9be3da8b62414ed4" }, /* ab/c */
- { GIT_OBJECT_BLOB, "270b8ea76056d5cad83af921837702d3e3c2924d" }, /* ab/c/3.txt */
- { GIT_OBJECT_TREE, "b6361fc6a97178d8fc8639fdeed71c775ab52593" }, /* ab/de */
- { GIT_OBJECT_BLOB, "e7b4ad382349ff96dd8199000580b9b1e2042eb0" }, /* ab/de/2.txt */
- { GIT_OBJECT_TREE, "3259a6bd5b57fb9c1281bb7ed3167b50f224cb54" }, /* ab/de/fgh */
- { GIT_OBJECT_BLOB, "1f67fc4386b2d171e0d21be1c447e12660561f9b" }, /* ab/de/fgh/1.txt */
- { GIT_OBJECT_BLOB, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057" }, /* branch_file.txt */
- { GIT_OBJECT_BLOB, "fa49b077972391ad58037050f2a75f74e3671e92" }, /* new.txt */
+ { GIT_OBJECT_BLOB, "1385f264afb75a56a5bec74243be9b367ba4ca08", 4 }, /* README */
+ { GIT_OBJECT_TREE, "f1425cef211cc08caa31e7b545ffb232acb098c3", 90 }, /* ab */
+ { GIT_OBJECT_BLOB, "d6c93164c249c8000205dd4ec5cbca1b516d487f", 6 }, /* ab/4.txt */
+ { GIT_OBJECT_TREE, "9a03079b8a8ee85a0bee58bf9be3da8b62414ed4", 33 }, /* ab/c */
+ { GIT_OBJECT_BLOB, "270b8ea76056d5cad83af921837702d3e3c2924d", 6 }, /* ab/c/3.txt */
+ { GIT_OBJECT_TREE, "b6361fc6a97178d8fc8639fdeed71c775ab52593", 63 }, /* ab/de */
+ { GIT_OBJECT_BLOB, "e7b4ad382349ff96dd8199000580b9b1e2042eb0", 6 }, /* ab/de/2.txt */
+ { GIT_OBJECT_TREE, "3259a6bd5b57fb9c1281bb7ed3167b50f224cb54", 33 }, /* ab/de/fgh */
+ { GIT_OBJECT_BLOB, "1f67fc4386b2d171e0d21be1c447e12660561f9b", 6 }, /* ab/de/fgh/1.txt */
+ { GIT_OBJECT_BLOB, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057", 3 }, /* branch_file.txt */
+ { GIT_OBJECT_BLOB, "fa49b077972391ad58037050f2a75f74e3671e92", 9 }, /* new.txt */
/* refs/heads/chomped */
- { GIT_OBJECT_BLOB, "0266163a49e280c4f5ed1e08facd36a2bd716bcf" }, /* readme.txt */
+ { GIT_OBJECT_BLOB, "0266163a49e280c4f5ed1e08facd36a2bd716bcf", 51 }, /* readme.txt */
- { 0, NULL },
- { 0, NULL }
+ { 0, NULL, 0 },
+ { 0, NULL, 0 }
};
-void test_object_cache__cache_everything(void)
+void test_object_cache__cache_counts(void)
{
- int i, start;
+ int i, start, nonmatching = 0;
git_oid oid;
git_odb_object *odb_obj;
git_object *obj;
git_odb *odb;
- git_libgit2_opts(
- GIT_OPT_SET_CACHE_OBJECT_LIMIT, (int)GIT_OBJECT_BLOB, (size_t)32767);
+ git_libgit2_opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, object_type, cache_limit);
cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git")));
cl_git_pass(git_repository_odb(&odb, g_repo));
@@ -77,12 +104,16 @@ void test_object_cache__cache_everything(void)
git_object_free(obj);
}
- cl_assert_equal_i(count + 1, (int)git_cache_size(&g_repo->objects));
+ if ((g_data[i].type == object_type && g_data[i].size >= cache_limit) ||
+ (g_data[i].type != object_type && g_data[i].type == GIT_OBJECT_BLOB))
+ cl_assert_equal_i(count, (int)git_cache_size(&g_repo->objects));
+ else {
+ cl_assert_equal_i(count + 1, (int)git_cache_size(&g_repo->objects));
+ nonmatching++;
+ }
}
- cl_assert_equal_i(i, (int)git_cache_size(&g_repo->objects) - start);
-
- git_odb_free(odb);
+ cl_assert_equal_i(nonmatching, (int)git_cache_size(&g_repo->objects) - start);
for (i = 0; g_data[i].sha != NULL; ++i) {
int count = (int)git_cache_size(&g_repo->objects);
@@ -94,48 +125,6 @@ void test_object_cache__cache_everything(void)
cl_assert_equal_i(count, (int)git_cache_size(&g_repo->objects));
}
-}
-
-void test_object_cache__cache_no_blobs(void)
-{
- int i, start, nonblobs = 0;
- git_oid oid;
- git_odb_object *odb_obj;
- git_object *obj;
- git_odb *odb;
-
- git_libgit2_opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, (int)GIT_OBJECT_BLOB, (size_t)0);
-
- cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git")));
- cl_git_pass(git_repository_odb(&odb, g_repo));
-
- start = (int)git_cache_size(&g_repo->objects);
-
- for (i = 0; g_data[i].sha != NULL; ++i) {
- int count = (int)git_cache_size(&g_repo->objects);
-
- cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha));
-
- /* alternate between loading raw and parsed objects */
- if ((i & 1) == 0) {
- cl_git_pass(git_odb_read(&odb_obj, odb, &oid));
- cl_assert(g_data[i].type == git_odb_object_type(odb_obj));
- git_odb_object_free(odb_obj);
- } else {
- cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJECT_ANY));
- cl_assert(g_data[i].type == git_object_type(obj));
- git_object_free(obj);
- }
-
- if (g_data[i].type == GIT_OBJECT_BLOB)
- cl_assert_equal_i(count, (int)git_cache_size(&g_repo->objects));
- else {
- cl_assert_equal_i(count + 1, (int)git_cache_size(&g_repo->objects));
- nonblobs++;
- }
- }
-
- cl_assert_equal_i(nonblobs, (int)git_cache_size(&g_repo->objects) - start);
git_odb_free(odb);
}
diff --git a/tests/online/clone.c b/tests/online/clone.c
index 0d0334cbb..b7042f3d6 100644
--- a/tests/online/clone.c
+++ b/tests/online/clone.c
@@ -682,12 +682,6 @@ void test_online_clone__ssh_memory_auth(void)
cl_git_pass(git_clone(&g_repo, _remote_url, "./foo", &g_options));
}
-void test_online_clone__url_with_no_path_returns_EINVALIDSPEC(void)
-{
- cl_git_fail_with(git_clone(&g_repo, "http://github.com", "./foo", &g_options),
- GIT_EINVALIDSPEC);
-}
-
static int fail_certificate_check(git_cert *cert, int valid, const char *host, void *payload)
{
GIT_UNUSED(cert);
@@ -847,3 +841,25 @@ void test_online_clone__proxy_auto_not_detected(void)
cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
}
+
+void test_online_clone__proxy_cred_callback_after_failed_url_creds(void)
+{
+ git_buf url = GIT_BUF_INIT;
+
+ if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
+ cl_skip();
+
+ cl_git_pass(git_buf_printf(&url, "%s://invalid_user_name:INVALID_pass_WORD@%s/",
+ _remote_proxy_scheme ? _remote_proxy_scheme : "http",
+ _remote_proxy_host));
+
+ g_options.fetch_opts.proxy_opts.type = GIT_PROXY_SPECIFIED;
+ g_options.fetch_opts.proxy_opts.url = url.ptr;
+ g_options.fetch_opts.proxy_opts.credentials = proxy_cred_cb;
+ g_options.fetch_opts.proxy_opts.certificate_check = proxy_cert_cb;
+ called_proxy_creds = 0;
+ cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
+ cl_assert(called_proxy_creds);
+
+ git_buf_dispose(&url);
+}