diff options
| author | lmcglash <lmcglash@mathworks.com> | 2023-03-10 08:51:43 +0000 |
|---|---|---|
| committer | lmcglash <lmcglash@mathworks.com> | 2023-03-10 08:51:43 +0000 |
| commit | 570ef74a07f80d8890a2bf0125d72ee42f83187e (patch) | |
| tree | c3106ddd08967e3f071f1eec872a1d6db01dec37 /tests/libgit2 | |
| parent | a9793ac643a0cd82b00970d0d6e0b67681ec3112 (diff) | |
| parent | d066d0d95c43e97df6624292f3f527f9372ca8fe (diff) | |
| download | libgit2-570ef74a07f80d8890a2bf0125d72ee42f83187e.tar.gz | |
Merge commit 'd066d0d95c43e97df6624292f3f527f9372ca8fe'
Diffstat (limited to 'tests/libgit2')
50 files changed, 1821 insertions, 1901 deletions
diff --git a/tests/libgit2/CMakeLists.txt b/tests/libgit2/CMakeLists.txt index 7f6fafe77..866122d1c 100644 --- a/tests/libgit2/CMakeLists.txt +++ b/tests/libgit2/CMakeLists.txt @@ -69,7 +69,9 @@ add_clar_test(libgit2_tests invasive -v -sfilter::stream::bigfile -so add_clar_test(libgit2_tests online -v -sonline -xonline::customcert) add_clar_test(libgit2_tests online_customcert -v -sonline::customcert) add_clar_test(libgit2_tests gitdaemon -v -sonline::push) -add_clar_test(libgit2_tests ssh -v -sonline::push -sonline::clone::ssh_cert -sonline::clone::ssh_with_paths -sonline::clone::path_whitespace_ssh) +add_clar_test(libgit2_tests gitdaemon_namespace -v -sonline::clone::namespace) +add_clar_test(libgit2_tests gitdaemon_sha256 -v -sonline::clone::sha256) +add_clar_test(libgit2_tests ssh -v -sonline::push -sonline::clone::ssh_cert -sonline::clone::ssh_with_paths -sonline::clone::path_whitespace_ssh -sonline::clone::ssh_auth_methods) add_clar_test(libgit2_tests proxy -v -sonline::clone::proxy) add_clar_test(libgit2_tests auth_clone -v -sonline::clone::cred) add_clar_test(libgit2_tests auth_clone_and_push -v -sonline::clone::push -sonline::push) diff --git a/tests/libgit2/commit/parse.c b/tests/libgit2/commit/parse.c index b313fc308..3a1fc3d26 100644 --- a/tests/libgit2/commit/parse.c +++ b/tests/libgit2/commit/parse.c @@ -287,7 +287,7 @@ static int parse_commit(git_commit **out, const char *buffer) fake_odb_object.buffer = (char *)buffer; fake_odb_object.cached.size = strlen(fake_odb_object.buffer); - error = git_commit__parse(commit, &fake_odb_object); + error = git_commit__parse(commit, &fake_odb_object, GIT_OID_SHA1); *out = commit; return error; diff --git a/tests/libgit2/config/include.c b/tests/libgit2/config/include.c index 9328f3cf6..1b55fdc86 100644 --- a/tests/libgit2/config/include.c +++ b/tests/libgit2/config/include.c @@ -42,8 +42,13 @@ void test_config_include__absolute(void) void test_config_include__homedir(void) { - cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, cl_fixture("config"))); + git_str homefile = GIT_STR_INIT; + + cl_fake_homedir(&homefile); + cl_git_pass(git_str_joinpath(&homefile, homefile.ptr, "config-included")); + cl_git_mkfile("config-include-homedir", "[include]\npath = ~/config-included"); + cl_git_mkfile(homefile.ptr, "[foo \"bar\"]\n\tbaz = huzzah\n"); cl_git_pass(git_config_open_ondisk(&cfg, "config-include-homedir")); @@ -53,6 +58,8 @@ void test_config_include__homedir(void) cl_sandbox_set_search_path_defaults(); cl_git_pass(p_unlink("config-include-homedir")); + + git_str_dispose(&homefile); } /* We need to pretend that the variables were defined where the file was included */ @@ -113,7 +120,8 @@ void test_config_include__missing(void) void test_config_include__missing_homedir(void) { - cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, cl_fixture("config"))); + cl_fake_homedir(NULL); + cl_git_mkfile("including", "[include]\npath = ~/.nonexistentfile\n[foo]\nbar = baz"); git_error_clear(); diff --git a/tests/libgit2/config/read.c b/tests/libgit2/config/read.c index a2e668c20..ac6459b9e 100644 --- a/tests/libgit2/config/read.c +++ b/tests/libgit2/config/read.c @@ -728,14 +728,11 @@ void test_config_read__path(void) { git_config *cfg; git_buf path = GIT_BUF_INIT; - git_buf old_path = GIT_BUF_INIT; git_str home_path = GIT_STR_INIT; git_str expected_path = GIT_STR_INIT; - cl_git_pass(p_mkdir("fakehome", 0777)); - cl_git_pass(git_fs_path_prettify(&home_path, "fakehome", NULL)); - cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &old_path)); - cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, home_path.ptr)); + cl_fake_homedir(&home_path); + cl_git_mkfile("./testconfig", "[some]\n path = ~/somefile"); cl_git_pass(git_fs_path_join_unrooted(&expected_path, "somefile", home_path.ptr, NULL)); @@ -761,8 +758,6 @@ void test_config_read__path(void) cl_git_mkfile("./testconfig", "[some]\n path = ~user/foo"); cl_git_fail(git_config_get_path(&path, cfg, "some.path")); - cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, old_path.ptr)); - git_buf_dispose(&old_path); git_str_dispose(&home_path); git_str_dispose(&expected_path); git_config_free(cfg); diff --git a/tests/libgit2/core/oid.c b/tests/libgit2/core/oid.c index 9fe4413b7..a405b3344 100644 --- a/tests/libgit2/core/oid.c +++ b/tests/libgit2/core/oid.c @@ -52,7 +52,9 @@ void test_core_oid__streq_sha1(void) void test_core_oid__streq_sha256(void) { -#ifdef GIT_EXPERIMENTAL_SHA256 +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else cl_assert_equal_i(0, git_oid_streq(&id_sha256, str_oid_sha256)); cl_assert_equal_i(-1, git_oid_streq(&id_sha256, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef")); @@ -90,7 +92,9 @@ void test_core_oid__strcmp_sha1(void) void test_core_oid__strcmp_sha256(void) { -#ifdef GIT_EXPERIMENTAL_SHA256 +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else cl_assert_equal_i(0, git_oid_strcmp(&id_sha256, str_oid_sha256)); cl_assert(git_oid_strcmp(&id_sha256, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef") < 0); @@ -129,7 +133,9 @@ void test_core_oid__ncmp_sha1(void) void test_core_oid__ncmp_sha256(void) { -#ifdef GIT_EXPERIMENTAL_SHA256 +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else cl_assert(!git_oid_ncmp(&id_sha256, &idp_sha256, 0)); cl_assert(!git_oid_ncmp(&id_sha256, &idp_sha256, 1)); cl_assert(!git_oid_ncmp(&id_sha256, &idp_sha256, 2)); @@ -186,3 +192,22 @@ void test_core_oid__fmt_substr_sha1(void) git_oid_fmt_substr(buf, &id_sha1, 5, 6); cl_assert_equal_s(buf, "12eea6"); } + +void test_core_oid__type_lookup(void) +{ + cl_assert_equal_i(GIT_OID_SHA1, git_oid_type_fromstr("sha1")); + cl_assert_equal_i(GIT_OID_SHA1, git_oid_type_fromstrn("sha1...", 4)); + cl_assert_equal_s("sha1", git_oid_type_name(GIT_OID_SHA1)); + +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_assert_equal_i(GIT_OID_SHA256, git_oid_type_fromstr("sha256")); + cl_assert_equal_i(GIT_OID_SHA256, git_oid_type_fromstrn("sha256...", 6)); + cl_assert_equal_s("sha256", git_oid_type_name(GIT_OID_SHA256)); +#endif + + cl_assert_equal_i(0, git_oid_type_fromstr("sha42")); + cl_assert_equal_i(0, git_oid_type_fromstrn("sha1", 3)); + cl_assert_equal_i(0, git_oid_type_fromstrn("sha1...", 5)); + cl_assert_equal_s("unknown", git_oid_type_name(0)); + cl_assert_equal_s("unknown", git_oid_type_name(42)); +} diff --git a/tests/libgit2/core/opts.c b/tests/libgit2/core/opts.c index e8f65d510..486ff58c6 100644 --- a/tests/libgit2/core/opts.c +++ b/tests/libgit2/core/opts.c @@ -34,8 +34,9 @@ void test_core_opts__extensions_query(void) cl_git_pass(git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, &out)); - cl_assert_equal_sz(out.count, 1); + cl_assert_equal_sz(out.count, 2); cl_assert_equal_s("noop", out.strings[0]); + cl_assert_equal_s("objectformat", out.strings[1]); git_strarray_dispose(&out); } @@ -48,9 +49,10 @@ void test_core_opts__extensions_add(void) cl_git_pass(git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, in, ARRAY_SIZE(in))); cl_git_pass(git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, &out)); - cl_assert_equal_sz(out.count, 2); + cl_assert_equal_sz(out.count, 3); cl_assert_equal_s("noop", out.strings[0]); - cl_assert_equal_s("foo", out.strings[1]); + cl_assert_equal_s("objectformat", out.strings[1]); + cl_assert_equal_s("foo", out.strings[2]); git_strarray_dispose(&out); } @@ -63,9 +65,10 @@ void test_core_opts__extensions_remove(void) cl_git_pass(git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, in, ARRAY_SIZE(in))); cl_git_pass(git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, &out)); - cl_assert_equal_sz(out.count, 2); - cl_assert_equal_s("bar", out.strings[0]); - cl_assert_equal_s("baz", out.strings[1]); + cl_assert_equal_sz(out.count, 3); + cl_assert_equal_s("objectformat", out.strings[0]); + cl_assert_equal_s("bar", out.strings[1]); + cl_assert_equal_s("baz", out.strings[2]); git_strarray_dispose(&out); } diff --git a/tests/libgit2/core/structinit.c b/tests/libgit2/core/structinit.c index 160e2f612..8a6e48d2a 100644 --- a/tests/libgit2/core/structinit.c +++ b/tests/libgit2/core/structinit.c @@ -160,6 +160,11 @@ void test_core_structinit__compare(void) git_stash_apply_options, GIT_STASH_APPLY_OPTIONS_VERSION, \ GIT_STASH_APPLY_OPTIONS_INIT, git_stash_apply_options_init); + /* stash save */ + CHECK_MACRO_FUNC_INIT_EQUAL( \ + git_stash_save_options, GIT_STASH_SAVE_OPTIONS_VERSION, \ + GIT_STASH_SAVE_OPTIONS_INIT, git_stash_save_options_init); + /* status */ CHECK_MACRO_FUNC_INIT_EQUAL( \ git_status_options, GIT_STATUS_OPTIONS_VERSION, \ diff --git a/tests/libgit2/diff/workdir.c b/tests/libgit2/diff/workdir.c index 8ccde41ff..21c5b0de9 100644 --- a/tests/libgit2/diff/workdir.c +++ b/tests/libgit2/diff/workdir.c @@ -1232,6 +1232,42 @@ void test_diff_workdir__checks_options_version(void) cl_assert_equal_i(GIT_ERROR_INVALID, err->klass); } +void test_diff_workdir__can_diff_empty_untracked_file(void) +{ + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; + git_diff *diff = NULL; + git_patch *patch = NULL; + + g_repo = cl_git_sandbox_init("empty_standard_repo"); + + cl_git_mkfile("empty_standard_repo/emptyfile.txt", ""); + + opts.context_lines = 3; + opts.interhunk_lines = 1; + opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED | GIT_DIFF_SHOW_UNTRACKED_CONTENT; + + cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts)); + + /* without filters */ + git_patch_from_diff(&patch, diff, 0); + cl_assert(NULL != patch); + cl_assert(0 == git_patch_get_delta(patch)->new_file.size); + cl_assert(0 == strcmp("emptyfile.txt", git_patch_get_delta(patch)->new_file.path)); + git_patch_free(patch); + patch = NULL; + + /* with a filter */ + cl_repo_set_bool(g_repo, "core.autocrlf", true); /* install some filter */ + git_patch_from_diff(&patch, diff, 0); + cl_assert(NULL != patch); + cl_assert(0 == git_patch_get_delta(patch)->new_file.size); + cl_assert(0 == strcmp("emptyfile.txt", git_patch_get_delta(patch)->new_file.path)); + git_patch_free(patch); + patch = NULL; + + git_diff_free(diff); +} + void test_diff_workdir__can_diff_empty_file(void) { git_diff *diff; diff --git a/tests/libgit2/email/create.c.bak b/tests/libgit2/email/create.c.bak deleted file mode 100644 index cbb140bd2..000000000 --- a/tests/libgit2/email/create.c.bak +++ /dev/null @@ -1,386 +0,0 @@ -#include "clar.h" -#include "clar_libgit2.h" - -#include "buffer.h" -#include "diff_generate.h" - -static git_repository *repo; - -void test_email_create__initialize(void) -{ - repo = cl_git_sandbox_init("diff_format_email"); -} - -void test_email_create__cleanup(void) -{ - cl_git_sandbox_cleanup(); -} - -static void email_for_commit( - git_buf *out, - const char *commit_id, - git_email_create_options *opts) -{ - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; - - git_oid_fromstr(&oid, commit_id, GIT_OID_SHA1); - - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - - cl_git_pass(git_email_create_from_commit(out, commit, opts)); - - git_diff_free(diff); - git_commit_free(commit); -} - -static void assert_email_match( - const char *expected, - const char *commit_id, - git_email_create_options *opts) -{ - git_buf buf = GIT_BUF_INIT; - - email_for_commit(&buf, commit_id, opts); - cl_assert_equal_s(expected, git_buf_cstr(&buf)); - - git_buf_dispose(&buf); -} - -static void assert_subject_match( - const char *expected, - const char *commit_id, - git_email_create_options *opts) -{ - git_buf buf = GIT_BUF_INIT; - const char *loc; - - email_for_commit(&buf, commit_id, opts); - - cl_assert((loc = strstr(buf.ptr, "\nSubject: ")) != NULL); - git_buf_consume(&buf, (loc + 10)); - git_buf_truncate_at_char(&buf, '\n'); - - cl_assert_equal_s(expected, git_buf_cstr(&buf)); - - git_buf_dispose(&buf); -} - -void test_email_create__commit(void) -{ - const char *expected = - "From 9264b96c6d104d0e07ae33d3007b6a48246c6f92 Mon Sep 17 00:00:00 2001\n" \ - "From: Jacques Germishuys <jacquesg@striata.com>\n" \ - "Date: Wed, 9 Apr 2014 20:57:01 +0200\n" \ - "Subject: [PATCH] Modify some content\n" \ - "\n" \ - "---\n" \ - " file1.txt | 8 +++++---\n" \ - " 1 file changed, 5 insertions(+), 3 deletions(-)\n" \ - "\n" \ - "diff --git a/file1.txt b/file1.txt\n" \ - "index 94aaae8..af8f41d 100644\n" \ - "--- a/file1.txt\n" \ - "+++ b/file1.txt\n" \ - "@@ -1,15 +1,17 @@\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - "+_file1.txt_\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - "+\n" \ - "+\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "+_file1.txt_\n" \ - "+_file1.txt_\n" \ - " file1.txt\n" \ - "--\n" \ - "libgit2 " LIBGIT2_VERSION "\n" \ - "\n"; - - assert_email_match( - expected, "9264b96c6d104d0e07ae33d3007b6a48246c6f92", NULL); -} - -void test_email_create__custom_summary_and_body(void) -{ - const char *expected = "From 627e7e12d87e07a83fad5b6bfa25e86ead4a5270 Mon Sep 17 00:00:00 2001\n" \ - "From: Patrick Steinhardt <ps@pks.im>\n" \ - "Date: Tue, 24 Nov 2015 13:34:39 +0100\n" \ - "Subject: [PPPPPATCH 2/4] This is a subject\n" \ - "\n" \ - "Modify content of file3.txt by appending a new line. Make this\n" \ - "commit message somewhat longer to test behavior with newlines\n" \ - "embedded in the message body.\n" \ - "\n" \ - "Also test if new paragraphs are included correctly.\n" \ - "---\n" \ - " file3.txt | 1 +\n" \ - " 1 file changed, 1 insertion(+)\n" \ - "\n" \ - "diff --git a/file3.txt b/file3.txt\n" \ - "index 9a2d780..7309653 100644\n" \ - "--- a/file3.txt\n" \ - "+++ b/file3.txt\n" \ - "@@ -3,3 +3,4 @@ file3!\n" \ - " file3\n" \ - " file3\n" \ - " file3\n" \ - "+file3\n" \ - "--\n" \ - "libgit2 " LIBGIT2_VERSION "\n" \ - "\n"; - - const char *summary = "This is a subject\nwith\nnewlines"; - const char *body = "Modify content of file3.txt by appending a new line. Make this\n" \ - "commit message somewhat longer to test behavior with newlines\n" \ - "embedded in the message body.\n" \ - "\n" \ - "Also test if new paragraphs are included correctly."; - - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; - git_buf buf = GIT_BUF_INIT; - git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT; - - opts.subject_prefix = "PPPPPATCH"; - - git_oid_fromstr(&oid, "627e7e12d87e07a83fad5b6bfa25e86ead4a5270", GIT_OID_SHA1); - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); - cl_git_pass(git_email_create_from_diff(&buf, diff, 2, 4, &oid, summary, body, git_commit_author(commit), &opts)); - - cl_assert_equal_s(expected, git_buf_cstr(&buf)); - - git_diff_free(diff); - git_commit_free(commit); - git_buf_dispose(&buf); -} - -void test_email_create__mode_change(void) -{ - const char *expected = - "From 7ade76dd34bba4733cf9878079f9fd4a456a9189 Mon Sep 17 00:00:00 2001\n" \ - "From: Jacques Germishuys <jacquesg@striata.com>\n" \ - "Date: Thu, 10 Apr 2014 10:05:03 +0200\n" \ - "Subject: [PATCH] Update permissions\n" \ - "\n" \ - "---\n" \ - " file1.txt.renamed | 0\n" \ - " 1 file changed, 0 insertions(+), 0 deletions(-)\n" \ - " mode change 100644 => 100755 file1.txt.renamed\n" \ - "\n" \ - "diff --git a/file1.txt.renamed b/file1.txt.renamed\n" \ - "old mode 100644\n" \ - "new mode 100755\n" \ - "--\n" \ - "libgit2 " LIBGIT2_VERSION "\n" \ - "\n"; - - assert_email_match(expected, "7ade76dd34bba4733cf9878079f9fd4a456a9189", NULL); -} - -void test_email_create__rename(void) -{ - const char *expected = - "From 6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d Mon Sep 17 00:00:00 2001\n" \ - "From: Jacques Germishuys <jacquesg@striata.com>\n" \ - "Date: Wed, 9 Apr 2014 21:15:56 +0200\n" \ - "Subject: [PATCH] Renamed file1.txt -> file1.txt.renamed\n" \ - "\n" \ - "---\n" \ - " file1.txt => file1.txt.renamed | 4 ++--\n" \ - " 1 file changed, 2 insertions(+), 2 deletions(-)\n" \ - "\n" \ - "diff --git a/file1.txt b/file1.txt.renamed\n" \ - "similarity index 86%\n" \ - "rename from file1.txt\n" \ - "rename to file1.txt.renamed\n" \ - "index af8f41d..a97157a 100644\n" \ - "--- a/file1.txt\n" \ - "+++ b/file1.txt.renamed\n" \ - "@@ -3,13 +3,13 @@ file1.txt\n" \ - " _file1.txt_\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - "-file1.txt\n" \ - "+file1.txt_renamed\n" \ - " file1.txt\n" \ - " \n" \ - " \n" \ - " file1.txt\n" \ - " file1.txt\n" \ - "-file1.txt\n" \ - "+file1.txt_renamed\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - " _file1.txt_\n" \ - "--\n" \ - "libgit2 " LIBGIT2_VERSION "\n" \ - "\n"; - - assert_email_match(expected, "6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d", NULL); -} - -void test_email_create__rename_as_add_delete(void) -{ - const char *expected = - "From 6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d Mon Sep 17 00:00:00 2001\n" \ - "From: Jacques Germishuys <jacquesg@striata.com>\n" \ - "Date: Wed, 9 Apr 2014 21:15:56 +0200\n" \ - "Subject: [PATCH] Renamed file1.txt -> file1.txt.renamed\n" \ - "\n" \ - "---\n" \ - " file1.txt | 17 -----------------\n" \ - " file1.txt.renamed | 17 +++++++++++++++++\n" \ - " 2 files changed, 17 insertions(+), 17 deletions(-)\n" \ - " delete mode 100644 file1.txt\n" \ - " create mode 100644 file1.txt.renamed\n" \ - "\n" \ - "diff --git a/file1.txt b/file1.txt\n" \ - "deleted file mode 100644\n" \ - "index af8f41d..0000000\n" \ - "--- a/file1.txt\n" \ - "+++ /dev/null\n" \ - "@@ -1,17 +0,0 @@\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "-_file1.txt_\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "-\n" \ - "-\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "-_file1.txt_\n" \ - "-_file1.txt_\n" \ - "-file1.txt\n" \ - "diff --git a/file1.txt.renamed b/file1.txt.renamed\n" \ - "new file mode 100644\n" \ - "index 0000000..a97157a\n" \ - "--- /dev/null\n" \ - "+++ b/file1.txt.renamed\n" \ - "@@ -0,0 +1,17 @@\n" \ - "+file1.txt\n" \ - "+file1.txt\n" \ - "+_file1.txt_\n" \ - "+file1.txt\n" \ - "+file1.txt\n" \ - "+file1.txt_renamed\n" \ - "+file1.txt\n" \ - "+\n" \ - "+\n" \ - "+file1.txt\n" \ - "+file1.txt\n" \ - "+file1.txt_renamed\n" \ - "+file1.txt\n" \ - "+file1.txt\n" \ - "+_file1.txt_\n" \ - "+_file1.txt_\n" \ - "+file1.txt\n" \ - "--\n" \ - "libgit2 " LIBGIT2_VERSION "\n" \ - "\n"; - - git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT; - opts.flags |= GIT_EMAIL_CREATE_NO_RENAMES; - - assert_email_match(expected, "6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d", &opts); -} - -void test_email_create__binary(void) -{ - const char *expected = - "From 8d7523f6fcb2404257889abe0d96f093d9f524f9 Mon Sep 17 00:00:00 2001\n" \ - "From: Jacques Germishuys <jacquesg@striata.com>\n" \ - "Date: Sun, 13 Apr 2014 18:10:18 +0200\n" \ - "Subject: [PATCH] Modified binary file\n" \ - "\n" \ - "---\n" \ - " binary.bin | Bin 3 -> 5 bytes\n" \ - " 1 file changed, 0 insertions(+), 0 deletions(-)\n" \ - "\n" \ - "diff --git a/binary.bin b/binary.bin\n" \ - "index bd474b2519cc15eab801ff851cc7d50f0dee49a1..9ac35ff15cd8864aeafd889e4826a3150f0b06c4 100644\n" \ - "GIT binary patch\n" \ - "literal 5\n" \ - "Mc${NkU}WL~000&M4gdfE\n" \ - "\n" \ - "literal 3\n" \ - "Kc${Nk-~s>u4FC%O\n" \ - "\n" \ - "--\n" \ - "libgit2 " LIBGIT2_VERSION "\n" \ - "\n"; - - assert_email_match(expected, "8d7523f6fcb2404257889abe0d96f093d9f524f9", NULL); -} - -void test_email_create__binary_not_included(void) -{ - const char *expected = - "From 8d7523f6fcb2404257889abe0d96f093d9f524f9 Mon Sep 17 00:00:00 2001\n" \ - "From: Jacques Germishuys <jacquesg@striata.com>\n" \ - "Date: Sun, 13 Apr 2014 18:10:18 +0200\n" \ - "Subject: [PATCH] Modified binary file\n" \ - "\n" \ - "---\n" \ - " binary.bin | Bin 3 -> 5 bytes\n" \ - " 1 file changed, 0 insertions(+), 0 deletions(-)\n" \ - "\n" \ - "diff --git a/binary.bin b/binary.bin\n" \ - "index bd474b2..9ac35ff 100644\n" \ - "Binary files a/binary.bin and b/binary.bin differ\n" \ - "--\n" \ - "libgit2 " LIBGIT2_VERSION "\n" \ - "\n"; - - git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT; - opts.diff_opts.flags &= ~GIT_DIFF_SHOW_BINARY; - - assert_email_match(expected, "8d7523f6fcb2404257889abe0d96f093d9f524f9", &opts); -} - -void test_email_create__commit_subjects(void) -{ - git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT; - - assert_subject_match("[PATCH] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); - - opts.reroll_number = 42; - assert_subject_match("[PATCH v42] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); - - opts.flags |= GIT_EMAIL_CREATE_ALWAYS_NUMBER; - assert_subject_match("[PATCH v42 1/1] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); - - opts.start_number = 9; - assert_subject_match("[PATCH v42 9/9] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); - - opts.subject_prefix = ""; - assert_subject_match("[v42 9/9] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); - - opts.reroll_number = 0; - assert_subject_match("[9/9] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); - - opts.start_number = 0; - assert_subject_match("[1/1] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); - - opts.flags = GIT_EMAIL_CREATE_OMIT_NUMBERS; - assert_subject_match("Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); -} diff --git a/tests/libgit2/graph/commitgraph.c b/tests/libgit2/graph/commitgraph.c index e2452000d..82f7f936f 100644 --- a/tests/libgit2/graph/commitgraph.c +++ b/tests/libgit2/graph/commitgraph.c @@ -124,3 +124,44 @@ void test_graph_commitgraph__writer(void) git_commit_graph_writer_free(w); git_repository_free(repo); } + +void test_graph_commitgraph__validate(void) +{ + git_repository *repo; + struct git_commit_graph *cgraph; + git_str objects_dir = GIT_STR_INIT; + + cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); + cl_git_pass(git_str_joinpath(&objects_dir, git_repository_path(repo), "objects")); + + /* git_commit_graph_open() calls git_commit_graph_validate() */ + cl_git_pass(git_commit_graph_open(&cgraph, git_str_cstr(&objects_dir))); + + git_commit_graph_free(cgraph); + git_str_dispose(&objects_dir); + git_repository_free(repo); +} + +void test_graph_commitgraph__validate_corrupt(void) +{ + git_repository *repo; + struct git_commit_graph *cgraph; + int fd = -1; + + cl_fixture_sandbox("testrepo.git"); + cl_git_pass(git_repository_open(&repo, cl_git_sandbox_path(1, "testrepo.git", NULL))); + + /* corrupt commit graph checksum at the end of the file */ + cl_assert((fd = p_open(cl_git_sandbox_path(0, "testrepo.git", "objects", "info", "commit-graph", NULL), O_WRONLY)) > 0); + cl_assert(p_lseek(fd, -5, SEEK_END) > 0); + cl_must_pass(p_write(fd, "\0\0", 2)); + cl_must_pass(p_close(fd)); + + /* git_commit_graph_open() calls git_commit_graph_validate() */ + cl_git_fail(git_commit_graph_open(&cgraph, cl_git_sandbox_path(1, "testrepo.git", "objects", NULL))); + + git_commit_graph_free(cgraph); + git_repository_free(repo); + + cl_fixture_cleanup("testrepo.git"); +} diff --git a/tests/libgit2/ignore/path.c b/tests/libgit2/ignore/path.c index a574d1d79..17f28bc5d 100644 --- a/tests/libgit2/ignore/path.c +++ b/tests/libgit2/ignore/path.c @@ -286,14 +286,16 @@ void test_ignore_path__subdirectory_gitignore(void) void test_ignore_path__expand_tilde_to_homedir(void) { + git_str homefile = GIT_STR_INIT; git_config *cfg; assert_is_ignored(false, "example.global_with_tilde"); - cl_fake_home(); + cl_fake_homedir(&homefile); + cl_git_pass(git_str_joinpath(&homefile, homefile.ptr, "globalexclude")); /* construct fake home with fake global excludes */ - cl_git_mkfile("home/globalexclude", "# found me\n*.global_with_tilde\n"); + cl_git_mkfile(homefile.ptr, "# found me\n*.global_with_tilde\n"); cl_git_pass(git_repository_config(&cfg, g_repo)); cl_git_pass(git_config_set_string(cfg, "core.excludesfile", "~/globalexclude")); @@ -305,11 +307,13 @@ void test_ignore_path__expand_tilde_to_homedir(void) cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES)); - cl_fake_home_cleanup(NULL); + cl_fake_homedir_cleanup(NULL); git_attr_cache_flush(g_repo); /* must reset to pick up change */ assert_is_ignored(false, "example.global_with_tilde"); + + git_str_dispose(&homefile); } /* Ensure that the .gitignore in the subdirectory only affects diff --git a/tests/libgit2/ignore/status.c b/tests/libgit2/ignore/status.c index deb717590..a007774d7 100644 --- a/tests/libgit2/ignore/status.c +++ b/tests/libgit2/ignore/status.c @@ -363,6 +363,7 @@ void test_ignore_status__subdirectories_not_at_root(void) void test_ignore_status__leading_slash_ignores(void) { + git_str homedir = GIT_STR_INIT; git_status_options opts = GIT_STATUS_OPTIONS_INIT; status_entry_counts counts; static const char *paths_2[] = { @@ -385,8 +386,9 @@ void test_ignore_status__leading_slash_ignores(void) make_test_data(test_repo_1, test_files_1); - cl_fake_home(); - cl_git_mkfile("home/.gitignore", "/ignore_me\n"); + cl_fake_homedir(&homedir); + cl_git_pass(git_str_joinpath(&homedir, homedir.ptr, ".gitignore")); + cl_git_mkfile(homedir.ptr, "/ignore_me\n"); { git_config *cfg; cl_git_pass(git_repository_config(&cfg, g_repo)); @@ -412,6 +414,8 @@ void test_ignore_status__leading_slash_ignores(void) cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); + + git_str_dispose(&homedir); } void test_ignore_status__multiple_leading_slash(void) diff --git a/tests/libgit2/index/addall.c b/tests/libgit2/index/addall.c index 6f95f6386..e76b6e81d 100644 --- a/tests/libgit2/index/addall.c +++ b/tests/libgit2/index/addall.c @@ -441,6 +441,52 @@ void test_index_addall__callback_filtering(void) git_index_free(index); } +void test_index_addall__handles_ignored_files_in_directory(void) +{ + git_index *index; + + g_repo = cl_git_sandbox_init_new(TEST_DIR); + + cl_git_mkfile(TEST_DIR "/file.foo", "a file"); + cl_git_mkfile(TEST_DIR "/file.bar", "another file"); + cl_must_pass(p_mkdir(TEST_DIR "/folder", 0777)); + cl_git_mkfile(TEST_DIR "/folder/asdf", "yet another file"); + + cl_git_mkfile(TEST_DIR "/.gitignore", "folder/\n"); + + check_status(g_repo, 0, 0, 0, 3, 0, 0, 1, 0); + + cl_git_pass(git_repository_index(&index, g_repo)); + cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL)); + + check_status(g_repo, 3, 0, 0, 0, 0, 0, 1, 0); + + git_index_free(index); +} + +void test_index_addall__force_adds_ignored_directories(void) +{ + git_index *index; + + g_repo = cl_git_sandbox_init_new(TEST_DIR); + + cl_git_mkfile(TEST_DIR "/file.foo", "a file"); + cl_git_mkfile(TEST_DIR "/file.bar", "another file"); + cl_must_pass(p_mkdir(TEST_DIR "/folder", 0777)); + cl_git_mkfile(TEST_DIR "/folder/asdf", "yet another file"); + + cl_git_mkfile(TEST_DIR "/.gitignore", "folder/\n"); + + check_status(g_repo, 0, 0, 0, 3, 0, 0, 1, 0); + + cl_git_pass(git_repository_index(&index, g_repo)); + cl_git_pass(git_index_add_all(index, NULL, GIT_INDEX_ADD_FORCE, NULL, NULL)); + + check_status(g_repo, 4, 0, 0, 0, 0, 0, 0, 0); + + git_index_free(index); +} + void test_index_addall__adds_conflicts(void) { git_index *index; diff --git a/tests/libgit2/network/url/joinpath.c b/tests/libgit2/network/url/joinpath.c deleted file mode 100644 index bf4557138..000000000 --- a/tests/libgit2/network/url/joinpath.c +++ /dev/null @@ -1,194 +0,0 @@ -#include "clar_libgit2.h" -#include "net.h" -#include "netops.h" - -static git_net_url source, target; - -void test_network_url_joinpath__initialize(void) -{ - memset(&source, 0, sizeof(source)); - memset(&target, 0, sizeof(target)); -} - -void test_network_url_joinpath__cleanup(void) -{ - git_net_url_dispose(&source); - git_net_url_dispose(&target); -} - -void test_network_url_joinpath__target_paths_and_queries(void) -{ - cl_git_pass(git_net_url_parse(&source, "http://example.com/a/b")); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/c/d")); - cl_assert_equal_s(target.path, "/a/b/c/d"); - cl_assert_equal_p(target.query, NULL); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/c/d?foo")); - cl_assert_equal_s(target.path, "/a/b/c/d"); - cl_assert_equal_s(target.query, "foo"); - git_net_url_dispose(&target); -} - -void test_network_url_joinpath__source_query_removed(void) -{ - cl_git_pass(git_net_url_parse(&source, "http://example.com/a/b?query&one&two")); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/c/d")); - cl_assert_equal_s(target.path, "/a/b/c/d"); - cl_assert_equal_p(target.query, NULL); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/c/d?foo")); - cl_assert_equal_s(target.path, "/a/b/c/d"); - cl_assert_equal_s(target.query, "foo"); - git_net_url_dispose(&target); -} - -void test_network_url_joinpath__source_lacks_path(void) -{ - cl_git_pass(git_net_url_parse(&source, "http://example.com")); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/")); - cl_assert_equal_s(target.path, "/"); - cl_assert_equal_p(target.query, NULL); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "")); - cl_assert_equal_s(target.path, "/"); - cl_assert_equal_p(target.query, NULL); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "asdf")); - cl_assert_equal_s(target.path, "/asdf"); - cl_assert_equal_p(target.query, NULL); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/asdf")); - cl_assert_equal_s(target.path, "/asdf"); - cl_assert_equal_p(target.query, NULL); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/foo/bar")); - cl_assert_equal_s(target.path, "/foo/bar"); - cl_assert_equal_p(target.query, NULL); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "asdf?hello")); - cl_assert_equal_s(target.path, "/asdf"); - cl_assert_equal_s(target.query, "hello"); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/asdf?hello")); - cl_assert_equal_s(target.path, "/asdf"); - cl_assert_equal_s(target.query, "hello"); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/foo/bar?hello")); - cl_assert_equal_s(target.path, "/foo/bar"); - cl_assert_equal_s(target.query, "hello"); - git_net_url_dispose(&target); -} - -void test_network_url_joinpath__source_is_slash(void) -{ - cl_git_pass(git_net_url_parse(&source, "http://example.com/")); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/")); - cl_assert_equal_s(target.path, "/"); - cl_assert_equal_p(target.query, NULL); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "")); - cl_assert_equal_s(target.path, "/"); - cl_assert_equal_p(target.query, NULL); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "asdf")); - cl_assert_equal_s(target.path, "/asdf"); - cl_assert_equal_p(target.query, NULL); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/asdf")); - cl_assert_equal_s(target.path, "/asdf"); - cl_assert_equal_p(target.query, NULL); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/foo/bar")); - cl_assert_equal_s(target.path, "/foo/bar"); - cl_assert_equal_p(target.query, NULL); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "asdf?hello")); - cl_assert_equal_s(target.path, "/asdf"); - cl_assert_equal_s(target.query, "hello"); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/asdf?hello")); - cl_assert_equal_s(target.path, "/asdf"); - cl_assert_equal_s(target.query, "hello"); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/foo/bar?hello")); - cl_assert_equal_s(target.path, "/foo/bar"); - cl_assert_equal_s(target.query, "hello"); - git_net_url_dispose(&target); -} - - -void test_network_url_joinpath__source_has_query(void) -{ - cl_git_pass(git_net_url_parse(&source, "http://example.com?query")); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/")); - cl_assert_equal_s(target.path, "/"); - cl_assert_equal_p(target.query, NULL); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "")); - cl_assert_equal_s(target.path, "/"); - cl_assert_equal_p(target.query, NULL); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "asdf")); - cl_assert_equal_s(target.path, "/asdf"); - cl_assert_equal_p(target.query, NULL); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/asdf")); - cl_assert_equal_s(target.path, "/asdf"); - cl_assert_equal_p(target.query, NULL); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/foo/bar")); - cl_assert_equal_s(target.path, "/foo/bar"); - cl_assert_equal_p(target.query, NULL); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "asdf?hello")); - cl_assert_equal_s(target.path, "/asdf"); - cl_assert_equal_s(target.query, "hello"); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/asdf?hello")); - cl_assert_equal_s(target.path, "/asdf"); - cl_assert_equal_s(target.query, "hello"); - git_net_url_dispose(&target); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/foo/bar?hello")); - cl_assert_equal_s(target.path, "/foo/bar"); - cl_assert_equal_s(target.query, "hello"); - git_net_url_dispose(&target); -} - - -void test_network_url_joinpath__empty_query_ignored(void) -{ - cl_git_pass(git_net_url_parse(&source, "http://example.com/foo")); - - cl_git_pass(git_net_url_joinpath(&target, &source, "/bar/baz?")); - cl_assert_equal_s(target.path, "/foo/bar/baz"); - cl_assert_equal_p(target.query, NULL); - git_net_url_dispose(&target); -} diff --git a/tests/libgit2/network/url/parse.c b/tests/libgit2/network/url/parse.c deleted file mode 100644 index 8149ba52c..000000000 --- a/tests/libgit2/network/url/parse.c +++ /dev/null @@ -1,557 +0,0 @@ -#include "clar_libgit2.h" -#include "net.h" - -static git_net_url conndata; - -void test_network_url_parse__initialize(void) -{ - memset(&conndata, 0, sizeof(conndata)); -} - -void test_network_url_parse__cleanup(void) -{ - git_net_url_dispose(&conndata); -} - -/* Hostname */ - -void test_network_url_parse__hostname_trivial(void) -{ - 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_url_parse__hostname_root(void) -{ - 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_url_parse__hostname_implied_root(void) -{ - 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_url_parse__hostname_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_url_parse__hostname_implied_root_empty_port(void) -{ - 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_url_parse__hostname_encoded_password(void) -{ - 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_url_parse__hostname_user(void) -{ - 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_url_parse__hostname_user_pass(void) -{ - /* user:pass@hostname.tld/resource */ - 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_url_parse__hostname_port(void) -{ - /* hostname.tld:port/resource */ - 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_url_parse__hostname_empty_port(void) -{ - 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_url_parse__hostname_user_port(void) -{ - /* user@hostname.tld:port/resource */ - 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_url_parse__hostname_user_pass_port(void) -{ - /* user:pass@hostname.tld:port/resource */ - 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, "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); -} - -/* IPv4 addresses */ - -void test_network_url_parse__ipv4_trivial(void) -{ - cl_git_pass(git_net_url_parse(&conndata, "http://192.168.1.1/resource")); - cl_assert_equal_s(conndata.scheme, "http"); - cl_assert_equal_s(conndata.host, "192.168.1.1"); - 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_url_parse__ipv4_root(void) -{ - cl_git_pass(git_net_url_parse(&conndata, "http://192.168.1.1/")); - cl_assert_equal_s(conndata.scheme, "http"); - cl_assert_equal_s(conndata.host, "192.168.1.1"); - 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_url_parse__ipv4_implied_root(void) -{ - cl_git_pass(git_net_url_parse(&conndata, "http://192.168.1.1")); - cl_assert_equal_s(conndata.scheme, "http"); - cl_assert_equal_s(conndata.host, "192.168.1.1"); - 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_url_parse__ipv4_implied_root_custom_port(void) -{ - cl_git_pass(git_net_url_parse(&conndata, "http://192.168.1.1:42")); - cl_assert_equal_s(conndata.scheme, "http"); - cl_assert_equal_s(conndata.host, "192.168.1.1"); - 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_url_parse__ipv4_implied_root_empty_port(void) -{ - cl_git_pass(git_net_url_parse(&conndata, "http://192.168.1.1:")); - cl_assert_equal_s(conndata.scheme, "http"); - cl_assert_equal_s(conndata.host, "192.168.1.1"); - 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_url_parse__ipv4_encoded_password(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "https://user:pass%2fis%40bad@192.168.1.1:1234/")); - cl_assert_equal_s(conndata.scheme, "https"); - cl_assert_equal_s(conndata.host, "192.168.1.1"); - 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_url_parse__ipv4_user(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "https://user@192.168.1.1/resource")); - cl_assert_equal_s(conndata.scheme, "https"); - cl_assert_equal_s(conndata.host, "192.168.1.1"); - 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_url_parse__ipv4_user_pass(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "https://user:pass@192.168.1.1/resource")); - cl_assert_equal_s(conndata.scheme, "https"); - cl_assert_equal_s(conndata.host, "192.168.1.1"); - 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_url_parse__ipv4_port(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "https://192.168.1.1:9191/resource")); - cl_assert_equal_s(conndata.scheme, "https"); - cl_assert_equal_s(conndata.host, "192.168.1.1"); - 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_url_parse__ipv4_empty_port(void) -{ - cl_git_pass(git_net_url_parse(&conndata, "http://192.168.1.1:/resource")); - cl_assert_equal_s(conndata.scheme, "http"); - cl_assert_equal_s(conndata.host, "192.168.1.1"); - 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_url_parse__ipv4_user_port(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "https://user@192.168.1.1:9191/resource")); - cl_assert_equal_s(conndata.scheme, "https"); - cl_assert_equal_s(conndata.host, "192.168.1.1"); - 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_url_parse__ipv4_user_pass_port(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "https://user:pass@192.168.1.1:9191/resource")); - cl_assert_equal_s(conndata.scheme, "https"); - cl_assert_equal_s(conndata.host, "192.168.1.1"); - 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); -} - -/* IPv6 addresses */ - -void test_network_url_parse__ipv6_trivial(void) -{ - cl_git_pass(git_net_url_parse(&conndata, "http://[fe80::dcad:beff:fe00:0001]/resource")); - cl_assert_equal_s(conndata.scheme, "http"); - cl_assert_equal_s(conndata.host, "fe80::dcad:beff:fe00:0001"); - 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_url_parse__ipv6_root(void) -{ - cl_git_pass(git_net_url_parse(&conndata, "http://[fe80::dcad:beff:fe00:0001]/")); - cl_assert_equal_s(conndata.scheme, "http"); - cl_assert_equal_s(conndata.host, "fe80::dcad:beff:fe00:0001"); - 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_url_parse__ipv6_implied_root(void) -{ - cl_git_pass(git_net_url_parse(&conndata, "http://[fe80::dcad:beff:fe00:0001]")); - cl_assert_equal_s(conndata.scheme, "http"); - cl_assert_equal_s(conndata.host, "fe80::dcad:beff:fe00:0001"); - 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_url_parse__ipv6_implied_root_custom_port(void) -{ - cl_git_pass(git_net_url_parse(&conndata, "http://[fe80::dcad:beff:fe00:0001]:42")); - cl_assert_equal_s(conndata.scheme, "http"); - cl_assert_equal_s(conndata.host, "fe80::dcad:beff:fe00:0001"); - 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_url_parse__ipv6_implied_root_empty_port(void) -{ - cl_git_pass(git_net_url_parse(&conndata, "http://[fe80::dcad:beff:fe00:0001]:")); - cl_assert_equal_s(conndata.scheme, "http"); - cl_assert_equal_s(conndata.host, "fe80::dcad:beff:fe00:0001"); - 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_url_parse__ipv6_encoded_password(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "https://user:pass%2fis%40bad@[fe80::dcad:beff:fe00:0001]:1234/")); - cl_assert_equal_s(conndata.scheme, "https"); - cl_assert_equal_s(conndata.host, "fe80::dcad:beff:fe00:0001"); - 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_url_parse__ipv6_user(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "https://user@[fe80::dcad:beff:fe00:0001]/resource")); - cl_assert_equal_s(conndata.scheme, "https"); - cl_assert_equal_s(conndata.host, "fe80::dcad:beff:fe00:0001"); - 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_url_parse__ipv6_user_pass(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "https://user:pass@[fe80::dcad:beff:fe00:0001]/resource")); - cl_assert_equal_s(conndata.scheme, "https"); - cl_assert_equal_s(conndata.host, "fe80::dcad:beff:fe00:0001"); - 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_url_parse__ipv6_port(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "https://[fe80::dcad:beff:fe00:0001]:9191/resource")); - cl_assert_equal_s(conndata.scheme, "https"); - cl_assert_equal_s(conndata.host, "fe80::dcad:beff:fe00:0001"); - 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_url_parse__ipv6_empty_port(void) -{ - cl_git_pass(git_net_url_parse(&conndata, "http://[fe80::dcad:beff:fe00:0001]:/resource")); - cl_assert_equal_s(conndata.scheme, "http"); - cl_assert_equal_s(conndata.host, "fe80::dcad:beff:fe00:0001"); - 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_url_parse__ipv6_user_port(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "https://user@[fe80::dcad:beff:fe00:0001]:9191/resource")); - cl_assert_equal_s(conndata.scheme, "https"); - cl_assert_equal_s(conndata.host, "fe80::dcad:beff:fe00:0001"); - 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_url_parse__ipv6_user_pass_port(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "https://user:pass@[fe80::dcad:beff:fe00:0001]:9191/resource")); - cl_assert_equal_s(conndata.scheme, "https"); - cl_assert_equal_s(conndata.host, "fe80::dcad:beff:fe00:0001"); - 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); -} - -void test_network_url_parse__ipv6_invalid_addresses(void) -{ - /* Opening bracket missing */ - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "http://fe80::dcad:beff:fe00:0001]/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "http://fe80::dcad:beff:fe00:0001]/")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "http://fe80::dcad:beff:fe00:0001]")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "http://fe80::dcad:beff:fe00:0001]:42")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "http://fe80::dcad:beff:fe00:0001]:")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "https://user:pass%2fis%40bad@fe80::dcad:beff:fe00:0001]:1234/")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "https://user@fe80::dcad:beff:fe00:0001]/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "https://user:pass@fe80::dcad:beff:fe00:0001]/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "https://fe80::dcad:beff:fe00:0001]:9191/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "http://fe80::dcad:beff:fe00:0001]:/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "https://user@fe80::dcad:beff:fe00:0001]:9191/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "https://user:pass@fe80::dcad:beff:fe00:0001]:9191/resource")); - - /* Closing bracket missing */ - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "http://[fe80::dcad:beff:fe00:0001/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "http://[fe80::dcad:beff:fe00:0001/")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "http://[fe80::dcad:beff:fe00:0001")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "http://[fe80::dcad:beff:fe00:0001:42")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "http://[fe80::dcad:beff:fe00:0001:")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "https://user:pass%2fis%40bad@[fe80::dcad:beff:fe00:0001:1234/")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "https://user@[fe80::dcad:beff:fe00:0001/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "https://user:pass@[fe80::dcad:beff:fe00:0001/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "https://[fe80::dcad:beff:fe00:0001:9191/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "http://[fe80::dcad:beff:fe00:0001:/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "https://user@[fe80::dcad:beff:fe00:0001:9191/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "https://user:pass@[fe80::dcad:beff:fe00:0001:9191/resource")); - /* Both brackets missing */ - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "http://fe80::dcad:beff:fe00:0001/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "http://fe80::dcad:beff:fe00:0001/")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "http://fe80::dcad:beff:fe00:0001")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "http://fe80::dcad:beff:fe00:0001:42")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "http://fe80::dcad:beff:fe00:0001:")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "https://user:pass%2fis%40bad@fe80::dcad:beff:fe00:0001:1234/")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "https://user@fe80::dcad:beff:fe00:0001/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "https://user:pass@fe80::dcad:beff:fe00:0001/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "https://fe80::dcad:beff:fe00:0001:9191/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "http://fe80::dcad:beff:fe00:0001:/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "https://user@fe80::dcad:beff:fe00:0001:9191/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "https://user:pass@fe80::dcad:beff:fe00:0001:9191/resource")); - - /* Invalid character inside address */ - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, "http://[fe8o::dcad:beff:fe00:0001]/resource")); -} diff --git a/tests/libgit2/network/url/pattern.c b/tests/libgit2/network/url/pattern.c deleted file mode 100644 index 5e4495f70..000000000 --- a/tests/libgit2/network/url/pattern.c +++ /dev/null @@ -1,103 +0,0 @@ -#include "clar_libgit2.h" -#include "net.h" - -struct url_pattern { - const char *url; - const char *pattern; - bool matches; -}; - -void test_network_url_pattern__single(void) -{ - git_net_url url; - size_t i; - - struct url_pattern url_patterns[] = { - /* Wildcard matches */ - { "https://example.com/", "", false }, - { "https://example.com/", "*", true }, - - /* Literal and wildcard matches */ - { "https://example.com/", "example.com", true }, - { "https://example.com/", ".example.com", true }, - { "https://example.com/", "*.example.com", true }, - { "https://www.example.com/", "www.example.com", true }, - { "https://www.example.com/", ".example.com", true }, - { "https://www.example.com/", "*.example.com", true }, - - /* Literal and wildcard failures */ - { "https://example.com/", "example.org", false }, - { "https://example.com/", ".example.org", false }, - { "https://example.com/", "*.example.org", false }, - { "https://foo.example.com/", "www.example.com", false }, - - /* - * A port in the pattern is optional; if no port is - * present, it matches *all* ports. - */ - { "https://example.com/", "example.com:443", true }, - { "https://example.com/", "example.com:80", false }, - { "https://example.com:1443/", "example.com", true }, - - /* Failures with similar prefix/suffix */ - { "https://texample.com/", "example.com", false }, - { "https://example.com/", "mexample.com", false }, - { "https://example.com:44/", "example.com:443", false }, - { "https://example.com:443/", "example.com:44", false }, - }; - - for (i = 0; i < ARRAY_SIZE(url_patterns); i++) { - cl_git_pass(git_net_url_parse(&url, url_patterns[i].url)); - cl_assert_(git_net_url_matches_pattern(&url, url_patterns[i].pattern) == url_patterns[i].matches, url_patterns[i].pattern); - git_net_url_dispose(&url); - } -} - -void test_network_url_pattern__list(void) -{ - git_net_url url; - size_t i; - - struct url_pattern url_patterns[] = { - /* Wildcard matches */ - { "https://example.com/", "", false }, - { "https://example.com/", "*", true }, - { "https://example.com/", ",example.com,", true }, - { "https://example.com/", "foo,,example.com,,bar", true }, - { "https://example.com/", "foo,,zzz,,*,,bar", true }, - - /* Literals */ - { "https://example.com/", "example.com", true }, - { "https://example.com/", "foo.bar,example.com", true }, - { "https://example.com/", "foo.bar", false }, - { "https://example.com/", "foo.bar,example.org", false }, - { "https://www.example.com/", "foo.example.com,www.example.com,bar.example.com", true }, - { "https://www.example.com/", "foo.example.com,baz.example.com,bar.example.com", false }, - { "https://foo.example.com/", "www.example.com", false }, - { "https://foo.example.com/", "bar.example.com,www.example.com,", false }, - - /* Wildcards */ - { "https://example.com/", ".example.com", true }, - { "https://example.com/", "*.example.com", true }, - { "https://example.com/", "foo.com,bar.com,.example.com", true }, - { "https://example.com/", ".foo.com,.bar.com,.example.com", true }, - { "https://example.com/", ".foo.com,.bar.com,asdf.com", false }, - { "https://example.com/", "*.foo,*.bar,*.example.com,*.asdf", true }, - { "https://example.com/", "*.foo,*.bar,*.asdf", false }, - - - /* Ports! */ - { "https://example.com/", "example.com:443", true }, - { "https://example.com/", "example.com:42,example.com:443,example.com:99", true }, - { "https://example.com/", "example.com:42,example.com:80,example.org:443", false }, - { "https://example.com:1443/", "example.com", true }, - { "https://example.com:44/", "example.com:443", false }, - { "https://example.com:443/", "example.com:44", false }, - }; - - for (i = 0; i < ARRAY_SIZE(url_patterns); i++) { - cl_git_pass(git_net_url_parse(&url, url_patterns[i].url)); - cl_assert_(git_net_url_matches_pattern_list(&url, url_patterns[i].pattern) == url_patterns[i].matches, url_patterns[i].pattern); - git_net_url_dispose(&url); - } -} diff --git a/tests/libgit2/network/url/redirect.c b/tests/libgit2/network/url/redirect.c deleted file mode 100644 index a94db7daf..000000000 --- a/tests/libgit2/network/url/redirect.c +++ /dev/null @@ -1,147 +0,0 @@ -#include "clar_libgit2.h" -#include "net.h" -#include "netops.h" - -static git_net_url conndata; - -void test_network_url_redirect__initialize(void) -{ - memset(&conndata, 0, sizeof(conndata)); -} - -void test_network_url_redirect__cleanup(void) -{ - git_net_url_dispose(&conndata); -} - -void test_network_url_redirect__redirect_http(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "http://example.com/foo/bar/baz")); - cl_git_pass(git_net_url_apply_redirect(&conndata, - "http://example.com/foo/bar/baz", false, "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_url_redirect__redirect_ssl(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "https://example.com/foo/bar/baz")); - cl_git_pass(git_net_url_apply_redirect(&conndata, - "https://example.com/foo/bar/baz", false, "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_url_redirect__redirect_leaves_root_path(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "https://example.com/foo/bar/baz")); - cl_git_pass(git_net_url_apply_redirect(&conndata, - "https://example.com/foo/bar/baz", false, "/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_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")); - cl_git_pass(git_net_url_apply_redirect(&conndata, - "https://user%2fname:pass%40word%zyx%v@example.com/foo/bar/baz", false, "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_url_redirect__redirect_cross_host_allowed(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "https://bar.com/bar/baz")); - cl_git_pass(git_net_url_apply_redirect(&conndata, - "https://foo.com/bar/baz", true, 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, "/bar/baz"); - cl_assert_equal_p(conndata.username, NULL); - cl_assert_equal_p(conndata.password, NULL); -} - -void test_network_url_redirect__redirect_cross_host_denied(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "https://bar.com/bar/baz")); - cl_git_fail_with(git_net_url_apply_redirect(&conndata, - "https://foo.com/bar/baz", false, NULL), -1); -} - -void test_network_url_redirect__redirect_http_downgrade_denied(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "https://foo.com/bar/baz")); - cl_git_fail_with(git_net_url_apply_redirect(&conndata, - "http://foo.com/bar/baz", true, NULL), -1); -} - -void test_network_url_redirect__redirect_relative(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "http://foo.com/bar/baz/biff")); - cl_git_pass(git_net_url_apply_redirect(&conndata, - "/zap/baz/biff?bam", true, 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_url_redirect__redirect_relative_ssl(void) -{ - cl_git_pass(git_net_url_parse(&conndata, - "https://foo.com/bar/baz/biff")); - cl_git_pass(git_net_url_apply_redirect(&conndata, - "/zap/baz/biff?bam", true, 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); -} - -void test_network_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")); - cl_git_pass(git_net_url_apply_redirect(&conndata, - "/baz/info/refs", true, "/info/refs?service=git-upload-pack")); - cl_assert_equal_s(conndata.path, "/baz"); -} - -void test_network_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")); - cl_git_pass(git_net_url_apply_redirect(&conndata, - "/baz/info/refs?service=git-upload-pack", true, "/info/refs?service=git-upload-pack")); - cl_assert_equal_s(conndata.path, "/baz"); -} diff --git a/tests/libgit2/network/url/scp.c b/tests/libgit2/network/url/scp.c deleted file mode 100644 index 8cdc832ae..000000000 --- a/tests/libgit2/network/url/scp.c +++ /dev/null @@ -1,321 +0,0 @@ -#include "clar_libgit2.h" -#include "net.h" - -static git_net_url conndata; - -void test_network_url_scp__initialize(void) -{ - memset(&conndata, 0, sizeof(conndata)); -} - -void test_network_url_scp__cleanup(void) -{ - git_net_url_dispose(&conndata); -} - -/* Hostname */ - -void test_network_url_scp__hostname_trivial(void) -{ - cl_git_pass(git_net_url_parse_scp(&conndata, "example.com:/resource")); - cl_assert_equal_s(conndata.scheme, "ssh"); - cl_assert_equal_s(conndata.host, "example.com"); - cl_assert_equal_s(conndata.port, "22"); - 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_url_scp__hostname_bracketed(void) -{ - cl_git_pass(git_net_url_parse_scp(&conndata, "[example.com]:/resource")); - cl_assert_equal_s(conndata.scheme, "ssh"); - cl_assert_equal_s(conndata.host, "example.com"); - cl_assert_equal_s(conndata.port, "22"); - 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_url_scp__hostname_root(void) -{ - cl_git_pass(git_net_url_parse_scp(&conndata, "example.com:/")); - cl_assert_equal_s(conndata.scheme, "ssh"); - cl_assert_equal_s(conndata.host, "example.com"); - cl_assert_equal_s(conndata.port, "22"); - 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_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"); - cl_assert_equal_s(conndata.host, "example.com"); - cl_assert_equal_s(conndata.port, "22"); - cl_assert_equal_s(conndata.path, "/resource"); - cl_assert_equal_s(conndata.username, "git"); - cl_assert_equal_p(conndata.password, NULL); - cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); -} - -void test_network_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"); - cl_assert_equal_s(conndata.host, "example.com"); - cl_assert_equal_s(conndata.port, "22"); - cl_assert_equal_s(conndata.path, "/resource"); - cl_assert_equal_s(conndata.username, "git"); - cl_assert_equal_p(conndata.password, NULL); - cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); -} - -void test_network_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"); - cl_assert_equal_s(conndata.host, "example.com"); - cl_assert_equal_s(conndata.port, "42"); - 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_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"); - cl_assert_equal_s(conndata.host, "example.com"); - cl_assert_equal_s(conndata.port, "42"); - cl_assert_equal_s(conndata.path, "/resource"); - cl_assert_equal_s(conndata.username, "git"); - cl_assert_equal_p(conndata.password, NULL); - cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); -} - -void test_network_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"); - cl_assert_equal_s(conndata.host, "192.168.99.88"); - cl_assert_equal_s(conndata.port, "22"); - cl_assert_equal_s(conndata.path, "/resource/a/b/c"); - 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_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"); - cl_assert_equal_s(conndata.host, "192.168.99.88"); - cl_assert_equal_s(conndata.port, "22"); - cl_assert_equal_s(conndata.path, "/resource/a/b/c"); - 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_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"); - cl_assert_equal_s(conndata.host, "192.168.99.88"); - cl_assert_equal_s(conndata.port, "22"); - cl_assert_equal_s(conndata.path, "/resource/a/b/c"); - cl_assert_equal_s(conndata.username, "git"); - cl_assert_equal_p(conndata.password, NULL); - cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); -} - -void test_network_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"); - cl_assert_equal_s(conndata.host, "192.168.99.88"); - cl_assert_equal_s(conndata.port, "1111"); - cl_assert_equal_s(conndata.path, "/resource/a/b/c"); - 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_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"); - cl_assert_equal_s(conndata.host, "192.168.99.88"); - cl_assert_equal_s(conndata.port, "1111"); - cl_assert_equal_s(conndata.path, "/resource/a/b/c"); - cl_assert_equal_s(conndata.username, "git"); - cl_assert_equal_p(conndata.password, NULL); - cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); -} - -void test_network_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"); - cl_assert_equal_s(conndata.host, "[fe80::dcad:beff:fe00:0001]"); - cl_assert_equal_s(conndata.port, "22"); - cl_assert_equal_s(conndata.path, "/resource/foo"); - 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_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"); - cl_assert_equal_s(conndata.host, "[fe80::dcad:beff:fe00:0001]"); - cl_assert_equal_s(conndata.port, "22"); - cl_assert_equal_s(conndata.path, "/resource/foo"); - cl_assert_equal_s(conndata.username, "git"); - cl_assert_equal_p(conndata.password, NULL); - cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); -} - -void test_network_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"); - cl_assert_equal_s(conndata.host, "[fe80::dcad:beff:fe00:0001]"); - cl_assert_equal_s(conndata.port, "99"); - cl_assert_equal_s(conndata.path, "/resource/foo"); - 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_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"); - cl_assert_equal_s(conndata.host, "[fe80::dcad:beff:fe00:0001]"); - cl_assert_equal_s(conndata.port, "99"); - cl_assert_equal_s(conndata.path, "/resource/foo"); - cl_assert_equal_s(conndata.username, "git"); - cl_assert_equal_p(conndata.password, NULL); - cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); -} - -void test_network_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"); - cl_assert_equal_s(conndata.host, "fe"); - cl_assert_equal_s(conndata.port, "22"); - cl_assert_equal_s(conndata.path, "/resource/foo"); - 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_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"); - cl_assert_equal_s(conndata.host, "fe80"); - cl_assert_equal_s(conndata.port, "22"); - cl_assert_equal_s(conndata.path, ":dcad:beff:fe00:0001]:/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_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"); - cl_assert_equal_s(conndata.host, "[fe80::dcad:beff:fe00:0001]"); - cl_assert_equal_s(conndata.port, "22"); - cl_assert_equal_s(conndata.path, "42]:/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_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"); - cl_assert_equal_s(conndata.host, "[fe80::dcad:beff:fe00:0001]"); - cl_assert_equal_s(conndata.port, "22"); - cl_assert_equal_s(conndata.path, "42]:/resource"); - cl_assert_equal_s(conndata.username, "git"); - cl_assert_equal_p(conndata.password, NULL); - cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); -} - -void test_network_url_scp__invalid_addresses(void) -{ - /* Path is required */ - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "example.com")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "example.com:")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "[example.com:42]:")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "[git@example.com:42]:")); - - /* Host is required */ - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - ":")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - ":foo")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "git@:foo")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "[]:")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "git@[]:")); - - /* User is required if specified */ - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "@example.com:foo")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "@:foo")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "[@localhost:22]:foo")); - - /* Port is required in brackets */ - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "[example.com:]:foo")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "[git@example.com:]:foo")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "[fe:]:foo")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "[@localhost]:foo")); - - /* Extra brackets are disallowed */ - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "[git@[[fe80::dcad:beff:fe00:0001]]:42]:foo")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "[[git@[fe80::dcad:beff:fe00:0001]]:42]:foo")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "[[git@[fe80::dcad:beff:fe00:0001]:42]]:foo")); - - /* Closing bracket missing */ - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "[fe80::dcad:beff:fe00:0001:/resource")); - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, - "[[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")); - 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")); -} diff --git a/tests/libgit2/network/url/valid.c b/tests/libgit2/network/url/valid.c deleted file mode 100644 index 2b2cb7ba4..000000000 --- a/tests/libgit2/network/url/valid.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "clar_libgit2.h" -#include "net.h" - -void test_network_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/")); - cl_assert(git_net_str_is_url("ssh://user@host:42/tmp")); - cl_assert(git_net_str_is_url("git+ssh://user@host:42/tmp")); - cl_assert(git_net_str_is_url("ssh+git://user@host:42/tmp")); - cl_assert(git_net_str_is_url("https://user:pass@example.com/foo/bar")); - - cl_assert(!git_net_str_is_url("host:foo.git")); - cl_assert(!git_net_str_is_url("host:/foo.git")); - cl_assert(!git_net_str_is_url("[host:42]:/foo.git")); - cl_assert(!git_net_str_is_url("[user@host:42]:/foo.git")); -} diff --git a/tests/libgit2/object/commit/parse.c b/tests/libgit2/object/commit/parse.c index 28a3ccd85..6f9a65507 100644 --- a/tests/libgit2/object/commit/parse.c +++ b/tests/libgit2/object/commit/parse.c @@ -3,7 +3,10 @@ #include "object.h" #include "signature.h" -static void assert_commit_parses(const char *data, size_t datalen, +static void assert_commit_parses( + const char *data, + size_t datalen, + git_oid_t oid_type, const char *expected_treeid, const char *expected_author, const char *expected_committer, @@ -14,7 +17,7 @@ static void assert_commit_parses(const char *data, size_t datalen, git_commit *commit; if (!datalen) datalen = strlen(data); - cl_git_pass(git_object__from_raw((git_object **) &commit, data, datalen, GIT_OBJECT_COMMIT)); + cl_git_pass(git_object__from_raw((git_object **) &commit, data, datalen, GIT_OBJECT_COMMIT, oid_type)); if (expected_author) { git_signature *author; @@ -51,7 +54,7 @@ static void assert_commit_parses(const char *data, size_t datalen, if (expected_treeid) { git_oid tree_oid; - cl_git_pass(git_oid__fromstr(&tree_oid, expected_treeid, GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&tree_oid, expected_treeid, oid_type)); cl_assert_equal_oid(&tree_oid, &commit->tree_id); } @@ -60,15 +63,18 @@ static void assert_commit_parses(const char *data, size_t datalen, git_object__free(&commit->object); } -static void assert_commit_fails(const char *data, size_t datalen) +static void assert_commit_fails( + const char *data, + size_t datalen, + git_oid_t oid_type) { git_object *object; if (!datalen) datalen = strlen(data); - cl_git_fail(git_object__from_raw(&object, data, datalen, GIT_OBJECT_COMMIT)); + cl_git_fail(git_object__from_raw(&object, data, datalen, GIT_OBJECT_COMMIT, oid_type)); } -void test_object_commit_parse__parsing_commit_succeeds(void) +void test_object_commit_parse__sha1_parsing_commit_succeeds(void) { const char *commit = "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" @@ -77,7 +83,7 @@ void test_object_commit_parse__parsing_commit_succeeds(void) "encoding Encoding\n" "\n" "Message"; - assert_commit_parses(commit, 0, + assert_commit_parses(commit, 0, GIT_OID_SHA1, "3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8", "Author <author@example.com>", "Committer <committer@example.com>", @@ -85,7 +91,7 @@ void test_object_commit_parse__parsing_commit_succeeds(void) "Message", 0); } -void test_object_commit_parse__parsing_commit_without_encoding_succeeds(void) +void test_object_commit_parse__sha1_parsing_commit_without_encoding_succeeds(void) { const char *commit = "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" @@ -93,7 +99,7 @@ void test_object_commit_parse__parsing_commit_without_encoding_succeeds(void) "committer Committer <committer@example.com>\n" "\n" "Message"; - assert_commit_parses(commit, 0, + assert_commit_parses(commit, 0, GIT_OID_SHA1, "3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8", "Author <author@example.com>", "Committer <committer@example.com>", @@ -101,7 +107,7 @@ void test_object_commit_parse__parsing_commit_without_encoding_succeeds(void) "Message", 0); } -void test_object_commit_parse__parsing_commit_with_multiple_authors_succeeds(void) +void test_object_commit_parse__sha1_parsing_commit_with_multiple_authors_succeeds(void) { const char *commit = "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" @@ -112,7 +118,7 @@ void test_object_commit_parse__parsing_commit_with_multiple_authors_succeeds(voi "committer Committer <committer@example.com>\n" "\n" "Message"; - assert_commit_parses(commit, 0, + assert_commit_parses(commit, 0, GIT_OID_SHA1, "3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8", "Author1 <author@example.com>", "Committer <committer@example.com>", @@ -120,7 +126,7 @@ void test_object_commit_parse__parsing_commit_with_multiple_authors_succeeds(voi "Message", 0); } -void test_object_commit_parse__parsing_commit_with_multiple_committers_succeeds(void) +void test_object_commit_parse__sha1_parsing_commit_with_multiple_committers_succeeds(void) { const char *commit = "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" @@ -131,7 +137,7 @@ void test_object_commit_parse__parsing_commit_with_multiple_committers_succeeds( "committer Committer4 <committer@example.com>\n" "\n" "Message"; - assert_commit_parses(commit, 0, + assert_commit_parses(commit, 0, GIT_OID_SHA1, "3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8", "Author <author@example.com>", "Committer1 <committer@example.com>", @@ -139,13 +145,13 @@ void test_object_commit_parse__parsing_commit_with_multiple_committers_succeeds( "Message", 0); } -void test_object_commit_parse__parsing_commit_without_message_succeeds(void) +void test_object_commit_parse__sha1_parsing_commit_without_message_succeeds(void) { const char *commit = "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" "author Author <author@example.com>\n" "committer Committer <committer@example.com>\n"; - assert_commit_parses(commit, 0, + assert_commit_parses(commit, 0, GIT_OID_SHA1, "3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8", "Author <author@example.com>", "Committer <committer@example.com>", @@ -153,7 +159,7 @@ void test_object_commit_parse__parsing_commit_without_message_succeeds(void) "", 0); } -void test_object_commit_parse__parsing_commit_with_unknown_fields_succeeds(void) +void test_object_commit_parse__sha1_parsing_commit_with_unknown_fields_succeeds(void) { const char *commit = "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" @@ -163,7 +169,7 @@ void test_object_commit_parse__parsing_commit_with_unknown_fields_succeeds(void) "more garbage\n" "\n" "Message"; - assert_commit_parses(commit, 0, + assert_commit_parses(commit, 0, GIT_OID_SHA1, "3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8", "Author <author@example.com>", "Committer <committer@example.com>", @@ -171,7 +177,7 @@ void test_object_commit_parse__parsing_commit_with_unknown_fields_succeeds(void) "Message", 0); } -void test_object_commit_parse__parsing_commit_with_invalid_tree_fails(void) +void test_object_commit_parse__sha1_parsing_commit_with_invalid_tree_fails(void) { const char *commit = "tree 3e7ac388cadacccdf1xxx5f3445895b71d9cb0f8\n" @@ -179,40 +185,51 @@ void test_object_commit_parse__parsing_commit_with_invalid_tree_fails(void) "committer Committer <committer@example.com>\n" "\n" "Message"; - assert_commit_fails(commit, 0); + assert_commit_fails(commit, 0, GIT_OID_SHA1); } -void test_object_commit_parse__parsing_commit_without_tree_fails(void) +void test_object_commit_parse__sha1_parsing_commit_with_sha256_tree_fails(void) { const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" "author Author <author@example.com>\n" "committer Committer <committer@example.com>\n" "\n" "Message"; - assert_commit_fails(commit, 0); + assert_commit_fails(commit, 0, GIT_OID_SHA1); } -void test_object_commit_parse__parsing_commit_without_author_fails(void) +void test_object_commit_parse__sha1_parsing_commit_without_tree_fails(void) +{ + const char *commit = + "author Author <author@example.com>\n" + "committer Committer <committer@example.com>\n" + "\n" + "Message"; + assert_commit_fails(commit, 0, GIT_OID_SHA1); +} + +void test_object_commit_parse__sha1_parsing_commit_without_author_fails(void) { const char *commit = "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" "committer Committer <committer@example.com>\n" "\n" "Message"; - assert_commit_fails(commit, 0); + assert_commit_fails(commit, 0, GIT_OID_SHA1); } -void test_object_commit_parse__parsing_commit_without_committer_fails(void) +void test_object_commit_parse__sha1_parsing_commit_without_committer_fails(void) { const char *commit = "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" "author Author <author@example.com>\n" "\n" "Message"; - assert_commit_fails(commit, 0); + assert_commit_fails(commit, 0, GIT_OID_SHA1); } -void test_object_commit_parse__parsing_encoding_will_not_cause_oob_read(void) +void test_object_commit_parse__sha1_parsing_encoding_will_not_cause_oob_read(void) { const char *commit = "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" @@ -223,10 +240,237 @@ void test_object_commit_parse__parsing_encoding_will_not_cause_oob_read(void) * As we ignore unknown fields, the cut-off encoding field will be * parsed just fine. */ - assert_commit_parses(commit, strlen(commit) - strlen("ncoding foo\n"), + assert_commit_parses( + commit, strlen(commit) - strlen("ncoding foo\n"), + GIT_OID_SHA1, "3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8", "<>", "<>", NULL, "", 0); } + + +void test_object_commit_parse__sha256_parsing_commit_succeeds(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author Author <author@example.com>\n" + "committer Committer <committer@example.com>\n" + "encoding Encoding\n" + "\n" + "Message"; + assert_commit_parses(commit, 0, GIT_OID_SHA256, + "f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736", + "Author <author@example.com>", + "Committer <committer@example.com>", + "Encoding", + "Message", 0); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_without_encoding_succeeds(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author Author <author@example.com>\n" + "committer Committer <committer@example.com>\n" + "\n" + "Message"; + assert_commit_parses(commit, 0, GIT_OID_SHA256, + "f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736", + "Author <author@example.com>", + "Committer <committer@example.com>", + NULL, + "Message", 0); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_with_multiple_authors_succeeds(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author Author1 <author@example.com>\n" + "author Author2 <author@example.com>\n" + "author Author3 <author@example.com>\n" + "author Author4 <author@example.com>\n" + "committer Committer <committer@example.com>\n" + "\n" + "Message"; + assert_commit_parses(commit, 0, GIT_OID_SHA256, + "f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736", + "Author1 <author@example.com>", + "Committer <committer@example.com>", + NULL, + "Message", 0); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_with_multiple_committers_succeeds(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author Author <author@example.com>\n" + "committer Committer1 <committer@example.com>\n" + "committer Committer2 <committer@example.com>\n" + "committer Committer3 <committer@example.com>\n" + "committer Committer4 <committer@example.com>\n" + "\n" + "Message"; + assert_commit_parses(commit, 0, GIT_OID_SHA256, + "f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736", + "Author <author@example.com>", + "Committer1 <committer@example.com>", + NULL, + "Message", 0); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_without_message_succeeds(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author Author <author@example.com>\n" + "committer Committer <committer@example.com>\n"; + assert_commit_parses(commit, 0, GIT_OID_SHA256, + "f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736", + "Author <author@example.com>", + "Committer <committer@example.com>", + NULL, + "", 0); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_with_unknown_fields_succeeds(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author Author <author@example.com>\n" + "committer Committer <committer@example.com>\n" + "foo bar\n" + "more garbage\n" + "\n" + "Message"; + assert_commit_parses(commit, 0, GIT_OID_SHA256, + "f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736", + "Author <author@example.com>", + "Committer <committer@example.com>", + NULL, + "Message", 0); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_with_invalid_tree_fails(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9adxxxd55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author Author <author@example.com>\n" + "committer Committer <committer@example.com>\n" + "\n" + "Message"; + assert_commit_fails(commit, 0, GIT_OID_SHA256); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_with_sha1_tree_fails(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" + "author Author <author@example.com>\n" + "committer Committer <committer@example.com>\n" + "\n" + "Message"; + assert_commit_fails(commit, 0, GIT_OID_SHA256); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_without_tree_fails(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "author Author <author@example.com>\n" + "committer Committer <committer@example.com>\n" + "\n" + "Message"; + assert_commit_fails(commit, 0, GIT_OID_SHA256); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_without_author_fails(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "committer Committer <committer@example.com>\n" + "\n" + "Message"; + assert_commit_fails(commit, 0, GIT_OID_SHA256); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_without_committer_fails(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author Author <author@example.com>\n" + "\n" + "Message"; + assert_commit_fails(commit, 0, GIT_OID_SHA256); +#endif +} + +void test_object_commit_parse__sha256_parsing_encoding_will_not_cause_oob_read(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author <>\n" + "committer <>\n" + "encoding foo\n"; + /* + * As we ignore unknown fields, the cut-off encoding field will be + * parsed just fine. + */ + assert_commit_parses( + commit, strlen(commit) - strlen("ncoding foo\n"), + GIT_OID_SHA256, + "f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736", + "<>", + "<>", + NULL, + "", 0); +#endif +} diff --git a/tests/libgit2/object/lookup256.c b/tests/libgit2/object/lookup256.c new file mode 100644 index 000000000..3e1dab661 --- /dev/null +++ b/tests/libgit2/object/lookup256.c @@ -0,0 +1,153 @@ +#include "clar_libgit2.h" + +#include "repository.h" + +#ifdef GIT_EXPERIMENTAL_SHA256 +static git_repository *g_repo; +#endif + +void test_object_lookup256__initialize(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + g_repo = cl_git_sandbox_init("testrepo_256.git"); +#endif +} + +void test_object_lookup256__cleanup(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_sandbox_cleanup(); +#endif +} + +void test_object_lookup256__lookup_wrong_type_returns_enotfound(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = "4d46d9719e425ef2dfb5bfba098d0b62e21b2b92d0731892eef70db0870e3744"; + git_oid oid; + git_object *object; + + cl_git_pass(git_oid__fromstr(&oid, commit, GIT_OID_SHA256)); + cl_assert_equal_i( + GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_TAG)); +#endif +} + +void test_object_lookup256__lookup_nonexisting_returns_enotfound(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *unknown = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"; + git_oid oid; + git_object *object; + + cl_git_pass(git_oid__fromstr(&oid, unknown, GIT_OID_SHA256)); + cl_assert_equal_i( + GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_ANY)); +#endif +} + +void test_object_lookup256__lookup_wrong_type_by_abbreviated_id_returns_enotfound(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = "4d46d97"; + git_oid oid; + git_object *object; + + cl_git_pass(git_oid__fromstrn(&oid, commit, strlen(commit), GIT_OID_SHA256)); + cl_assert_equal_i( + GIT_ENOTFOUND, git_object_lookup_prefix(&object, g_repo, &oid, strlen(commit), GIT_OBJECT_TAG)); +#endif +} + +void test_object_lookup256__lookup_wrong_type_eventually_returns_enotfound(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = "4d46d9719e425ef2dfb5bfba098d0b62e21b2b92d0731892eef70db0870e3744"; + git_oid oid; + git_object *object; + + cl_git_pass(git_oid__fromstr(&oid, commit, GIT_OID_SHA256)); + + cl_git_pass(git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_COMMIT)); + git_object_free(object); + + cl_assert_equal_i( + GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_TAG)); +#endif +} + +void test_object_lookup256__lookup_corrupt_object_returns_error(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = "5ca8959deb2b8327458e0344523eb1ddeeef4bce03e35864640b452f84d26848", + *file = "objects/5c/a8959deb2b8327458e0344523eb1ddeeef4bce03e35864640b452f84d26848"; + git_str path = GIT_STR_INIT, contents = GIT_STR_INIT; + git_oid oid; + git_object *object; + size_t i; + + cl_git_pass(git_oid__fromstr(&oid, commit, GIT_OID_SHA256)); + cl_git_pass(git_str_joinpath(&path, git_repository_path(g_repo), file)); + cl_git_pass(git_futils_readbuffer(&contents, path.ptr)); + + /* Corrupt and try to read the object */ + for (i = 0; i < contents.size; i++) { + contents.ptr[i] ^= 0x1; + cl_git_pass(git_futils_writebuffer(&contents, path.ptr, O_RDWR, 0644)); + cl_git_fail(git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_COMMIT)); + contents.ptr[i] ^= 0x1; + } + + /* Restore original content and assert we can read the object */ + cl_git_pass(git_futils_writebuffer(&contents, path.ptr, O_RDWR, 0644)); + cl_git_pass(git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_COMMIT)); + + git_object_free(object); + git_str_dispose(&path); + git_str_dispose(&contents); +#endif +} + +void test_object_lookup256__lookup_object_with_wrong_hash_returns_error(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *oldloose = "objects/5c/a8959deb2b8327458e0344523eb1ddeeef4bce03e35864640b452f84d26848", + *newloose = "objects/5c/a8959deb2b8327458e0344523eb1ddeeef4bce03e35864640b452f84d26840", + *commit = "5ca8959deb2b8327458e0344523eb1ddeeef4bce03e35864640b452f84d26840"; + + git_str oldpath = GIT_STR_INIT, newpath = GIT_STR_INIT; + git_object *object; + git_oid oid; + + cl_git_pass(git_oid__fromstr(&oid, commit, GIT_OID_SHA256)); + + /* Copy object to another location with wrong hash */ + cl_git_pass(git_str_joinpath(&oldpath, git_repository_path(g_repo), oldloose)); + cl_git_pass(git_str_joinpath(&newpath, git_repository_path(g_repo), newloose)); + cl_git_pass(git_futils_cp(oldpath.ptr, newpath.ptr, 0644)); + + /* Verify that lookup fails due to a hashsum mismatch */ + cl_git_fail_with(GIT_EMISMATCH, git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_COMMIT)); + + /* Disable verification and try again */ + cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 0)); + cl_git_pass(git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_COMMIT)); + cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 1)); + + git_object_free(object); + git_str_dispose(&oldpath); + git_str_dispose(&newpath); +#endif +} diff --git a/tests/libgit2/object/tag/parse.c b/tests/libgit2/object/tag/parse.c index 92298b5ce..d7a4d85bf 100644 --- a/tests/libgit2/object/tag/parse.c +++ b/tests/libgit2/object/tag/parse.c @@ -14,7 +14,7 @@ static void assert_tag_parses(const char *data, size_t datalen, if (!datalen) datalen = strlen(data); - cl_git_pass(git_object__from_raw((git_object **) &tag, data, datalen, GIT_OBJECT_TAG)); + cl_git_pass(git_object__from_raw((git_object **) &tag, data, datalen, GIT_OBJECT_TAG, GIT_OID_SHA1)); cl_assert_equal_i(tag->type, GIT_OBJECT_TAG); if (expected_oid) { @@ -54,7 +54,7 @@ static void assert_tag_fails(const char *data, size_t datalen) git_object *object; if (!datalen) datalen = strlen(data); - cl_git_fail(git_object__from_raw(&object, data, datalen, GIT_OBJECT_TAG)); + cl_git_fail(git_object__from_raw(&object, data, datalen, GIT_OBJECT_TAG, GIT_OID_SHA1)); } void test_object_tag_parse__valid_tag_parses(void) diff --git a/tests/libgit2/object/tree/parse.c b/tests/libgit2/object/tree/parse.c index d6d6e5302..fc985d672 100644 --- a/tests/libgit2/object/tree/parse.c +++ b/tests/libgit2/object/tree/parse.c @@ -26,7 +26,7 @@ static void assert_tree_parses(const char *data, size_t datalen, if (!datalen) datalen = strlen(data); - cl_git_pass(git_object__from_raw((git_object **) &tree, data, datalen, GIT_OBJECT_TREE)); + cl_git_pass(git_object__from_raw((git_object **) &tree, data, datalen, GIT_OBJECT_TREE, GIT_OID_SHA1)); cl_assert_equal_i(git_tree_entrycount(tree), expected_nentries); @@ -51,7 +51,7 @@ static void assert_tree_fails(const char *data, size_t datalen) git_object *object; if (!datalen) datalen = strlen(data); - cl_git_fail(git_object__from_raw(&object, data, datalen, GIT_OBJECT_TREE)); + cl_git_fail(git_object__from_raw(&object, data, datalen, GIT_OBJECT_TREE, GIT_OID_SHA1)); } void test_object_tree_parse__single_blob_parses(void) diff --git a/tests/libgit2/object/validate.c b/tests/libgit2/object/validate.c index 87193deb6..e11038115 100644 --- a/tests/libgit2/object/validate.c +++ b/tests/libgit2/object/validate.c @@ -1,50 +1,154 @@ #include "clar_libgit2.h" -#define VALID_COMMIT "tree bdd24e358576f1baa275df98cdcaf3ac9a3f4233\n" \ - "parent d6d956f1d66210bfcd0484166befab33b5987a39\n" \ - "author Edward Thomson <ethomson@edwardthomson.com> 1638286404 -0500\n" \ - "committer Edward Thomson <ethomson@edwardthomson.com> 1638324642 -0500\n" \ - "\n" \ - "commit go here.\n" -#define VALID_TREE "100644 HEADER\0\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42" - -#define INVALID_COMMIT "tree bdd24e358576f1baa275df98cdcaf3ac9a3f4233\n" \ - "parent d6d956f1d66210bfcd0484166befab33b5987a39\n" \ - "committer Edward Thomson <ethomson@edwardthomson.com> 1638324642 -0500\n" \ - "\n" \ - "commit go here.\n" -#define INVALID_TREE "100644 HEADER \x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42" - -void test_object_validate__valid(void) +#define VALID_COMMIT_SHA1 \ + "tree bdd24e358576f1baa275df98cdcaf3ac9a3f4233\n" \ + "parent d6d956f1d66210bfcd0484166befab33b5987a39\n" \ + "author Edward Thomson <ethomson@edwardthomson.com> 1638286404 -0500\n" \ + "committer Edward Thomson <ethomson@edwardthomson.com> 1638324642 -0500\n" \ + "\n" \ + "commit go here.\n" + +#define VALID_TREE_SHA1 \ + "100644 HEADER\0\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42" + +#define INVALID_COMMIT_SHA1 \ + "tree bdd24e358576f1baa275df98cdcaf3ac9a3f4233\n" \ + "parent d6d956f1d66210bfcd0484166befab33b5987a39\n" \ + "committer Edward Thomson <ethomson@edwardthomson.com> 1638324642 -0500\n" \ + "\n" \ + "commit go here.\n" + +#define INVALID_TREE_SHA1 \ + "100644 HEADER \x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42" + +#define VALID_COMMIT_SHA256 \ + "tree d0fc7f52dc42358506e7f3f3be72f5271994abb104b9397ab3e19bb42361504d\n" \ + "parent 652412419a24ba62a1d897f40aeb80eecbf873797b04a1bbb8d71918653ef65b\n" \ + "author Edward Thomson <ethomson@edwardthomson.com> 1638286404 -0500\n" \ + "committer Edward Thomson <ethomson@edwardthomson.com> 1638324642 -0500\n" \ + "\n" \ + "commit go here.\n" + +#define VALID_TREE_SHA256 \ + "100644 HEADER\0\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42" + +#define INVALID_COMMIT_SHA256 \ + "tree d0fc7f52dc42358506e7f3f3be72f5271994abb104b9397ab3e19bb42361504d\n" \ + "parent 652412419a24ba62a1d897f40aeb80eecbf873797b04a1bbb8d71918653ef65b\n" \ + "committer Edward Thomson <ethomson@edwardthomson.com> 1638324642 -0500\n" \ + "\n" \ + "commit go here.\n" + +#define INVALID_TREE_SHA256 \ + "100644 HEADER \x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42" + +#ifdef GIT_EXPERIMENTAL_SHA256 +# define sha1_rawcontent_is_valid(v, c, l, t) \ + git_object_rawcontent_is_valid(v, c, l, t, GIT_OID_SHA1) +#else +# define sha1_rawcontent_is_valid(v, c, l, t) \ + git_object_rawcontent_is_valid(v, c, l, t) +#endif + +void test_object_validate__valid_sha1(void) +{ + int valid; + + cl_git_pass(sha1_rawcontent_is_valid(&valid, "", 0, GIT_OBJECT_BLOB)); + cl_assert_equal_i(1, valid); + + cl_git_pass(sha1_rawcontent_is_valid(&valid, "foobar", 0, GIT_OBJECT_BLOB)); + cl_assert_equal_i(1, valid); + + cl_git_pass(sha1_rawcontent_is_valid(&valid, VALID_COMMIT_SHA1, CONST_STRLEN(VALID_COMMIT_SHA1), GIT_OBJECT_COMMIT)); + cl_assert_equal_i(1, valid); + + cl_git_pass(sha1_rawcontent_is_valid(&valid, VALID_TREE_SHA1, CONST_STRLEN(VALID_TREE_SHA1), GIT_OBJECT_TREE)); + cl_assert_equal_i(1, valid); +} + +void test_object_validate__cannot_parse_sha256_as_sha1(void) +{ + int valid; + + cl_git_pass(sha1_rawcontent_is_valid(&valid, VALID_COMMIT_SHA256, CONST_STRLEN(INVALID_COMMIT_SHA256), GIT_OBJECT_COMMIT)); + cl_assert_equal_i(0, valid); + + cl_git_pass(sha1_rawcontent_is_valid(&valid, INVALID_TREE_SHA256, CONST_STRLEN(INVALID_TREE_SHA256), GIT_OBJECT_TREE)); + cl_assert_equal_i(0, valid); +} + +void test_object_validate__invalid_sha1(void) { int valid; - cl_git_pass(git_object_rawcontent_is_valid(&valid, "", 0, GIT_OBJECT_BLOB)); + cl_git_pass(sha1_rawcontent_is_valid(&valid, "", 0, GIT_OBJECT_COMMIT)); + cl_assert_equal_i(0, valid); + + cl_git_pass(sha1_rawcontent_is_valid(&valid, "foobar", 0, GIT_OBJECT_COMMIT)); + cl_assert_equal_i(0, valid); + + cl_git_pass(sha1_rawcontent_is_valid(&valid, INVALID_COMMIT_SHA1, CONST_STRLEN(INVALID_COMMIT_SHA1), GIT_OBJECT_COMMIT)); + cl_assert_equal_i(0, valid); + + cl_git_pass(sha1_rawcontent_is_valid(&valid, INVALID_TREE_SHA1, CONST_STRLEN(INVALID_TREE_SHA1), GIT_OBJECT_TREE)); + cl_assert_equal_i(0, valid); +} + + +void test_object_validate__valid_sha256(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + int valid; + + cl_git_pass(git_object_rawcontent_is_valid(&valid, "", 0, GIT_OBJECT_BLOB, GIT_OID_SHA256)); cl_assert_equal_i(1, valid); - cl_git_pass(git_object_rawcontent_is_valid(&valid, "foobar", 0, GIT_OBJECT_BLOB)); + cl_git_pass(git_object_rawcontent_is_valid(&valid, "foobar", 0, GIT_OBJECT_BLOB, GIT_OID_SHA256)); cl_assert_equal_i(1, valid); - cl_git_pass(git_object_rawcontent_is_valid(&valid, VALID_COMMIT, CONST_STRLEN(VALID_COMMIT), GIT_OBJECT_COMMIT)); + cl_git_pass(git_object_rawcontent_is_valid(&valid, VALID_COMMIT_SHA256, CONST_STRLEN(VALID_COMMIT_SHA256), GIT_OBJECT_COMMIT, GIT_OID_SHA256)); cl_assert_equal_i(1, valid); - cl_git_pass(git_object_rawcontent_is_valid(&valid, VALID_TREE, CONST_STRLEN(VALID_TREE), GIT_OBJECT_TREE)); + cl_git_pass(git_object_rawcontent_is_valid(&valid, VALID_TREE_SHA256, CONST_STRLEN(VALID_TREE_SHA256), GIT_OBJECT_TREE, GIT_OID_SHA256)); cl_assert_equal_i(1, valid); +#endif } -void test_object_validate__invalid(void) +void test_object_validate__invalid_sha256(void) { +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else int valid; - cl_git_pass(git_object_rawcontent_is_valid(&valid, "", 0, GIT_OBJECT_COMMIT)); + cl_git_pass(git_object_rawcontent_is_valid(&valid, "", 0, GIT_OBJECT_COMMIT, GIT_OID_SHA256)); + cl_assert_equal_i(0, valid); + + cl_git_pass(git_object_rawcontent_is_valid(&valid, "foobar", 0, GIT_OBJECT_COMMIT, GIT_OID_SHA256)); cl_assert_equal_i(0, valid); - cl_git_pass(git_object_rawcontent_is_valid(&valid, "foobar", 0, GIT_OBJECT_COMMIT)); + cl_git_pass(git_object_rawcontent_is_valid(&valid, INVALID_COMMIT_SHA256, CONST_STRLEN(INVALID_COMMIT_SHA256), GIT_OBJECT_COMMIT, GIT_OID_SHA256)); cl_assert_equal_i(0, valid); - cl_git_pass(git_object_rawcontent_is_valid(&valid, INVALID_COMMIT, CONST_STRLEN(INVALID_COMMIT), GIT_OBJECT_COMMIT)); + cl_git_pass(git_object_rawcontent_is_valid(&valid, INVALID_TREE_SHA256, CONST_STRLEN(INVALID_TREE_SHA256), GIT_OBJECT_TREE, GIT_OID_SHA256)); + cl_assert_equal_i(0, valid); +#endif +} + +void test_object_validate__cannot_parse_sha1_as_sha256(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + int valid; + + cl_git_pass(git_object_rawcontent_is_valid(&valid, VALID_COMMIT_SHA1, CONST_STRLEN(INVALID_COMMIT_SHA1), GIT_OBJECT_COMMIT, GIT_OID_SHA256)); cl_assert_equal_i(0, valid); - cl_git_pass(git_object_rawcontent_is_valid(&valid, INVALID_TREE, CONST_STRLEN(INVALID_TREE), GIT_OBJECT_TREE)); + cl_git_pass(git_object_rawcontent_is_valid(&valid, INVALID_TREE_SHA1, CONST_STRLEN(INVALID_TREE_SHA1), GIT_OBJECT_TREE, GIT_OID_SHA256)); cl_assert_equal_i(0, valid); +#endif } diff --git a/tests/libgit2/odb/backend/loose.c b/tests/libgit2/odb/backend/loose.c new file mode 100644 index 000000000..781b61d9f --- /dev/null +++ b/tests/libgit2/odb/backend/loose.c @@ -0,0 +1,43 @@ +#include "clar_libgit2.h" +#include "repository.h" +#include "odb.h" +#include "backend_helpers.h" +#include "git2/sys/mempack.h" + +static git_repository *_repo; +static git_odb *_odb; + +void test_odb_backend_loose__initialize(void) +{ + git_odb_backend *backend; + + cl_fixture_sandbox("testrepo.git"); + +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_odb_backend_loose(&backend, "testrepo.git/objects", NULL)); +#else + cl_git_pass(git_odb_backend_loose(&backend, "testrepo.git/objects", 0, 0, 0, 0)); +#endif + + cl_git_pass(git_odb__new(&_odb, NULL)); + cl_git_pass(git_odb_add_backend(_odb, backend, 10)); + cl_git_pass(git_repository_wrap_odb(&_repo, _odb)); +} + +void test_odb_backend_loose__cleanup(void) +{ + git_odb_free(_odb); + git_repository_free(_repo); + + cl_fixture_cleanup("testrepo.git"); +} + +void test_odb_backend_loose__read(void) +{ + git_oid oid; + git_odb_object *obj; + + cl_git_pass(git_oid__fromstr(&oid, "1385f264afb75a56a5bec74243be9b367ba4ca08", GIT_OID_SHA1)); + cl_git_pass(git_odb_read(&obj, _odb, &oid)); + git_odb_object_free(obj); +} diff --git a/tests/libgit2/odb/foreach.c b/tests/libgit2/odb/foreach.c index 165a511a0..56b3e882c 100644 --- a/tests/libgit2/odb/foreach.c +++ b/tests/libgit2/odb/foreach.c @@ -52,7 +52,16 @@ void test_odb_foreach__one_pack(void) int nobj = 0; cl_git_pass(git_odb__new(&_odb, NULL)); - cl_git_pass(git_odb_backend_one_pack(&backend, cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"))); + +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_odb_backend_one_pack(&backend, + cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"), + NULL)); +#else + cl_git_pass(git_odb_backend_one_pack(&backend, + cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"))); +#endif + cl_git_pass(git_odb_add_backend(_odb, backend, 1)); _repo = NULL; diff --git a/tests/libgit2/odb/loose.c b/tests/libgit2/odb/loose.c index e79525478..0409dfb28 100644 --- a/tests/libgit2/odb/loose.c +++ b/tests/libgit2/odb/loose.c @@ -160,7 +160,9 @@ void test_odb_loose__exists_sha1(void) void test_odb_loose__exists_sha256(void) { -#ifdef GIT_EXPERIMENTAL_SHA256 +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else git_oid id, id2; git_odb *odb; git_odb_options odb_opts = GIT_ODB_OPTIONS_INIT; @@ -201,7 +203,9 @@ void test_odb_loose__simple_reads_sha1(void) void test_odb_loose__simple_reads_sha256(void) { -#ifdef GIT_EXPERIMENTAL_SHA256 +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else test_read_object(&commit_sha256); test_read_object(&tree_sha256); test_read_object(&tag_sha256); @@ -230,7 +234,9 @@ void test_odb_loose__streaming_reads_sha1(void) void test_odb_loose__streaming_reads_sha256(void) { -#ifdef GIT_EXPERIMENTAL_SHA256 +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else size_t blocksizes[] = { 1, 2, 4, 16, 99, 1024, 123456789 }; size_t i; @@ -259,7 +265,9 @@ void test_odb_loose__read_header_sha1(void) void test_odb_loose__read_header_sha256(void) { -#ifdef GIT_EXPERIMENTAL_SHA256 +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else test_read_header(&commit_sha256); test_read_header(&tree_sha256); test_read_header(&tag_sha256); diff --git a/tests/libgit2/odb/open.c b/tests/libgit2/odb/open.c new file mode 100644 index 000000000..395406d0f --- /dev/null +++ b/tests/libgit2/odb/open.c @@ -0,0 +1,34 @@ +#include "clar_libgit2.h" + +void test_odb_open__initialize(void) +{ + cl_fixture_sandbox("testrepo.git"); +} + +void test_odb_open__cleanup(void) +{ + cl_fixture_cleanup("testrepo.git"); +} + +void test_odb_open__exists(void) +{ + git_odb *odb; + git_oid one, two; + +#ifdef GIT_EXPERIMENTAL_SHA256 + git_odb_options opts = GIT_ODB_OPTIONS_INIT; + + cl_git_pass(git_odb_open(&odb, "testrepo.git/objects", &opts)); + cl_git_pass(git_oid_fromstr(&one, "1385f264afb75a56a5bec74243be9b367ba4ca08", GIT_OID_SHA1)); + cl_git_pass(git_oid_fromstr(&two, "00112233445566778899aabbccddeeff00112233", GIT_OID_SHA1)); +#else + cl_git_pass(git_odb_open(&odb, "testrepo.git/objects")); + cl_git_pass(git_oid_fromstr(&one, "1385f264afb75a56a5bec74243be9b367ba4ca08")); + cl_git_pass(git_oid_fromstr(&two, "00112233445566778899aabbccddeeff00112233")); +#endif + + cl_assert(git_odb_exists(odb, &one)); + cl_assert(!git_odb_exists(odb, &two)); + + git_odb_free(odb); +} diff --git a/tests/libgit2/odb/pack_data_256.h b/tests/libgit2/odb/pack_data_256.h new file mode 100644 index 000000000..b63188227 --- /dev/null +++ b/tests/libgit2/odb/pack_data_256.h @@ -0,0 +1,154 @@ +#ifdef GIT_EXPERIMENTAL_SHA256 + +static const char *packed_objects_256[] = { + "99f3b405443221141eb0fd1e0cca5d355f893983749b7fb455769fba434e7945", + "d0fc7f52dc42358506e7f3f3be72f5271994abb104b9397ab3e19bb42361504d", + "86e228d9904af64586e9a8378005ba654681ff5be3c43ca930bf6b1f28d4395f", + "652412419a24ba62a1d897f40aeb80eecbf873797b04a1bbb8d71918653ef65b", + "ad90f638cb67720b20b904478471504acebacc7bb36e5dcad3e882acec496fed", + "4d46d9719e425ef2dfb5bfba098d0b62e21b2b92d0731892eef70db0870e3744", + "80ec1e36b983e68664e8357c538cd35b30638bb0cb99626f906d145e2d2e2558", + "e8bbf40ee280bc43b33c04df2250903b75e92f2497e91759cf1cad753c23be6c", + "8864b5746d7c5780083bb98449a3f5bf78d8281e8c5e3fd12a8ccd9103eb3a1f", + "083c2b8b445640d171e7aa667b0b32007006f786711032ebb82931cca69cc15b", + "5c8bea399f78d3d6a037a41cee2e763d00024180b66f2ec738d443b6a3dd7081", + "281c36286eab5e534f1c2121a4cf2cd48a32b3773a3e78df500bed3f3c9747f3", + "c9dc53358a0d83bee1caae40ee81d752abf4962a9f206702e24a447b766b5bd7", + "fafc05a1d0b7614ba32f428eb52f3439ffbfed9a817e5ae069364cfc3fa3e4d4", + "25a4efebb38c55b8f2309ce5e3116b2b9287239952cc2fa174074e05c6e5875a", + "c223f1b579bad18635efdeffa7a8ff40567d03fa427e08bb90d9878f958d8021", + "8a0042d434a2f8a2e8d47caa4eb454f388752fb3fe71150c1cea12e807cfdf1c", + "d79e913b4137117b7f8fc2a8d184373f657d6f71bbeaca0fe83b7757ce486108", + "375f69d3d41e36d6904bfa86221690ec49de2a030664a362abaf86c426f9f7e0", + "22b6705b86e4aa9120eff203af24709d483698d9f78695e86e82de121784b570", + "4516b0e63349c81abc6584cb11ce84ab8ba38b105f9de39d0d0a1455dba2478d", + "c2b535bfc3501f0b4e179d5d6f0e2cea613940fa3813be5923db7e71e190849f", + "aa793f0e9d9d746eba8a7a60cb4981f7e24ce9691910350d7df9b9e94c7567b9", + "890bb959ac8c20db603bf083bc82f55f9f42b6dca6581d941d0b361188abae3b", + "bfc0ee6fe04854c11011539f38cc6b9b73e0c445bac2008de2fb877123efc2e3", + "5ba7253f47d390ee2c7c7afe8fd9a963a7a2674bbdadeb9a927665c9246306c4", + "79bc735b91f8dfa9379d1d6c21e2d519ac1bf0d04d48534864c9ff571df5297d", + "f362826c827aa3bcbeb3ff8b71bba08d7440b89ab53fe95d61b8922d01f46e28", + "4a1b9c078e7bb20759a2d75e3a4b96827c851446c0261750b96aa5f286efe378", + "2e2aa456dbbb8889923eb6713672427854020298a764967c50235a9a76d7ce4b", + "97b0e3661fa0caa6200c50381233f8320b907540ceb9d17ac94fedc66fd093c2", + "ade7d297ede7bb58008da582de1253f0a55cb76e82d1cd376f82ccf97f70bced", + "3315093132a8f28bd202c0a9562d04eebea4943dcd1e1c754341b0389722042f", + "6fae137ba81d0d81c2a85759b99322e7ea8103bd7c8b85be3163b7e91e18c125", + "f8b45f792840019909fd35f9dcb98082b3bc39373268d467e1b00f1da5ac71e5", + "d2ab425d6092770366bc3dff5276e3a869221bc7b6d22e99c089d556e7eb8331", + "4dd37b9df07bcc7b45ce72a44e3f5fcaf5f0a9a5f3148963714eac4c99a60388", + "8c53c0f9f0972a1c77e40549170b9ae51d365c200ffc4cb220628c5bce3dd0b2", + "11d0463a82345c2512bd704dd00211aefb7d5b8590ca92809122fd09486a9f06", + "1ab4fa663d22416f45cb1a007d767a58d0abf5255bf86f888393dae637b37c3b", + "345d2fbf1d306c7ea46a05f497793308357e9e17ab0e866446d2b9894378ddce", + "304352ddad641770fcc94ee4d9f957cde7aaf4c107dbf8b5ba14d543640bf7dd", + "cfdd565f4cbc315760c287d57714852e1a4894eef9c715332fd556f2e114a9f1", + "d6d2e87e6de8690efd26b8c5b58de28dcb3c9bd2b7659eccf34468d71a7a4478", + "aa61d4adf622265ec814c1a97198d2bcd3f58fb08989cb9beda32a4d0aab6697", + "40799f33b8cd9ca41f36a2f89d8ac8550537ad01dfb21fbc76f01eeb62f512d4", + "faa7ca59426e17f6b34fa407d06cd634faaabeb4abe26df12296e05a17c98eef", + "1f6ea2cab887a2ff4bb1557a36dd6bac9931ef1f36794ddd22b4b7b7276051fb", + "b38a7a2ee69d55f021efa91caf59e23bccdaf6b8a9c3f83acd978aa177587537", + "f66691f32eb9b23a029b43251bfa994d16481fe97903057e121b76e4e78f6ff4", + "afe1fad6f6b22eea530ff7b373d6b9b787b39792f720e6fcd0692ba6ef99e02f", + "b71ee6c8837efa5b3ba3361f88c321d391ac05f41d5b2506cad39319e80716e4", + "e207a266e228414023223530eb77c64b10f2f5124f3354deb45aff04c1db98b9", + "696503760a18787240ba52ad1abec3be6517bb802238e9469b3a8999cbd6432c", + "c30d06fd49797e3135652d654db0de122dd83f8400df1c7a0e95ca3720defb0d", + "8a9b600a21987e6ffddbad745f38c115797eacef9117043bd9d2da4835ee3cc4", + "d509fa76ff5944e25f48c2476736b6239a53f0463cba6ebc488464d087951951", + "3e00d8cae2726dc33879adf876b30c306f50e7a85b15c8add4a27f84d88616d7", + "ce55f9f5ab1d799a9ffaa839539af196d13f35677b3d0761b0fe034e764f8d07", + "84005e38a65f4115d5c94790010dc57e1a3297f4aa89744f5927f208af758bd0", + "75b0ed5f4a2d5c810f34d867dbca51db6a596d4739abfaf24fcc0f05d99097a8", + "3eab74a6894d790767f3d92615a6887dcccaffa9e48fdd2ce482b5f17efcf9b9", + "8e61988c998c96a131cfe72225fce43e555bec4e590fa8c239373172a9d485ce", + "5f45a18f90f2934e7c7985d05b2b5b3584886fd057c9202f26f562d6c3080038", + "7609c608c1097270356a6fe336a8756ff124d4a9c2e941bba26a6e8c3becdeb1", + "81ba4e67aa59ccb078e3dc9ff3075f50084ec1696bd867e8e4284fcfc34fe3cf", + "3b1b991ae70d1f5388ad16b63d2285e99ada7a618c6f5d01e50a6d4b33c4767d", + "ac49410f64fad10760838866a40107573e42c86908c83ece433d64b7a8b57f7f", + "72c472319cf7d5d59bf9fea9e90b9785d7ab39340003fbc68619c11a9e583c2f", + "3a0cd33a47fcd0c7b8f8c1d407aaa53f648e25f2ffe2533a7e9c09c3d1b9da75", + "bf409f1aa76256282ebf1a7cc6c9f4220be9ffc47b2cc42248fcc5cbb67bce1f", + "13c8c9dae9fa63b1ec48b8abb12312fc8df61b9414678f504fa68164a48eef28", + "078baf54914fab56842798c90fec863f15f67a22041e8aa54a88c43f059da050", + "41c166c241a4e878f444932a193501e12ab38ba0634747291df70e619dccee1c", + "9db520a5a88c7d75b86a4faa1ce9010edf38af922f400c69a4a93aef69e25c4c", + "edf6e0dbfaf8a7ad89b05b5768981eeedd7a2bda4b1d0fae07aa2a9d49bb39df", + "ec1866b39026366e69ab8e167c15312c27f5eda4c0afdf9367ac3d76f56bf8e7", + "695bdb545f636d454b4825effd29db96c46d81772dda6c104f97dffe2ec509f1", + "07c31b4be5f3ec8f82c7ad6c91cbdf07ae876bb73041903d64fe8bac64bbcb6e", + "06665948a581e547ac1dc883b35bab54682fc311f7a87d5563a76501ecba55fc", + "fa6a2b7e588e57115d2772c0d5250d886757404fc510a5956be8de4926e94c01", + "28aec9a4450d9de98db98a021f97026bf12f1328f66e53319669eb5adce5ed3e", + "290d84a2cf108c074d3764ca8dc56e1215a5a7482837f098dff7a55e23d89d5f", + "ed10f9520d5f0d6bbd9c467ed83a239df0cba94ae9031602e02f6ad6256c459e", + "ad05c66a177f844f8239a1d186a1f803a4daa6286c959538838e222bc6337dc9", + "88fecc715077807bd7ee9e6a1dff65fde000379e0bf2a15cc2404469cef4c82b", + "bcc4fa242e55c5e08f64900407dca1cf2451806830905be616f339bf7a5580aa", + "4a4ebb837e3c9883f35d0ecdc26d4bc76a0f665568b08f3e967096f2fd3fa537", + "9abb7801e72353060a1490ffa3331674d6882558e7d6458de397b4b00d31ff8c", + "466cdfec4c74f3ed4fe53165e468a52df5dff9c6533ec433cdf235a73e099d32", + "8a1e1a6cc00519c4df8ce404c987751446fa299662308622cb63576fb52996d7", + "e5ea38108d603a6ed8dbb0b8455abe6d971f2d60920207e67ba646d267ece305", + "97e00ba4c8028ea91e7131c8c7596227cd03d3d2d14ed2d179fe0f305ebbca39", + "807faa3586b7f1aff2797a7c39c135b0196647c9ae7ee8843322accc960b2f22", + "b9134c331629e9cb29d1bbc03904d911a942b451e087543fc16deb0116391297", + "23cb97c200205dc84109c248be5bd719c23bdab52b52c51ec92fef9a48790833", + "b6e8427e3afe1cf0095d0f5aeca0642c4fb12d4e529f62e8264b6c4db72f04b4", + "92128dfb792caea934f5218807ec993867b0c8487a3de69ebac33e067f64d38a", + "a13ecbc514b571721a9a1c92af7f89d473a5fe13228904f8d17368e71f273ea1", + "3f5dca26a2f512d6681ce1957b8afba5e031bf63d52fd52d8f57093bf92391a4", + "1aa24b7ebd910f39a676f2ccab8e9a79f14842c20b55ed18e3dc297bdbaca279", + "1e0ce38d00e8f3e613febc0f8b275e0fd7fbef8af293fd62698be46dfbbc937d", + "dd9b1d5ca653752cef167e034324198971ab6f2f38f3db9db571cb2985759f00", + "efc4b8fd4b0b2586fce256b107ee2a052d11d26f99d85ce0478c3d49d1b2186b", + "da38f65b32fb03ce332e0c4238edae0a733e4cd793d849522bb4e0bdd0af608c", + "bf66badfda7b5d2157db65c5310cfdc4e904d7d5da57ac5abe17542de612f856", + "2c0f52f9ae1f34f280dfc1c755cbfaf2b9968fd3bab1f1eb16d3ac0fafd71940", + "165ec90aa4190bbe12ee415b294fd6d204c64afcf1ca64dd815782872b24ea26", + "cc3d272d457c7e26c5d611923841511a1766bcd58e5be66433698627e6fb3f9d", + "d970d1a6296d149bfb8283b8b4a9a6f7e9ee320c5d46a5ef216e10400df2d281", + "bdc530e0b98dd736cd812408eeed9aa0d393bbd0630b355eb7601e61f0dbc7c4", + "94db24aca3f8e07f481744f62633730feb4fc47605280381a08be510ae971ffe", + "151c7527acc5b731199a03a932ae374331e16e5ae29256e98cb652f37669889b", + "ac88849a26c126b03fc6fcb17cb23ec563e87a5f63b7afe800ad0f436128ce98", + "26a2dac21f8f0939566570e48f7f4fcf89239c2746ef8d3dbf31d179c691808f", + "619f24a7f37f8ca922c83b3a1b9a384eb6a444ff3a2a52c712f3c60dde6f24fb", + "5329dd2fd8557be5ad06b57882cf42e23d767cdc8a4b25e464fdb00890649e07", + "fff5cbc10ffea865d69aba64082ae17479c522e8e0305e678469749282bf0a18", + "d0c992aae9cde855b17ac826234a73255ecb09534cdcfa633d90640f6a4324d9", + "6129f1672465ee7b9e2edef53fbf3846ab5d06e8e6a1d7fb51e31666a8b411f8", + "0a8c0add81b065b97451f7b47a9935f0e240251c5f90a89ced885cb7d4efc2ba", + "471fa4fc2da467dd94e57babb1912bbdb5e40b96c8129d46fc709c0bfc009bca", + "23cea2b49eed4993c5b92a9d5f0b82efe4fae3837ea707d921de645d04479015", + "c85e35eec23dea4089aee7a2dc7f6d937ad7e13c66bdbd7eef37bd6336418609", + "a0f3dac8fa0e22dcf356aecbbdf79440715687c1053bc59b83354f276d688ceb", + "1cfb8ae71e9e576d1b16b7bd1a62156d0641c6e51f5d76877be6de4f26410623" +}; + +static const char *loose_objects_256[] = { + "96c18f0297e38d01f4b2dacddea4259aea6b2961eb0822bd2c0c3f6029030045", + "aea29dc305d40e362df25c3fdeed5502fd56b182af01b7740d297a24459333c5", + "73b4f3c4f3182e6c8dd2c98aeb2c7811556538e7673e4b325307c71685fbf5b6", + "901505c3355518bee35475c5d3f23bac1dded688b2bd314cc32b7f157e100724", + "4bc142808884e472ee6cc331b132e66ef18f564d41efb055804ec1dd28efb3f5", + "7e4633ae1b0e83503dbea4417f9d5ccaf22b877c5a4522b6d1d2b16090ee2f6f", + "473a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813", + "7030f925768d9beb65654ab8f436e3ca0a82b25eddefd237bf5a26a0441c2aa7", + "cb282e7c15fd8aeb2265cd621f5a228cb33dc84192980ca426cf9ab2a48cb9f0", + "33e415b835a670bb5c3c760efa0433ac0cbd2d44679f68f2df3a9ae7014cf2a8", + "8155958bbda08eed88c8ac908dc44452ed38911cffa54ccc06076f30a1ffb1bf", + "1b4b74772bd83ff28bf44cda9be93f4afc2279623bb5b36c9194a660b7623c24", + "f31459efb9367c5a19c9dd24c75107423d5773066922ea5e55eaeb6490979562", + "6d5fd291bb0f67444e99ab492f1bf1fcdf5dca09dab24cf331e05111b4cfc1a3", + "b83624f6ac0995273c0034a7ab8c68929bdc91b69ad54ef94979b93eba3f6022", + "61489e9e831f1d9001084d39b79f964c293db8620d679ea3596673c8a326446e", + "abee32b3339d1566d75613ea61f40c14bdfc5b101b60fde4f44b58dd06667640", + "a4813ef6708e6011e8187224297e83e4a285f58bf5eabb1db270351388603c95", + "43e084a4599ca42c476919917e3db8fde0045ee66305fd5e634b0c793c536a1b" +}; + +#endif diff --git a/tests/libgit2/odb/pack_data_one256.h b/tests/libgit2/odb/pack_data_one256.h new file mode 100644 index 000000000..98a874798 --- /dev/null +++ b/tests/libgit2/odb/pack_data_one256.h @@ -0,0 +1,21 @@ +/* Just a few to make sure it's working, the rest is tested already */ +#ifdef GIT_EXPERIMENTAL_SHA256 +static const char *packed_objects_one256[] = { + "ea926306b1bab6d3f25f45609907eb6dff91a1460b25e63bf4a0494c70e7a269", + "d048ba2ef4fafa502a44cbc1a50cd58359b9bc243b84a08f541a08ca5f621137", + "a66bda0109d2b3c9bc87970da81bd91076b5f871febbc860f09ae997668b6800", + "3609a41c0506fe19d01fb8b4729923362675f191fe5f63fab3111ef804c48fdf", + "22b6705b86e4aa9120eff203af24709d483698d9f78695e86e82de121784b570", + "6f11d93bfb269ee8c7a506178f60c430abfac5d424acfd9c0b0b27b98e6ab49b", + "0aefd477d9e5b3f8d708a3cf6d78be6b670dfa2e2ec41244634f3b8f115d8e04", + "580474d948cd2ebd2e5ce7a5b81b872d87ba4639c1ac4c0fa7a11a8eddf9827c", + "0636b4292bfdd7274a977cb6f8b2ded8f315ea1bcd8dbedfca37964c2ed3d085", + "19fb1c78b11f0f8bda658d6fa6cc63c0b573c0f6760ee5a9c2df6ce2cde00c5c", + "7f2f7afccb317bb3fdd28555f126846dc4eebe5d9ae7b8d8a1456e8ff85422ce", + "4066249c68b0d3c8b39ebe02c9188935900465acad02a49269710f56720fa58e", + "a560d1fa1edf114f57b402e16d662c17b1e3b7e8601ff7dcea6615ba7f1e48ef", + "58923faa87c7d559d308a114ec2b164e5d6046c889420ed1def6eef2d55106a2", + "753ddabab8ae9c1e733cda15e8e3c83dd43f5a2d939ae32cc3b30b0be1e91f96", + "46333d32b3801cf11d9f80b557245c9e32b0e05deca61dae968914fde159f0e5" +}; +#endif diff --git a/tests/libgit2/odb/packed256.c b/tests/libgit2/odb/packed256.c new file mode 100644 index 000000000..65220fd4c --- /dev/null +++ b/tests/libgit2/odb/packed256.c @@ -0,0 +1,98 @@ +#include "clar_libgit2.h" +#include "odb.h" +#include "pack_data_256.h" + +#ifdef GIT_EXPERIMENTAL_SHA256 +static git_odb *_odb; +#endif + +void test_odb_packed256__initialize(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + git_odb_options opts = GIT_ODB_OPTIONS_INIT; + + opts.oid_type = GIT_OID_SHA256; + + cl_git_pass(git_odb__open( + &_odb, + cl_fixture("testrepo_256.git/objects"), + &opts)); +#endif +} + +void test_odb_packed256__cleanup(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + git_odb_free(_odb); + _odb = NULL; +#endif +} + +void test_odb_packed256__mass_read(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(packed_objects_256); ++i) { + git_oid id; + git_odb_object *obj; + + cl_git_pass(git_oid__fromstr(&id, packed_objects_256[i], GIT_OID_SHA256)); + cl_assert(git_odb_exists(_odb, &id) == 1); + cl_git_pass(git_odb_read(&obj, _odb, &id)); + + git_odb_object_free(obj); + } +#endif +} + +void test_odb_packed256__read_header_0(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(packed_objects_256); ++i) { + git_oid id; + git_odb_object *obj; + size_t len; + git_object_t type; + + cl_git_pass(git_oid__fromstr(&id, packed_objects_256[i], GIT_OID_SHA256)); + + cl_git_pass(git_odb_read(&obj, _odb, &id)); + cl_git_pass(git_odb_read_header(&len, &type, _odb, &id)); + + cl_assert(obj->cached.size == len); + cl_assert(obj->cached.type == type); + + git_odb_object_free(obj); + } +#endif +} + +void test_odb_packed256__read_header_1(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(loose_objects_256); ++i) { + git_oid id; + git_odb_object *obj; + size_t len; + git_object_t type; + + cl_git_pass(git_oid__fromstr(&id, loose_objects_256[i], GIT_OID_SHA256)); + + cl_assert(git_odb_exists(_odb, &id) == 1); + + cl_git_pass(git_odb_read(&obj, _odb, &id)); + cl_git_pass(git_odb_read_header(&len, &type, _odb, &id)); + + cl_assert(obj->cached.size == len); + cl_assert(obj->cached.type == type); + + git_odb_object_free(obj); + } +#endif +} + diff --git a/tests/libgit2/odb/packed_one.c b/tests/libgit2/odb/packedone.c index 7a1d3d913..8637001ff 100644 --- a/tests/libgit2/odb/packed_one.c +++ b/tests/libgit2/odb/packedone.c @@ -6,22 +6,29 @@ static git_odb *_odb; -void test_odb_packed_one__initialize(void) +void test_odb_packedone__initialize(void) { git_odb_backend *backend = NULL; cl_git_pass(git_odb__new(&_odb, NULL)); - cl_git_pass(git_odb_backend_one_pack(&backend, cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"))); +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_odb_backend_one_pack(&backend, + cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"), + NULL)); +#else + cl_git_pass(git_odb_backend_one_pack(&backend, + cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"))); +#endif cl_git_pass(git_odb_add_backend(_odb, backend, 1)); } -void test_odb_packed_one__cleanup(void) +void test_odb_packedone__cleanup(void) { git_odb_free(_odb); _odb = NULL; } -void test_odb_packed_one__mass_read(void) +void test_odb_packedone__mass_read(void) { unsigned int i; @@ -37,7 +44,7 @@ void test_odb_packed_one__mass_read(void) } } -void test_odb_packed_one__read_header_0(void) +void test_odb_packedone__read_header_0(void) { unsigned int i; diff --git a/tests/libgit2/odb/packedone256.c b/tests/libgit2/odb/packedone256.c new file mode 100644 index 000000000..fdeac4205 --- /dev/null +++ b/tests/libgit2/odb/packedone256.c @@ -0,0 +1,78 @@ +#include "clar_libgit2.h" +#include "git2/odb_backend.h" + +#include "pack_data_one256.h" +#include "pack.h" + +#ifdef GIT_EXPERIMENTAL_SHA256 +static git_odb *_odb; +#endif + +void test_odb_packedone256__initialize(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + git_odb_backend *backend = NULL; + git_odb_options odb_opts = GIT_ODB_OPTIONS_INIT; + git_odb_backend_pack_options backend_opts = GIT_ODB_BACKEND_PACK_OPTIONS_INIT; + + odb_opts.oid_type = GIT_OID_SHA256; + backend_opts.oid_type = GIT_OID_SHA256; + + cl_git_pass(git_odb__new(&_odb, &odb_opts)); + cl_git_pass(git_odb_backend_one_pack( + &backend, + cl_fixture("testrepo_256.git/objects/pack/pack-e2f07f30db7e480ea84a0e64ee791b9b270067124b2609019b74f33f256f33fa.idx"), + &backend_opts)); + cl_git_pass(git_odb_add_backend(_odb, backend, 1)); +#endif +} + +void test_odb_packedone256__cleanup(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + git_odb_free(_odb); + _odb = NULL; +#endif +} + +void test_odb_packedone256__mass_read(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(packed_objects_one256); ++i) { + git_oid id; + git_odb_object *obj; + + cl_git_pass(git_oid__fromstr(&id, packed_objects_one256[i], GIT_OID_SHA256)); + cl_assert(git_odb_exists(_odb, &id) == 1); + cl_git_pass(git_odb_read(&obj, _odb, &id)); + + git_odb_object_free(obj); + } +#endif +} + +void test_odb_packedone256__read_header_0(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(packed_objects_one256); ++i) { + git_oid id; + git_odb_object *obj; + size_t len; + git_object_t type; + + cl_git_pass(git_oid__fromstr(&id, packed_objects_one256[i], GIT_OID_SHA256)); + + cl_git_pass(git_odb_read(&obj, _odb, &id)); + cl_git_pass(git_odb_read_header(&len, &type, _odb, &id)); + + cl_assert(obj->cached.size == len); + cl_assert(obj->cached.type == type); + + git_odb_object_free(obj); + } +#endif +} diff --git a/tests/libgit2/odb/sorting.c b/tests/libgit2/odb/sorting.c index 1010872f4..ec4e3696b 100644 --- a/tests/libgit2/odb/sorting.c +++ b/tests/libgit2/odb/sorting.c @@ -82,7 +82,11 @@ void test_odb_sorting__override_default_backend_priority(void) cl_git_pass(git_libgit2_opts(GIT_OPT_SET_ODB_LOOSE_PRIORITY, 5)); cl_git_pass(git_libgit2_opts(GIT_OPT_SET_ODB_PACKED_PRIORITY, 3)); - git_odb_backend_pack(&packed, "./testrepo.git/objects"); + git_odb_backend_pack(&packed, "./testrepo.git/objects" +#ifdef GIT_EXPERIMENTAL_SHA256 + , NULL +#endif + ); git_odb__backend_loose(&loose, "./testrepo.git/objects", NULL); cl_git_pass(git_odb__open(&new_odb, cl_fixture("testrepo.git/objects"), NULL)); diff --git a/tests/libgit2/online/clone.c b/tests/libgit2/online/clone.c index 6a087b1af..1a4cdb520 100644 --- a/tests/libgit2/online/clone.c +++ b/tests/libgit2/online/clone.c @@ -21,6 +21,7 @@ static git_clone_options g_options; static char *_remote_url = NULL; static char *_remote_user = NULL; static char *_remote_pass = NULL; +static char *_remote_branch = NULL; static char *_remote_sslnoverify = NULL; static char *_remote_ssh_pubkey = NULL; static char *_remote_ssh_privkey = NULL; @@ -35,6 +36,11 @@ static char *_remote_expectcontinue = NULL; static char *_remote_redirect_initial = NULL; static char *_remote_redirect_subsequent = NULL; +static char *_github_ssh_pubkey = NULL; +static char *_github_ssh_privkey = NULL; +static char *_github_ssh_passphrase = NULL; +static char *_github_ssh_remotehostkey = NULL; + static int _orig_proxies_need_reset = 0; static char *_orig_http_proxy = NULL; static char *_orig_https_proxy = NULL; @@ -69,6 +75,7 @@ void test_online_clone__initialize(void) _remote_url = cl_getenv("GITTEST_REMOTE_URL"); _remote_user = cl_getenv("GITTEST_REMOTE_USER"); _remote_pass = cl_getenv("GITTEST_REMOTE_PASS"); + _remote_branch = cl_getenv("GITTEST_REMOTE_BRANCH"); _remote_sslnoverify = cl_getenv("GITTEST_REMOTE_SSL_NOVERIFY"); _remote_ssh_pubkey = cl_getenv("GITTEST_REMOTE_SSH_PUBKEY"); _remote_ssh_privkey = cl_getenv("GITTEST_REMOTE_SSH_KEY"); @@ -83,6 +90,11 @@ void test_online_clone__initialize(void) _remote_redirect_initial = cl_getenv("GITTEST_REMOTE_REDIRECT_INITIAL"); _remote_redirect_subsequent = cl_getenv("GITTEST_REMOTE_REDIRECT_SUBSEQUENT"); + _github_ssh_pubkey = cl_getenv("GITTEST_GITHUB_SSH_PUBKEY"); + _github_ssh_privkey = cl_getenv("GITTEST_GITHUB_SSH_KEY"); + _github_ssh_passphrase = cl_getenv("GITTEST_GITHUB_SSH_PASSPHRASE"); + _github_ssh_remotehostkey = cl_getenv("GITTEST_GITHUB_SSH_REMOTE_HOSTKEY"); + if (_remote_expectcontinue) git_libgit2_opts(GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE, 1); @@ -102,6 +114,7 @@ void test_online_clone__cleanup(void) git__free(_remote_url); git__free(_remote_user); git__free(_remote_pass); + git__free(_remote_branch); git__free(_remote_sslnoverify); git__free(_remote_ssh_pubkey); git__free(_remote_ssh_privkey); @@ -116,6 +129,11 @@ void test_online_clone__cleanup(void) git__free(_remote_redirect_initial); git__free(_remote_redirect_subsequent); + git__free(_github_ssh_pubkey); + git__free(_github_ssh_privkey); + git__free(_github_ssh_passphrase); + git__free(_github_ssh_remotehostkey); + if (_orig_proxies_need_reset) { cl_setenv("HTTP_PROXY", _orig_http_proxy); cl_setenv("HTTPS_PROXY", _orig_https_proxy); @@ -309,6 +327,16 @@ void test_online_clone__custom_headers(void) cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options)); } +void test_online_clone__long_custom_header(void) +{ + /* Long custom header with 1500 characters */ + char *ok = "X-Custom: a0MsqH2bXV9lILn7zkAHqKpGrOVvkik7SfoyqfXbFTxccsymN5SG9hEB0RLD9koTXKWtaI1vI9jHf5ViwLHq6xvkveFX9GiqaIhe3TRu5KDZrOBgeufdBYsTTONALPlpni9XVq71bR6x3AlVEqHdXi9qiq0TRuNiujMy0ZKs8LQkQVSE8kxWZXqLsO2IJtAPw5aqsUEenK5ec12GOeOTOYlSChGllzvl2Ow4SKlVg3t8NHVWvc8HyPGmBQ79l3qUMU30P0hnUXaIrhIzGgleYWnwhGFLpryxsQfCdwkdBMuvtLH0DnkhLoAkCmnCZItEExtHBOCirEzztoFMX3lH4lM4wMqePCU8II0qloNvzPgt6cBThQJP66FYUDSCwsSb63bcTWdVx7TCa6mAplkP49PKi5pFSvFKKbs5se5MPcBVG03GiatKszIQkii0vp6OV5b54Aym4N8hQJHFMhIChKiQM91tB7PQu9vPJE6h2bzAnQsn34bBPFZHT7pBplqkASiHDjw69YV6k3M8ffTOTr2ibQnTKxh1NH3ZRx6u0KxRty9i4YLMniZUZAfFgqbSW2xXk49e8J9VNFm7j2bgHp3t813wUzqnQL4NEc0CQlF0e6pId5ADXikoH6S7aMfuYUYi1Kn1i9m7UGtaB0U7dVC65uH9vIWKnyAcmBt0mN1aikRnjz7oBKjD65SRZrKWXeCDJkpgWlXnD5JjekDCyB9m3yGkaxy1FflI1kaa4kcVbPRfs6XebHRDl9golPBUyazRG1V1iOi1mKki9ClUNO8wviNfKm5eMbWW6hU8wMXh388EotRA73TUdL4JIfNpkC4XBFLNFbFtltzO34kxXBKvhj8t0XVZOp4AWpHEL3pUtuyKhNWaWlDF6ZhjCeO8vT1akKoYaA7t6nFyqawq5nPoB0iXEHQ7YugfYfgjzpNGLgvPJ6aLg9YIKZBqfi7J9xWb356IJvTQFswi7qm6Mu7IVXarS9m84b5IfT6UCVq84u4VcdBlDswNPTw6SbBtzg9vrLLs3MoTCzJY6fHPqnKt6YthgQwOOB1ig7GTSDiX3W3SMeaz5jTASociHrUS3HrwVSgjrODnF86962cv4s3DGYjiX2cIuNfq9mZVJlNsylZjFYFV9LzOjNLlSHZVJrrGQJLjmyOCwOMkG9u2xKdSvfjxTJzqhjhTvQSQZWhKt44hA9EidUqPqjc3MhfnZ6aeAIP232gtRHoRc7FdjRSan4Q3PWy02YiRodvKAafonwCOtMcm4MASrXBiBE1tibHLSTtK4UrodFNVhymtBCRnJdVRSgrCQcr2B5Jzs4Iv6uJlJqwwyuq6In54zcmecgJZezta84B3eFoSGJhCbI6Zza0khulccglCcppciWDStAHFhncePsCQL4tup0Z8fS01RksRQ7X1xgskVvQAKELThDqbJB4FJZwrwPXOpCweAoSONntp7Ly0lAUabw75gK5sR387IxNVdISmfP"; + + g_options.fetch_opts.custom_headers.count = 1; + g_options.fetch_opts.custom_headers.strings = &ok; + cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options)); +} + static int cred_failure_cb( git_credential **cred, const char *url, @@ -541,6 +569,68 @@ static int check_ssh_auth_methods(git_credential **cred, const char *url, const return GIT_EUSER; } +static int succeed_certificate_check(git_cert *cert, int valid, const char *host, void *payload) +{ + GIT_UNUSED(cert); + GIT_UNUSED(valid); + GIT_UNUSED(payload); + + cl_assert_equal_s("github.com", host); + + return 0; +} + +static int fail_certificate_check(git_cert *cert, int valid, const char *host, void *payload) +{ + GIT_UNUSED(cert); + GIT_UNUSED(valid); + GIT_UNUSED(host); + GIT_UNUSED(payload); + + return GIT_ECERTIFICATE; +} + +static int github_credentials( + git_credential **cred, + const char *url, + const char *username_from_url, + unsigned int allowed_types, + void *data) +{ + GIT_UNUSED(url); + GIT_UNUSED(username_from_url); + GIT_UNUSED(data); + + if ((allowed_types & GIT_CREDENTIAL_USERNAME) != 0) { + return git_credential_username_new(cred, "git"); + } + + cl_assert((allowed_types & GIT_CREDENTIAL_SSH_KEY) != 0); + + return git_credential_ssh_key_memory_new(cred, + "git", + _github_ssh_pubkey, + _github_ssh_privkey, + _github_ssh_passphrase); +} + +void test_online_clone__ssh_github(void) +{ +#if !defined(GIT_SSH) || !defined(GIT_SSH_MEMORY_CREDENTIALS) + clar__skip(); +#endif + + if (!_github_ssh_pubkey || !_github_ssh_privkey) + clar__skip(); + + cl_fake_homedir(NULL); + + g_options.fetch_opts.callbacks.credentials = github_credentials; + g_options.fetch_opts.callbacks.certificate_check = succeed_certificate_check; + + cl_git_pass(git_clone(&g_repo, SSH_REPO_URL, "./foo", &g_options)); +} + void test_online_clone__ssh_auth_methods(void) { int with_user; @@ -550,7 +640,7 @@ void test_online_clone__ssh_auth_methods(void) #endif g_options.fetch_opts.callbacks.credentials = check_ssh_auth_methods; g_options.fetch_opts.callbacks.payload = &with_user; - g_options.fetch_opts.callbacks.certificate_check = NULL; + g_options.fetch_opts.callbacks.certificate_check = succeed_certificate_check; with_user = 0; cl_git_fail_with(GIT_EUSER, @@ -561,6 +651,69 @@ void test_online_clone__ssh_auth_methods(void) git_clone(&g_repo, "ssh://git@github.com/libgit2/TestGitRepository", "./foo", &g_options)); } +/* + * Ensure that the certificate check callback is still called, and + * can accept a host key that is not in the known hosts file. + */ +void test_online_clone__ssh_certcheck_accepts_unknown(void) +{ +#if !defined(GIT_SSH) || !defined(GIT_SSH_MEMORY_CREDENTIALS) + clar__skip(); +#endif + + if (!_github_ssh_pubkey || !_github_ssh_privkey) + clar__skip(); + + cl_fake_homedir(NULL); + + g_options.fetch_opts.callbacks.credentials = github_credentials; + + /* Ensure we fail without the certificate check */ + cl_git_fail_with(GIT_ECERTIFICATE, + git_clone(&g_repo, SSH_REPO_URL, "./foo", NULL)); + + /* Set the callback to accept the certificate */ + g_options.fetch_opts.callbacks.certificate_check = succeed_certificate_check; + + cl_git_pass(git_clone(&g_repo, SSH_REPO_URL, "./foo", &g_options)); +} + +/* + * Ensure that the known hosts file is read and the certificate check + * callback is still called after that. + */ +void test_online_clone__ssh_certcheck_override_knownhosts(void) +{ + git_str knownhostsfile = GIT_STR_INIT; + +#if !defined(GIT_SSH) || !defined(GIT_SSH_MEMORY_CREDENTIALS) + clar__skip(); +#endif + + if (!_github_ssh_pubkey || !_github_ssh_privkey || !_github_ssh_remotehostkey) + clar__skip(); + + g_options.fetch_opts.callbacks.credentials = github_credentials; + + cl_fake_homedir(&knownhostsfile); + cl_git_pass(git_str_joinpath(&knownhostsfile, knownhostsfile.ptr, ".ssh")); + cl_git_pass(p_mkdir(knownhostsfile.ptr, 0777)); + + cl_git_pass(git_str_joinpath(&knownhostsfile, knownhostsfile.ptr, "known_hosts")); + cl_git_rewritefile(knownhostsfile.ptr, _github_ssh_remotehostkey); + + /* Ensure we succeed without the certificate check */ + cl_git_pass(git_clone(&g_repo, SSH_REPO_URL, "./foo", &g_options)); + git_repository_free(g_repo); + g_repo = NULL; + + /* Set the callback to reject the certificate */ + g_options.fetch_opts.callbacks.certificate_check = fail_certificate_check; + cl_git_fail_with(GIT_ECERTIFICATE, git_clone(&g_repo, SSH_REPO_URL, "./bar", &g_options)); + + git_str_dispose(&knownhostsfile); +} + static int custom_remote_ssh_with_paths( git_remote **out, git_repository *repo, @@ -733,16 +886,6 @@ void test_online_clone__ssh_memory_auth(void) cl_git_pass(git_clone(&g_repo, _remote_url, "./foo", &g_options)); } -static int fail_certificate_check(git_cert *cert, int valid, const char *host, void *payload) -{ - GIT_UNUSED(cert); - GIT_UNUSED(valid); - GIT_UNUSED(host); - GIT_UNUSED(payload); - - return GIT_ECERTIFICATE; -} - void test_online_clone__certificate_invalid(void) { g_options.fetch_opts.callbacks.certificate_check = fail_certificate_check; @@ -756,17 +899,6 @@ void test_online_clone__certificate_invalid(void) #endif } -static int succeed_certificate_check(git_cert *cert, int valid, const char *host, void *payload) -{ - GIT_UNUSED(cert); - GIT_UNUSED(valid); - GIT_UNUSED(payload); - - cl_assert_equal_s("github.com", host); - - return 0; -} - void test_online_clone__certificate_valid(void) { g_options.fetch_opts.callbacks.certificate_check = succeed_certificate_check; @@ -1006,3 +1138,61 @@ void test_online_clone__redirect_initial_fails_for_subsequent(void) cl_git_fail(git_clone(&g_repo, _remote_redirect_subsequent, "./fail", &options)); } + +void test_online_clone__namespace_bare(void) +{ + git_clone_options options = GIT_CLONE_OPTIONS_INIT; + git_reference *head; + + if (!_remote_url) + cl_skip(); + + options.bare = true; + + cl_git_pass(git_clone(&g_repo, _remote_url, "./namespaced.git", &options)); + + cl_git_pass(git_reference_lookup(&head, g_repo, GIT_HEAD_FILE)); + cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(head)); + cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head)); + + git_reference_free(head); +} + +void test_online_clone__namespace_with_specified_branch(void) +{ + git_clone_options options = GIT_CLONE_OPTIONS_INIT; + git_reference *head; + + if (!_remote_url || !_remote_branch) + cl_skip(); + + options.checkout_branch = _remote_branch; + + cl_git_pass(git_clone(&g_repo, _remote_url, "./namespaced", &options)); + + cl_git_pass(git_reference_lookup(&head, g_repo, GIT_HEAD_FILE)); + cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(head)); + cl_assert_equal_strn("refs/heads/", git_reference_symbolic_target(head), 11); + cl_assert_equal_s(_remote_branch, git_reference_symbolic_target(head) + 11); + + git_reference_free(head); +} + +void test_online_clone__sha256(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + git_clone_options options = GIT_CLONE_OPTIONS_INIT; + git_reference *head; + + if (!_remote_url) + cl_skip(); + + cl_git_pass(git_clone(&g_repo, _remote_url, "./sha256", &options)); + cl_git_pass(git_reference_lookup(&head, g_repo, GIT_HEAD_FILE)); + cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(head)); + + git_reference_free(head); +#endif +} diff --git a/tests/libgit2/online/push.c b/tests/libgit2/online/push.c index d9208d28a..204572cf5 100644 --- a/tests/libgit2/online/push.c +++ b/tests/libgit2/online/push.c @@ -841,13 +841,28 @@ void test_online_push__bad_refspecs(void) void test_online_push__expressions(void) { - /* TODO: Expressions in refspecs doesn't actually work yet */ - const char *specs_left_expr[] = { "refs/heads/b2~1:refs/heads/b2" }; + const char *specs_left_expr[] = { + "refs/heads/b3~1:refs/heads/b2", + "b4:refs/heads/b4", + "fa38b91f199934685819bea316186d8b008c52a2:refs/heads/b5", + "951bbbb:refs/heads/b6" + }; + push_status exp_stats[] = { + { "refs/heads/b2", 1 }, + { "refs/heads/b4", 1 }, + { "refs/heads/b5", 1 }, + { "refs/heads/b6", 1 } + }; + expected_ref exp_refs[] = { + { "refs/heads/b2", &_oid_b2 }, + { "refs/heads/b4", &_oid_b4 }, + { "refs/heads/b5", &_oid_b5 }, + { "refs/heads/b6", &_oid_b6 } + }; - /* TODO: Find a more precise way of checking errors than a exit code of -1. */ do_push(specs_left_expr, ARRAY_SIZE(specs_left_expr), - NULL, 0, - NULL, 0, -1, 0, 0); + exp_stats, ARRAY_SIZE(exp_stats), + exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1); } void test_online_push__notes(void) diff --git a/tests/libgit2/pack/indexer.c b/tests/libgit2/pack/indexer.c index 2ac287255..9722decaf 100644 --- a/tests/libgit2/pack/indexer.c +++ b/tests/libgit2/pack/indexer.c @@ -100,7 +100,12 @@ void test_pack_indexer__out_of_order(void) git_indexer *idx = 0; git_indexer_progress stats = { 0 }; +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); +#else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); +#endif + cl_git_pass(git_indexer_append( idx, out_of_order_pack, out_of_order_pack_len, &stats)); cl_git_pass(git_indexer_commit(idx, &stats)); @@ -117,7 +122,12 @@ void test_pack_indexer__missing_trailer(void) git_indexer *idx = 0; git_indexer_progress stats = { 0 }; +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); +#else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); +#endif + cl_git_pass(git_indexer_append( idx, missing_trailer_pack, missing_trailer_pack_len, &stats)); cl_git_fail(git_indexer_commit(idx, &stats)); @@ -133,7 +143,12 @@ void test_pack_indexer__leaky(void) git_indexer *idx = 0; git_indexer_progress stats = { 0 }; +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); +#else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); +#endif + cl_git_pass(git_indexer_append( idx, leaky_pack, leaky_pack_len, &stats)); cl_git_fail(git_indexer_commit(idx, &stats)); @@ -151,6 +166,7 @@ void test_pack_indexer__fix_thin(void) git_repository *repo; git_odb *odb; git_oid id, should_id; + git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT; cl_git_pass(git_repository_init(&repo, "thin.git", true)); cl_git_pass(git_repository_odb(&odb, repo)); @@ -160,7 +176,13 @@ void test_pack_indexer__fix_thin(void) git_oid__fromstr(&should_id, "e68fe8129b546b101aee9510c5328e7f21ca1d18", GIT_OID_SHA1); cl_assert_equal_oid(&should_id, &id); - cl_git_pass(git_indexer_new(&idx, ".", 0, odb, NULL)); +#ifdef GIT_EXPERIMENTAL_SHA256 + opts.odb = odb; + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, &opts)); +#else + cl_git_pass(git_indexer_new(&idx, ".", 0, odb, &opts)); +#endif + cl_git_pass(git_indexer_append(idx, thin_pack, thin_pack_len, &stats)); cl_git_pass(git_indexer_commit(idx, &stats)); @@ -192,7 +214,12 @@ void test_pack_indexer__fix_thin(void) cl_git_pass(p_stat(name, &st)); +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); +#else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); +#endif + read = p_read(fd, buffer, sizeof(buffer)); cl_assert(read != -1); p_close(fd); @@ -216,6 +243,7 @@ void test_pack_indexer__corrupt_length(void) git_repository *repo; git_odb *odb; git_oid id, should_id; + git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT; cl_git_pass(git_repository_init(&repo, "thin.git", true)); cl_git_pass(git_repository_odb(&odb, repo)); @@ -225,7 +253,13 @@ void test_pack_indexer__corrupt_length(void) git_oid__fromstr(&should_id, "e68fe8129b546b101aee9510c5328e7f21ca1d18", GIT_OID_SHA1); cl_assert_equal_oid(&should_id, &id); - cl_git_pass(git_indexer_new(&idx, ".", 0, odb, NULL)); +#ifdef GIT_EXPERIMENTAL_SHA256 + opts.odb = odb; + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, &opts)); +#else + cl_git_pass(git_indexer_new(&idx, ".", 0, odb, &opts)); +#endif + cl_git_pass(git_indexer_append( idx, corrupt_thin_pack, corrupt_thin_pack_len, &stats)); cl_git_fail(git_indexer_commit(idx, &stats)); @@ -246,7 +280,12 @@ void test_pack_indexer__incomplete_pack_fails_with_strict(void) opts.verify = 1; +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, &opts)); +#else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, &opts)); +#endif + cl_git_pass(git_indexer_append( idx, incomplete_pack, incomplete_pack_len, &stats)); cl_git_fail(git_indexer_commit(idx, &stats)); @@ -266,7 +305,12 @@ void test_pack_indexer__out_of_order_with_connectivity_checks(void) opts.verify = 1; +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, &opts)); +#else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, &opts)); +#endif + cl_git_pass(git_indexer_append( idx, out_of_order_pack, out_of_order_pack_len, &stats)); cl_git_pass(git_indexer_commit(idx, &stats)); @@ -309,7 +353,12 @@ void test_pack_indexer__no_tmp_files(void) git_str_dispose(&path); cl_assert(git_str_len(&first_tmp_file) == 0); +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); +#else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); +#endif + git_indexer_free(idx); cl_git_pass(git_str_sets(&path, clar_sandbox_path())); diff --git a/tests/libgit2/pack/packbuilder.c b/tests/libgit2/pack/packbuilder.c index 0889f46ed..ff3dc1f68 100644 --- a/tests/libgit2/pack/packbuilder.c +++ b/tests/libgit2/pack/packbuilder.c @@ -104,7 +104,12 @@ void test_pack_packbuilder__create_pack(void) seed_packbuilder(); +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&_indexer, ".", GIT_OID_SHA1, NULL)); +#else cl_git_pass(git_indexer_new(&_indexer, ".", 0, NULL, NULL)); +#endif + cl_git_pass(git_packbuilder_foreach(_packbuilder, feed_indexer, &stats)); cl_git_pass(git_indexer_commit(_indexer, &stats)); @@ -244,7 +249,13 @@ void test_pack_packbuilder__foreach(void) git_indexer *idx; seed_packbuilder(); + +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); +#else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); +#endif + cl_git_pass(git_packbuilder_foreach(_packbuilder, foreach_cb, idx)); cl_git_pass(git_indexer_commit(idx, &_stats)); git_indexer_free(idx); @@ -262,7 +273,13 @@ void test_pack_packbuilder__foreach_with_cancel(void) git_indexer *idx; seed_packbuilder(); + +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); +#else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); +#endif + cl_git_fail_with( git_packbuilder_foreach(_packbuilder, foreach_cancel_cb, idx), -1111); git_indexer_free(idx); diff --git a/tests/libgit2/refs/revparse.c b/tests/libgit2/refs/revparse.c index 02ffe005d..d2f464840 100644 --- a/tests/libgit2/refs/revparse.c +++ b/tests/libgit2/refs/revparse.c @@ -304,6 +304,9 @@ void test_refs_revparse__ordinal(void) test_object("@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); test_object("@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + test_object("HEAD@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + test_object("HEAD@{4}", "5b5b025afb0b4c913b4c338a42934a3863bf3644"); + test_object("master@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); test_object("master@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); test_object("heads/master@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); diff --git a/tests/libgit2/remote/httpproxy.c b/tests/libgit2/remote/httpproxy.c index f62a2545b..60fc67dec 100644 --- a/tests/libgit2/remote/httpproxy.c +++ b/tests/libgit2/remote/httpproxy.c @@ -6,7 +6,6 @@ static git_repository *repo; static git_net_url url = GIT_NET_URL_INIT; -static int orig_proxies_need_reset = 0; static char *orig_http_proxy = NULL; static char *orig_https_proxy = NULL; static char *orig_no_proxy = NULL; @@ -21,20 +20,25 @@ void test_remote_httpproxy__initialize(void) git_remote_free(remote); - orig_proxies_need_reset = 0; + /* Clear everything for a fresh start */ + orig_http_proxy = cl_getenv("HTTP_PROXY"); + orig_https_proxy = cl_getenv("HTTPS_PROXY"); + orig_no_proxy = cl_getenv("NO_PROXY"); + + cl_setenv("HTTP_PROXY", NULL); + cl_setenv("HTTPS_PROXY", NULL); + cl_setenv("NO_PROXY", NULL); } void test_remote_httpproxy__cleanup(void) { - if (orig_proxies_need_reset) { - cl_setenv("HTTP_PROXY", orig_http_proxy); - cl_setenv("HTTPS_PROXY", orig_https_proxy); - cl_setenv("NO_PROXY", orig_no_proxy); - - git__free(orig_http_proxy); - git__free(orig_https_proxy); - git__free(orig_no_proxy); - } + cl_setenv("HTTP_PROXY", orig_http_proxy); + cl_setenv("HTTPS_PROXY", orig_https_proxy); + cl_setenv("NO_PROXY", orig_no_proxy); + + git__free(orig_http_proxy); + git__free(orig_https_proxy); + git__free(orig_no_proxy); git_net_url_dispose(&url); cl_git_sandbox_cleanup(); @@ -132,7 +136,7 @@ static void assert_global_config_match(const char *config, const char *expected) void test_remote_httpproxy__config_overrides_detached_remote(void) { - cl_fake_home(); + cl_fake_globalconfig(NULL); assert_global_config_match(NULL, NULL); assert_global_config_match("http.proxy", "http://localhost:1/"); @@ -141,22 +145,10 @@ void test_remote_httpproxy__config_overrides_detached_remote(void) assert_global_config_match("http.https://github.com/libgit2.proxy", "http://localhost:4/"); assert_global_config_match("http.https://github.com/libgit2/.proxy", "http://localhost:5/"); assert_global_config_match("http.https://github.com/libgit2/libgit2.proxy", "http://localhost:6/"); - - cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES)); } void test_remote_httpproxy__env(void) { - orig_http_proxy = cl_getenv("HTTP_PROXY"); - orig_https_proxy = cl_getenv("HTTPS_PROXY"); - orig_no_proxy = cl_getenv("NO_PROXY"); - orig_proxies_need_reset = 1; - - /* Clear everything for a fresh start */ - cl_setenv("HTTP_PROXY", NULL); - cl_setenv("HTTPS_PROXY", NULL); - cl_setenv("NO_PROXY", NULL); - /* HTTP proxy is ignored for HTTPS */ cl_setenv("HTTP_PROXY", "http://localhost:9/"); assert_proxy_is(NULL); diff --git a/tests/libgit2/repo/extensions.c b/tests/libgit2/repo/extensions.c index e7772acd5..105cdae12 100644 --- a/tests/libgit2/repo/extensions.c +++ b/tests/libgit2/repo/extensions.c @@ -3,7 +3,7 @@ #include "sysdir.h" #include <ctype.h> -git_repository *repo; +static git_repository *repo; void test_repo_extensions__initialize(void) { diff --git a/tests/libgit2/repo/init.c b/tests/libgit2/repo/init.c index adcd9e025..d78ec063c 100644 --- a/tests/libgit2/repo/init.c +++ b/tests/libgit2/repo/init.c @@ -142,27 +142,46 @@ void test_repo_init__reinit_bare_repo(void) cl_git_pass(git_repository_init(&g_repo, "reinit.git", 1)); } -void test_repo_init__reinit_too_recent_bare_repo(void) +void test_repo_init__reinit_nondefault_version(void) { git_config *config; + cl_set_cleanup(&cleanup_repository, "reinit.git"); + /* Initialize the repository */ cl_git_pass(git_repository_init(&g_repo, "reinit.git", 1)); git_repository_config(&config, g_repo); + /* Set the config to a supported but not default version */ + cl_repo_set_string(g_repo, "core.repositoryformatversion", "1"); + git_config_free(config); + git_repository_free(g_repo); + g_repo = NULL; + + /* Try to reinitialize the repository */ + cl_git_pass(git_repository_init(&g_repo, "reinit.git", 1)); + cl_assert_equal_i(1, cl_repo_get_int(g_repo, "core.repositoryformatversion")); + + cl_fixture_cleanup("reinit.git"); +} + +void test_repo_init__reinit_unsupported_version(void) +{ + cl_set_cleanup(&cleanup_repository, "reinit.git"); + + /* Initialize the repository */ + cl_git_pass(git_repository_init(&g_repo, "reinit.git", 1)); + /* * Hack the config of the repository to make it look like it has - * been created by a recenter version of git/libgit2 + * been created by a too new and unsupported version of git/libgit2 */ - cl_git_pass(git_config_set_int32(config, "core.repositoryformatversion", 42)); - - git_config_free(config); + cl_repo_set_string(g_repo, "core.repositoryformatversion", "42"); git_repository_free(g_repo); g_repo = NULL; - /* Try to reinitialize the repository */ + /* Try and fail to reinitialize the repository */ cl_git_fail(git_repository_init(&g_repo, "reinit.git", 1)); - cl_fixture_cleanup("reinit.git"); } @@ -708,7 +727,7 @@ void test_repo_init__defaultbranch_config_empty(void) void test_repo_init__longpath(void) { #ifdef GIT_WIN32 - size_t padding = CONST_STRLEN("objects/pack/pack-.pack.lock") + GIT_OID_SHA1_HEXSIZE; + size_t padding = CONST_STRLEN("objects/pack/pack-.pack.lock") + GIT_OID_MAX_HEXSIZE; size_t max, i; git_str path = GIT_STR_INIT; git_repository *one = NULL, *two = NULL; diff --git a/tests/libgit2/repo/objectformat.c b/tests/libgit2/repo/objectformat.c new file mode 100644 index 000000000..d278e10c4 --- /dev/null +++ b/tests/libgit2/repo/objectformat.c @@ -0,0 +1,69 @@ +#include "clar_libgit2.h" +#include "futils.h" +#include "sysdir.h" +#include "repository.h" +#include <ctype.h> + +static git_repository *repo; +static git_config *config; + +void test_repo_objectformat__initialize(void) +{ + repo = cl_git_sandbox_init("empty_bare.git"); + + cl_git_pass(git_repository_config(&config, repo)); + cl_git_pass(git_config_set_int32(config, "core.repositoryformatversion", 1)); +} + +void test_repo_objectformat__cleanup(void) +{ + git_config_free(config); + cl_git_sandbox_cleanup(); +} + +void test_repo_objectformat__unspecified(void) +{ + git_repository *other; + + cl_git_pass(git_repository_open(&other, "empty_bare.git")); + cl_assert_equal_i(GIT_OID_SHA1, git_repository_oid_type(other)); + git_repository_free(other); +} + +void test_repo_objectformat__sha1(void) +{ + git_repository *other; + + cl_git_pass(git_config_set_string(config, "extensions.objectformat", "sha1")); + + cl_git_pass(git_repository_open(&other, "empty_bare.git")); + cl_assert_equal_i(GIT_OID_SHA1, git_repository_oid_type(other)); + git_repository_free(other); +} + +void test_repo_objectformat__sha256(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + git_repository *other; + + cl_git_pass(git_config_set_string(config, "extensions.objectformat", "sha256")); + + cl_git_pass(git_repository_open(&other, "empty_bare.git")); + cl_assert_equal_i(GIT_OID_SHA256, git_repository_oid_type(other)); + git_repository_free(other); +#endif +} + +void test_repo_objectformat__invalid(void) +{ + git_repository *other; + + cl_git_pass(git_config_set_string(config, "extensions.objectformat", "bogus")); + + cl_git_fail_with(GIT_EINVALID, git_repository_open(&other, "empty_bare.git")); + cl_assert_equal_s("unknown object format 'bogus'", git_error_last()->message); + git_repository_free(other); +} + diff --git a/tests/libgit2/repo/open.c b/tests/libgit2/repo/open.c index 634ba59d2..3d1a0620b 100644 --- a/tests/libgit2/repo/open.c +++ b/tests/libgit2/repo/open.c @@ -410,6 +410,7 @@ void test_repo_open__no_config(void) git_str_dispose(&path); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); + cl_assert(git_repository_oid_type(repo) == GIT_OID_SHA1); cl_git_pass(git_repository_config(&config, repo)); cl_git_pass(git_config_set_string(config, "test.set", "42")); @@ -433,11 +434,13 @@ void test_repo_open__force_bare(void) cl_git_pass(git_repository_open(&barerepo, "alternate")); cl_assert(!git_repository_is_bare(barerepo)); + cl_assert(git_repository_oid_type(barerepo) == GIT_OID_SHA1); git_repository_free(barerepo); cl_git_pass(git_repository_open_bare( &barerepo, "empty_standard_repo/.git")); cl_assert(git_repository_is_bare(barerepo)); + cl_assert(git_repository_oid_type(barerepo) == GIT_OID_SHA1); git_repository_free(barerepo); cl_git_fail(git_repository_open_bare(&barerepo, "alternate/.git")); @@ -487,7 +490,7 @@ void test_repo_open__validates_dir_ownership(void) /* When the system user owns the repo config, fail */ git_fs_path__set_owner(GIT_FS_PATH_OWNER_ADMINISTRATOR); - cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo")); #ifdef GIT_WIN32 /* When the user is an administrator, succeed on Windows. */ @@ -498,7 +501,7 @@ void test_repo_open__validates_dir_ownership(void) /* When an unknown user owns the repo config, fail */ git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); - cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo")); } void test_repo_open__validates_bare_repo_ownership(void) @@ -516,7 +519,7 @@ void test_repo_open__validates_bare_repo_ownership(void) /* When the system user owns the repo config, fail */ git_fs_path__set_owner(GIT_FS_PATH_OWNER_ADMINISTRATOR); - cl_git_fail(git_repository_open(&repo, "testrepo.git")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "testrepo.git")); #ifdef GIT_WIN32 /* When the user is an administrator, succeed on Windows. */ @@ -527,7 +530,7 @@ void test_repo_open__validates_bare_repo_ownership(void) /* When an unknown user owns the repo config, fail */ git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); - cl_git_fail(git_repository_open(&repo, "testrepo.git")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "testrepo.git")); } void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void) @@ -543,7 +546,7 @@ void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void) cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git")); git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); - cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo")); /* Add safe.directory options to the global configuration */ git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config"); @@ -575,6 +578,45 @@ void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void) git_str_dispose(&config_data); } +void test_repo_open__can_wildcard_allowlist_with_problematic_ownership(void) +{ + git_repository *repo; + git_str config_path = GIT_STR_INIT, config_filename = GIT_STR_INIT; + + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, 1)); + + cl_fixture_sandbox("empty_standard_repo"); + cl_git_pass(cl_rename( + "empty_standard_repo/.gitted", "empty_standard_repo/.git")); + + git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); + cl_git_fail_with( + GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo")); + + /* Add safe.directory options to the global configuration */ + git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config"); + cl_must_pass(p_mkdir(config_path.ptr, 0777)); + git_libgit2_opts( + GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, + config_path.ptr); + + git_str_joinpath(&config_filename, config_path.ptr, ".gitconfig"); + + cl_git_rewritefile(config_filename.ptr, "[foo]\n" + "\tbar = Foobar\n" + "\tbaz = Baz!\n" + "[safe]\n" + "\tdirectory = *\n" + "[bar]\n" + "\tfoo = barfoo\n"); + + cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); + git_repository_free(repo); + + git_str_dispose(&config_path); + git_str_dispose(&config_filename); +} + void test_repo_open__can_allowlist_bare_gitdir(void) { git_repository *repo; @@ -587,7 +629,7 @@ void test_repo_open__can_allowlist_bare_gitdir(void) cl_fixture_sandbox("testrepo.git"); git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); - cl_git_fail(git_repository_open(&repo, "testrepo.git")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "testrepo.git")); /* Add safe.directory options to the global configuration */ git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config"); @@ -619,6 +661,43 @@ void test_repo_open__can_allowlist_bare_gitdir(void) git_str_dispose(&config_data); } +void test_repo_open__can_wildcard_allowlist_bare_gitdir(void) +{ + git_repository *repo; + git_str config_path = GIT_STR_INIT, config_filename = GIT_STR_INIT; + + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, 1)); + + cl_fixture_sandbox("testrepo.git"); + + git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); + cl_git_fail_with( + GIT_EOWNER, git_repository_open(&repo, "testrepo.git")); + + /* Add safe.directory options to the global configuration */ + git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config"); + cl_must_pass(p_mkdir(config_path.ptr, 0777)); + git_libgit2_opts( + GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, + config_path.ptr); + + git_str_joinpath(&config_filename, config_path.ptr, ".gitconfig"); + + cl_git_rewritefile(config_filename.ptr, "[foo]\n" + "\tbar = Foobar\n" + "\tbaz = Baz!\n" + "[safe]\n" + "\tdirectory = *\n" + "[bar]\n" + "\tfoo = barfoo\n"); + + cl_git_pass(git_repository_open(&repo, "testrepo.git")); + git_repository_free(repo); + + git_str_dispose(&config_path); + git_str_dispose(&config_filename); +} + void test_repo_open__can_reset_safe_directory_list(void) { git_repository *repo; @@ -632,7 +711,7 @@ void test_repo_open__can_reset_safe_directory_list(void) cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git")); git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); - cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo")); /* Add safe.directory options to the global configuration */ git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config"); @@ -656,7 +735,7 @@ void test_repo_open__can_reset_safe_directory_list(void) clar_sandbox_path(), "empty_standard_repo"); cl_git_rewritefile(config_filename.ptr, config_data.ptr); - cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo")); /* The blank resets tmp and allows subsequent declarations to succeed */ diff --git a/tests/libgit2/revwalk/basic.c b/tests/libgit2/revwalk/basic.c index 62a57aaa3..41090a1da 100644 --- a/tests/libgit2/revwalk/basic.c +++ b/tests/libgit2/revwalk/basic.c @@ -180,6 +180,23 @@ void test_revwalk_basic__glob_heads_with_invalid(void) cl_assert_equal_i(20, i); } +void test_revwalk_basic__glob_invalid_symbolic_ref(void) +{ + int i; + git_oid oid; + + revwalk_basic_setup_walk("testrepo"); + + cl_git_mkfile("testrepo/.git/refs/heads/broken-sym-ref", "ref: refs/heads/does-not-exist"); + cl_git_pass(git_revwalk_push_glob(_walk, "heads")); + + for (i = 0; !git_revwalk_next(&oid, _walk); ++i) + /* walking */; + + /* git log --branches --oneline | wc -l => 16 */ + cl_assert_equal_i(20, i); +} + void test_revwalk_basic__push_head(void) { int i = 0; diff --git a/tests/libgit2/stash/save.c b/tests/libgit2/stash/save.c index f574211d7..23f3c1cbb 100644 --- a/tests/libgit2/stash/save.c +++ b/tests/libgit2/stash/save.c @@ -130,6 +130,19 @@ void test_stash_save__can_keep_index(void) assert_status(repo, "just.ignore", GIT_STATUS_IGNORED); } +void test_stash_save__can_keep_all(void) +{ + cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_KEEP_ALL)); + + assert_status(repo, "what", GIT_STATUS_WT_MODIFIED | GIT_STATUS_INDEX_MODIFIED); + assert_status(repo, "how", GIT_STATUS_INDEX_MODIFIED); + assert_status(repo, "who", GIT_STATUS_WT_MODIFIED); + assert_status(repo, "when", GIT_STATUS_WT_NEW); + assert_status(repo, "why", GIT_STATUS_INDEX_NEW); + assert_status(repo, "where", GIT_STATUS_WT_MODIFIED | GIT_STATUS_INDEX_NEW); + assert_status(repo, "just.ignore", GIT_STATUS_IGNORED); +} + static void assert_commit_message_contains(const char *revision, const char *fragment) { git_commit *commit; @@ -488,3 +501,27 @@ void test_stash_save__deleted_in_index_modified_in_workdir(void) git_index_free(index); } + +void test_stash_save__option_paths(void) +{ + git_stash_save_options options = GIT_STASH_SAVE_OPTIONS_INIT; + char *paths[2] = { "who", "where" }; + + options.paths = (git_strarray){ + paths, + 2 + }; + options.stasher = signature; + + cl_git_pass(git_stash_save_with_opts(&stash_tip_oid, repo, &options)); + + assert_blob_oid("refs/stash:who", "a0400d4954659306a976567af43125a0b1aa8595"); + assert_blob_oid("refs/stash:where", "e3d6434ec12eb76af8dfa843a64ba6ab91014a0b"); + + assert_blob_oid("refs/stash:what", "ce013625030ba8dba906f756967f9e9ca394464a"); + assert_blob_oid("refs/stash:how", "ac790413e2d7a26c3767e78c57bb28716686eebc"); + assert_blob_oid("refs/stash:when", NULL); + assert_blob_oid("refs/stash:why", NULL); + assert_blob_oid("refs/stash:.gitignore", "ac4d88de61733173d9959e4b77c69b9f17a00980"); + assert_blob_oid("refs/stash:just.ignore", NULL); +} diff --git a/tests/libgit2/submodule/update.c b/tests/libgit2/submodule/update.c index 4aa959852..052a4a1fe 100644 --- a/tests/libgit2/submodule/update.c +++ b/tests/libgit2/submodule/update.c @@ -206,6 +206,26 @@ void test_submodule_update__update_and_init_submodule(void) git_submodule_free(sm); } +void test_submodule_update__update_skip_configured_missing_submodule(void) +{ + git_submodule *sm; + git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT; + unsigned int submodule_status = 0; + + g_repo = setup_fixture_submod2(); + + /* get the submodule */ + cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_gitmodules_only")); + + cl_git_pass(git_submodule_status(&submodule_status, g_repo, "sm_gitmodules_only", GIT_SUBMODULE_IGNORE_UNSPECIFIED)); + cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_CONFIG); + + /* update (with option to initialize sub repo) */ + cl_git_pass(git_submodule_update(sm, 1, &update_options)); + + git_submodule_free(sm); +} + void test_submodule_update__update_already_checked_out_submodule(void) { git_submodule *sm = NULL; diff --git a/tests/libgit2/transports/smart/packet.c b/tests/libgit2/transports/smart/packet.c index 8801ef833..2035e3b65 100644 --- a/tests/libgit2/transports/smart/packet.c +++ b/tests/libgit2/transports/smart/packet.c @@ -11,8 +11,9 @@ static void assert_flush_parses(const char *line) size_t linelen = strlen(line) + 1; const char *endptr; git_pkt *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_FLUSH); cl_assert_equal_strn(endptr, line + 4, linelen - 4); @@ -24,8 +25,9 @@ static void assert_data_pkt_parses(const char *line, const char *expected_data, size_t linelen = strlen(line) + 1; const char *endptr; git_pkt_data *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_DATA); cl_assert_equal_i(pkt->len, expected_len); cl_assert_equal_strn(pkt->data, expected_data, expected_len); @@ -38,8 +40,9 @@ static void assert_sideband_progress_parses(const char *line, const char *expect size_t linelen = strlen(line) + 1; const char *endptr; git_pkt_progress *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_PROGRESS); cl_assert_equal_i(pkt->len, expected_len); cl_assert_equal_strn(pkt->data, expected_data, expected_len); @@ -52,8 +55,9 @@ static void assert_error_parses(const char *line, const char *expected_error, si size_t linelen = strlen(line) + 1; const char *endptr; git_pkt_err *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_ERR); cl_assert_equal_i(pkt->len, expected_len); cl_assert_equal_strn(pkt->error, expected_error, expected_len); @@ -67,10 +71,11 @@ static void assert_ack_parses(const char *line, const char *expected_oid, enum g const char *endptr; git_pkt_ack *pkt; git_oid oid; + git_pkt_parse_data pkt_parse_data = { 0 }; cl_git_pass(git_oid__fromstr(&oid, expected_oid, GIT_OID_SHA1)); - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_ACK); cl_assert_equal_oid(&pkt->oid, &oid); cl_assert_equal_i(pkt->status, expected_status); @@ -83,8 +88,9 @@ static void assert_nak_parses(const char *line) size_t linelen = strlen(line) + 1; const char *endptr; git_pkt *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_NAK); cl_assert_equal_strn(endptr, line + 7, linelen - 7); @@ -96,8 +102,9 @@ static void assert_comment_parses(const char *line, const char *expected_comment size_t linelen = strlen(line) + 1; const char *endptr; git_pkt_comment *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_COMMENT); cl_assert_equal_strn(pkt->comment, expected_comment, strlen(expected_comment)); @@ -109,8 +116,9 @@ static void assert_ok_parses(const char *line, const char *expected_ref) size_t linelen = strlen(line) + 1; const char *endptr; git_pkt_ok *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_OK); cl_assert_equal_strn(pkt->ref, expected_ref, strlen(expected_ref)); @@ -122,8 +130,9 @@ static void assert_unpack_parses(const char *line, bool ok) size_t linelen = strlen(line) + 1; const char *endptr; git_pkt_unpack *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_UNPACK); cl_assert_equal_i(pkt->unpack_ok, ok); @@ -135,8 +144,9 @@ static void assert_ng_parses(const char *line, const char *expected_ref, const c size_t linelen = strlen(line) + 1; const char *endptr; git_pkt_ng *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_NG); cl_assert_equal_strn(pkt->ref, expected_ref, strlen(expected_ref)); cl_assert_equal_strn(pkt->msg, expected_msg, strlen(expected_msg)); @@ -153,10 +163,11 @@ static void assert_ref_parses_(const char *line, size_t linelen, const char *exp const char *endptr; git_pkt_ref *pkt; git_oid oid; + git_pkt_parse_data pkt_parse_data = { 0 }; cl_git_pass(git_oid__fromstr(&oid, expected_oid, GIT_OID_SHA1)); - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_REF); cl_assert_equal_oid(&pkt->head.oid, &oid); cl_assert_equal_strn(pkt->head.name, expected_ref, strlen(expected_ref)); @@ -171,8 +182,10 @@ static void assert_ref_parses_(const char *line, size_t linelen, const char *exp static void assert_pkt_fails(const char *line) { const char *endptr; + git_pkt_parse_data pkt_parse_data = { 0 }; + git_pkt *pkt; - cl_git_fail(git_pkt_parse_line(&pkt, &endptr, line, strlen(line) + 1)); + cl_git_fail(git_pkt_parse_line(&pkt, &endptr, line, strlen(line) + 1, &pkt_parse_data)); } void test_transports_smart_packet__parsing_garbage_fails(void) diff --git a/tests/libgit2/win32/systemdir.c b/tests/libgit2/win32/systemdir.c index 52c1784a1..9039f05b2 100644 --- a/tests/libgit2/win32/systemdir.c +++ b/tests/libgit2/win32/systemdir.c @@ -1,7 +1,6 @@ #include "clar_libgit2.h" #include "futils.h" #include "sysdir.h" -#include "win32/findfile.h" #ifdef GIT_WIN32 static char *path_save; diff --git a/tests/libgit2/worktree/worktree.c b/tests/libgit2/worktree/worktree.c index 66273d1cb..9fd27f49c 100644 --- a/tests/libgit2/worktree/worktree.c +++ b/tests/libgit2/worktree/worktree.c @@ -120,7 +120,7 @@ void test_worktree_worktree__lookup_nonexistent_worktree(void) { git_worktree *wt; - cl_git_fail(git_worktree_lookup(&wt, fixture.repo, "nonexistent")); + cl_git_fail_with(GIT_ENOTFOUND, git_worktree_lookup(&wt, fixture.repo, "nonexistent")); cl_assert_equal_p(wt, NULL); } |
