Skip to content

Commit 0619351

Browse files
committed
tests: Move invalid nar tests from tests/functional to libutil-tests
Since 242f362 we have better infrastructure for this kind of tests.
1 parent fb117e0 commit 0619351

File tree

9 files changed

+15
-29
lines changed

9 files changed

+15
-29
lines changed

src/libutil-tests/archive.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ INSTANTIATE_TEST_SUITE_P(
4242
NarTest,
4343
InvalidNarTest,
4444
::testing::Values(
45-
std::pair{"invalid-tag-instead-of-contents", "bad archive: expected tag 'contents', got 'AAAAAAAA'"}));
45+
std::pair{"invalid-tag-instead-of-contents", "bad archive: expected tag 'contents', got 'AAAAAAAA'"},
46+
// Unpacking a NAR with a NUL character in a file name should fail.
47+
std::pair{"nul-character", "bad archive: NAR contains invalid file name 'f"},
48+
// Likewise for a '.' filename.
49+
std::pair{"dot", "bad archive: NAR contains invalid file name '.'"},
50+
// Likewise for a '..' filename.
51+
std::pair{"dotdot", "bad archive: NAR contains invalid file name '..'"},
52+
// Likewise for a filename containing a slash.
53+
std::pair{"slash", "bad archive: NAR contains invalid file name 'x/y'"},
54+
// Likewise for an empty filename.
55+
std::pair{"empty", "bad archive: NAR contains invalid file name ''"},
56+
// Test that the 'executable' field cannot come before the 'contents' field.
57+
std::pair{"executable-after-contents", "bad archive: expected tag ')', got 'executable'"},
58+
// Test that the 'name' field cannot come before the 'node' field in a directory entry.
59+
std::pair{"name-after-node", "bad archive: expected tag 'name'"}));
4660

4761
} // namespace nix
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/functional/nars.sh

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -131,31 +131,3 @@ else
131131
fi
132132

133133
rm -f "$TEST_ROOT/unicode-*"
134-
135-
# Unpacking a NAR with a NUL character in a file name should fail.
136-
rm -rf "$TEST_ROOT/out"
137-
expectStderr 1 nix-store --restore "$TEST_ROOT/out" < nul-character.nar | grepQuiet "NAR contains invalid file name 'f"
138-
139-
# Likewise for a '.' filename.
140-
rm -rf "$TEST_ROOT/out"
141-
expectStderr 1 nix-store --restore "$TEST_ROOT/out" < dot.nar | grepQuiet "NAR contains invalid file name '.'"
142-
143-
# Likewise for a '..' filename.
144-
rm -rf "$TEST_ROOT/out"
145-
expectStderr 1 nix-store --restore "$TEST_ROOT/out" < dotdot.nar | grepQuiet "NAR contains invalid file name '..'"
146-
147-
# Likewise for a filename containing a slash.
148-
rm -rf "$TEST_ROOT/out"
149-
expectStderr 1 nix-store --restore "$TEST_ROOT/out" < slash.nar | grepQuiet "NAR contains invalid file name 'x/y'"
150-
151-
# Likewise for an empty filename.
152-
rm -rf "$TEST_ROOT/out"
153-
expectStderr 1 nix-store --restore "$TEST_ROOT/out" < empty.nar | grepQuiet "NAR contains invalid file name ''"
154-
155-
# Test that the 'executable' field cannot come before the 'contents' field.
156-
rm -rf "$TEST_ROOT/out"
157-
expectStderr 1 nix-store --restore "$TEST_ROOT/out" < executable-after-contents.nar | grepQuiet "expected tag ')', got 'executable'"
158-
159-
# Test that the 'name' field cannot come before the 'node' field in a directory entry.
160-
rm -rf "$TEST_ROOT/out"
161-
expectStderr 1 nix-store --restore "$TEST_ROOT/out" < name-after-node.nar | grepQuiet "expected tag 'name'"

0 commit comments

Comments
 (0)