summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/checkout/nasty.c13
-rw-r--r--tests/clar_libgit2.h2
-rw-r--r--tests/index/tests.c136
-rw-r--r--tests/object/tree/write.c9
-rw-r--r--tests/path/core.c11
-rw-r--r--tests/path/dotgit.c1
-rw-r--r--tests/resources/nasty/.gitted/objects/33/8190107c7ee7d8f5aa30061fc19b7d5ddcda86bin0 -> 55 bytes
-rw-r--r--tests/resources/nasty/.gitted/objects/97/c14994866466aeb73e769a6f34e07c7f4b53f7bin0 -> 65 bytes
-rw-r--r--tests/resources/nasty/.gitted/objects/b8/edf3ad62dbcbc983857a5bfee7b0181ee1a513bin0 -> 135 bytes
-rw-r--r--tests/resources/nasty/.gitted/refs/heads/dotgit_alternate_data_stream1
10 files changed, 144 insertions, 29 deletions
diff --git a/tests/checkout/nasty.c b/tests/checkout/nasty.c
index d4d3c8fa4..2a602951b 100644
--- a/tests/checkout/nasty.c
+++ b/tests/checkout/nasty.c
@@ -206,9 +206,8 @@ void test_checkout_nasty__dot_git_dot(void)
*/
void test_checkout_nasty__git_tilde1(void)
{
-#ifdef GIT_WIN32
test_checkout_fails("refs/heads/git_tilde1", ".git/foobar");
-#endif
+ test_checkout_fails("refs/heads/git_tilde1", "git~1/foobar");
}
/* A tree that contains an entry "git~2", when we have forced the short
@@ -274,6 +273,16 @@ void test_checkout_nasty__dot_git_colon_stuff(void)
#endif
}
+/* A tree that contains an entry ".git::$INDEX_ALLOCATION" because NTFS
+ * will interpret that as a synonym to ".git", even when mounted via SMB
+ * on macOS.
+ */
+void test_checkout_nasty__dotgit_alternate_data_stream(void)
+{
+ test_checkout_fails("refs/heads/dotgit_alternate_data_stream", ".git/dummy-file");
+ test_checkout_fails("refs/heads/dotgit_alternate_data_stream", ".git::$INDEX_ALLOCATION/dummy-file");
+}
+
/* Trees that contains entries with a tree ".git" that contain
* byte sequences:
* { 0xe2, 0x80, 0x8c }
diff --git a/tests/clar_libgit2.h b/tests/clar_libgit2.h
index c72d37db3..b0a069355 100644
--- a/tests/clar_libgit2.h
+++ b/tests/clar_libgit2.h
@@ -29,8 +29,8 @@
* calls that are supposed to fail!
*/
#define cl_git_fail(expr) do { \
- giterr_clear(); \
if ((expr) == 0) \
+ giterr_clear(), \
cl_git_report_failure(0, 0, __FILE__, __LINE__, "Function call succeeded: " #expr); \
} while (0)
diff --git a/tests/index/tests.c b/tests/index/tests.c
index ea8335b48..8ca4939fe 100644
--- a/tests/index/tests.c
+++ b/tests/index/tests.c
@@ -452,7 +452,7 @@ void test_index_tests__add_bypath_to_a_bare_repository_returns_EBAREPO(void)
git_repository_free(bare_repo);
}
-static void add_invalid_filename(git_repository *repo, const char *fn)
+static void assert_add_bypath_fails(git_repository *repo, const char *fn)
{
git_index *index;
git_buf path = GIT_BUF_INIT;
@@ -473,7 +473,7 @@ static void add_invalid_filename(git_repository *repo, const char *fn)
}
/* Test that writing an invalid filename fails */
-void test_index_tests__add_invalid_filename(void)
+void test_index_tests__cannot_add_invalid_filename(void)
{
git_repository *repo;
@@ -488,13 +488,69 @@ void test_index_tests__add_invalid_filename(void)
if (!git_path_exists("./invalid/.GiT"))
cl_must_pass(p_mkdir("./invalid/.GiT", 0777));
- add_invalid_filename(repo, ".git/hello");
- add_invalid_filename(repo, ".GIT/hello");
- add_invalid_filename(repo, ".GiT/hello");
- add_invalid_filename(repo, "./.git/hello");
- add_invalid_filename(repo, "./foo");
- add_invalid_filename(repo, "./bar");
- add_invalid_filename(repo, "subdir/../bar");
+ assert_add_bypath_fails(repo, ".git/hello");
+ assert_add_bypath_fails(repo, ".GIT/hello");
+ assert_add_bypath_fails(repo, ".GiT/hello");
+ assert_add_bypath_fails(repo, "./.git/hello");
+ assert_add_bypath_fails(repo, "./foo");
+ assert_add_bypath_fails(repo, "./bar");
+ assert_add_bypath_fails(repo, "subdir/../bar");
+
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("invalid");
+}
+
+static void assert_add_fails(git_repository *repo, const char *fn)
+{
+ git_index *index;
+ git_buf path = GIT_BUF_INIT;
+ git_index_entry entry = {{0}};
+
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert(git_index_entrycount(index) == 0);
+
+ entry.path = fn;
+ entry.mode = GIT_FILEMODE_BLOB;
+ cl_git_pass(git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"));
+
+ cl_git_fail(git_index_add(index, &entry));
+
+ cl_assert(git_index_entrycount(index) == 0);
+
+ git_buf_free(&path);
+ git_index_free(index);
+}
+
+/*
+ * Test that writing an invalid filename fails on filesystem
+ * specific protected names
+ */
+void test_index_tests__cannot_add_protected_invalid_filename(void)
+{
+ git_repository *repo;
+ git_index *index;
+
+ cl_must_pass(p_mkdir("invalid", 0700));
+
+ cl_git_pass(git_repository_init(&repo, "./invalid", 0));
+
+ /* add a file to the repository so we can reference it later */
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_mkfile("invalid/dummy.txt", "");
+ cl_git_pass(git_index_add_bypath(index, "dummy.txt"));
+ cl_must_pass(p_unlink("invalid/dummy.txt"));
+ cl_git_pass(git_index_remove_bypath(index, "dummy.txt"));
+ git_index_free(index);
+
+ cl_repo_set_bool(repo, "core.protectHFS", true);
+ cl_repo_set_bool(repo, "core.protectNTFS", true);
+
+ assert_add_fails(repo, ".git./hello");
+ assert_add_fails(repo, ".git\xe2\x80\xad/hello");
+ assert_add_fails(repo, "git~1/hello");
+ assert_add_fails(repo, ".git\xe2\x81\xaf/hello");
+ assert_add_fails(repo, ".git::$INDEX_ALLOCATION/dummy-file");
git_repository_free(repo);
@@ -510,7 +566,7 @@ static void replace_char(char *str, char in, char out)
*c = out;
}
-static void write_invalid_filename(git_repository *repo, const char *fn_orig)
+static void assert_write_fails(git_repository *repo, const char *fn_orig)
{
git_index *index;
git_oid expected;
@@ -527,6 +583,7 @@ static void write_invalid_filename(git_repository *repo, const char *fn_orig)
*/
fn = git__strdup(fn_orig);
replace_char(fn, '/', '_');
+ replace_char(fn, ':', '!');
git_buf_joinpath(&path, "./invalid", fn);
@@ -538,6 +595,7 @@ static void write_invalid_filename(git_repository *repo, const char *fn_orig)
/* kids, don't try this at home */
replace_char((char *)entry->path, '_', '/');
+ replace_char((char *)entry->path, '!', ':');
/* write-tree */
cl_git_fail(git_index_write_tree(&expected, index));
@@ -559,13 +617,13 @@ void test_index_tests__write_invalid_filename(void)
cl_git_pass(git_repository_init(&repo, "./invalid", 0));
- write_invalid_filename(repo, ".git/hello");
- write_invalid_filename(repo, ".GIT/hello");
- write_invalid_filename(repo, ".GiT/hello");
- write_invalid_filename(repo, "./.git/hello");
- write_invalid_filename(repo, "./foo");
- write_invalid_filename(repo, "./bar");
- write_invalid_filename(repo, "foo/../bar");
+ assert_write_fails(repo, ".git/hello");
+ assert_write_fails(repo, ".GIT/hello");
+ assert_write_fails(repo, ".GiT/hello");
+ assert_write_fails(repo, "./.git/hello");
+ assert_write_fails(repo, "./foo");
+ assert_write_fails(repo, "./bar");
+ assert_write_fails(repo, "foo/../bar");
git_repository_free(repo);
@@ -583,16 +641,52 @@ void test_index_tests__honors_protect_filesystems(void)
cl_repo_set_bool(repo, "core.protectHFS", true);
cl_repo_set_bool(repo, "core.protectNTFS", true);
- write_invalid_filename(repo, ".git./hello");
- write_invalid_filename(repo, ".git\xe2\x80\xad/hello");
- write_invalid_filename(repo, "git~1/hello");
- write_invalid_filename(repo, ".git\xe2\x81\xaf/hello");
+ assert_write_fails(repo, ".git./hello");
+ assert_write_fails(repo, ".git\xe2\x80\xad/hello");
+ assert_write_fails(repo, "git~1/hello");
+ assert_write_fails(repo, ".git\xe2\x81\xaf/hello");
+ assert_write_fails(repo, ".git::$INDEX_ALLOCATION/dummy-file");
+
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("invalid");
+}
+
+void test_index_tests__protectntfs_on_by_default(void)
+{
+ git_repository *repo;
+
+ p_mkdir("invalid", 0700);
+
+ cl_git_pass(git_repository_init(&repo, "./invalid", 0));
+ assert_write_fails(repo, ".git./hello");
+ assert_write_fails(repo, "git~1/hello");
git_repository_free(repo);
cl_fixture_cleanup("invalid");
}
+void test_index_tests__can_disable_protectntfs(void)
+{
+ git_repository *repo;
+ git_index *index;
+
+ cl_must_pass(p_mkdir("valid", 0700));
+ cl_git_rewritefile("valid/git~1", "steal the shortname");
+
+ cl_git_pass(git_repository_init(&repo, "./valid", 0));
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_repo_set_bool(repo, "core.protectNTFS", false);
+
+ cl_git_pass(git_index_add_bypath(index, "git~1"));
+
+ git_index_free(index);
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("valid");
+}
+
void test_index_tests__remove_entry(void)
{
git_repository *repo;
diff --git a/tests/object/tree/write.c b/tests/object/tree/write.c
index a1ee03d6d..bef5ff3f6 100644
--- a/tests/object/tree/write.c
+++ b/tests/object/tree/write.c
@@ -141,7 +141,7 @@ void test_object_tree_write__sorted_subtrees(void)
cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL));
for (i = 0; i < ARRAY_SIZE(entries); ++i) {
- git_oid *id = entries[i].attr == GIT_FILEMODE_TREE ? &tid : &bid;
+ git_oid *id = entries[i].attr == GIT_FILEMODE_TREE ? &tid : &bid;
cl_git_pass(git_treebuilder_insert(NULL,
builder, entries[i].filename, id, entries[i].attr));
@@ -418,10 +418,8 @@ void test_object_tree_write__protect_filesystems(void)
*/
cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL));
-#ifndef GIT_WIN32
- cl_git_pass(git_treebuilder_insert(NULL, builder, ".git.", &bid, GIT_FILEMODE_BLOB));
- cl_git_pass(git_treebuilder_insert(NULL, builder, "git~1", &bid, GIT_FILEMODE_BLOB));
-#endif
+ cl_git_fail(git_treebuilder_insert(NULL, builder, ".git.", &bid, GIT_FILEMODE_BLOB));
+ cl_git_fail(git_treebuilder_insert(NULL, builder, "git~1", &bid, GIT_FILEMODE_BLOB));
#ifndef __APPLE__
cl_git_pass(git_treebuilder_insert(NULL, builder, ".git\xef\xbb\xbf", &bid, GIT_FILEMODE_BLOB));
@@ -444,6 +442,7 @@ void test_object_tree_write__protect_filesystems(void)
cl_git_fail(git_treebuilder_insert(NULL, builder, ".git\xef\xbb\xbf", &bid, GIT_FILEMODE_BLOB));
cl_git_fail(git_treebuilder_insert(NULL, builder, ".git\xe2\x80\xad", &bid, GIT_FILEMODE_BLOB));
+ cl_git_fail(git_treebuilder_insert(NULL, builder, ".git::$INDEX_ALLOCATION/dummy-file", &bid, GIT_FILEMODE_BLOB));
git_treebuilder_free(builder);
}
diff --git a/tests/path/core.c b/tests/path/core.c
index 0ab41ea50..dcc85fb78 100644
--- a/tests/path/core.c
+++ b/tests/path/core.c
@@ -352,3 +352,14 @@ void test_path_core__join_unrooted(void)
git_buf_free(&out);
}
+
+void test_path_core__join_unrooted_respects_funny_windows_roots(void)
+{
+ test_join_unrooted("💩:/foo/bar/foobar", 9, "bar/foobar", "💩:/foo");
+ test_join_unrooted("💩:/foo/bar/foobar", 13, "foobar", "💩:/foo/bar");
+ test_join_unrooted("💩:/foo", 5, "💩:/foo", "💩:/asdf");
+ test_join_unrooted("💩:/foo/bar", 5, "💩:/foo/bar", "💩:/asdf");
+ test_join_unrooted("💩:/foo/bar/foobar", 9, "💩:/foo/bar/foobar", "💩:/foo");
+ test_join_unrooted("💩:/foo/bar/foobar", 13, "💩:/foo/bar/foobar", "💩:/foo/bar");
+ test_join_unrooted("💩:/foo/bar/foobar", 9, "💩:/foo/bar/foobar", "💩:/foo/");
+}
diff --git a/tests/path/dotgit.c b/tests/path/dotgit.c
index 20e585edb..425392403 100644
--- a/tests/path/dotgit.c
+++ b/tests/path/dotgit.c
@@ -116,4 +116,5 @@ void test_path_dotgit__dotgit_modules_symlink(void)
cl_assert_equal_b(true, git_path_isvalid(NULL, ".gitmodules", 0, GIT_PATH_REJECT_DOT_GIT_HFS|GIT_PATH_REJECT_DOT_GIT_NTFS));
cl_assert_equal_b(false, git_path_isvalid(NULL, ".gitmodules", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(false, git_path_isvalid(NULL, ".gitmodules", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS));
+ cl_assert_equal_b(false, git_path_isvalid(NULL, ".gitmodules . .::$DATA", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS));
}
diff --git a/tests/resources/nasty/.gitted/objects/33/8190107c7ee7d8f5aa30061fc19b7d5ddcda86 b/tests/resources/nasty/.gitted/objects/33/8190107c7ee7d8f5aa30061fc19b7d5ddcda86
new file mode 100644
index 000000000..e539ccfec
--- /dev/null
+++ b/tests/resources/nasty/.gitted/objects/33/8190107c7ee7d8f5aa30061fc19b7d5ddcda86
Binary files differ
diff --git a/tests/resources/nasty/.gitted/objects/97/c14994866466aeb73e769a6f34e07c7f4b53f7 b/tests/resources/nasty/.gitted/objects/97/c14994866466aeb73e769a6f34e07c7f4b53f7
new file mode 100644
index 000000000..9f7679917
--- /dev/null
+++ b/tests/resources/nasty/.gitted/objects/97/c14994866466aeb73e769a6f34e07c7f4b53f7
Binary files differ
diff --git a/tests/resources/nasty/.gitted/objects/b8/edf3ad62dbcbc983857a5bfee7b0181ee1a513 b/tests/resources/nasty/.gitted/objects/b8/edf3ad62dbcbc983857a5bfee7b0181ee1a513
new file mode 100644
index 000000000..bf446263c
--- /dev/null
+++ b/tests/resources/nasty/.gitted/objects/b8/edf3ad62dbcbc983857a5bfee7b0181ee1a513
Binary files differ
diff --git a/tests/resources/nasty/.gitted/refs/heads/dotgit_alternate_data_stream b/tests/resources/nasty/.gitted/refs/heads/dotgit_alternate_data_stream
new file mode 100644
index 000000000..ecdd340cd
--- /dev/null
+++ b/tests/resources/nasty/.gitted/refs/heads/dotgit_alternate_data_stream
@@ -0,0 +1 @@
+b8edf3ad62dbcbc983857a5bfee7b0181ee1a513