Skip to content

Commit 30623b9

Browse files
committed
Add tests for .oci files
1 parent 20f5470 commit 30623b9

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

src/gardenlinux/features/reproducibility/comparator.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def _unpack(file: PathLike[str]) -> tempfile.TemporaryDirectory[str]:
7373
with tempfile.TemporaryDirectory() as extracted:
7474
# Extract .oci file
7575
with tarfile.open(file, "r") as tar:
76-
tar.extractall(path=extracted)
76+
tar.extractall(path=extracted, filter="fully_trusted")
7777

7878
layers_dir = Path(extracted).joinpath("blobs/sha256")
7979
assert layers_dir.is_dir()
@@ -96,14 +96,22 @@ def _unpack(file: PathLike[str]) -> tempfile.TemporaryDirectory[str]:
9696
with tarfile.open(layer_path, "r") as tar:
9797
for member in tar.getmembers():
9898
try:
99-
tar.extract(member, path=output_dir.name)
99+
tar.extract(
100+
member,
101+
path=output_dir.name,
102+
filter="fully_trusted",
103+
)
100104
except tarfile.AbsoluteLinkError:
101105
# Convert absolute link to relative link
102106
member.linkpath = (
103107
"../" * member.path.count("/")
104108
+ member.linkpath[1:]
105109
)
106-
tar.extract(member, path=output_dir.name)
110+
tar.extract(
111+
member,
112+
path=output_dir.name,
113+
filter="fully_trusted",
114+
)
107115
except tarfile.TarError as e:
108116
print(f"Skipping {member.name} due to error: {e}")
109117
else:
10 KB
Binary file not shown.
10 KB
Binary file not shown.

test-data/reproducibility/compare/cname-diff.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/features/test_reproducibility.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,26 +153,28 @@ def test_formatter_main(
153153
assert received == expected
154154

155155

156-
def test_comparator() -> None:
156+
@pytest.mark.parametrize("type", [".tar", ".oci"])
157+
def test_comparator_tar(type: str) -> None:
157158
comparator = Comparator()
158159

159160
files, whitelist = comparator.generate(
160-
compare_files.joinpath("a.tar"), compare_files.joinpath("b.tar")
161+
compare_files.joinpath(f"a{type}"), compare_files.joinpath(f"b{type}")
161162
)
162163

163164
assert not whitelist, "Whitelist is empty and should not filter anything"
164165

165166
assert files == ["/a/b/c.txt"]
166167

167168

169+
@pytest.mark.parametrize("type", [".tar", ".oci"])
168170
def test_comparator_main(
169-
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
171+
type: str, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
170172
) -> None:
171173
argv = [
172174
"gl-diff",
173175
"generate",
174-
str(compare_files.joinpath("a.tar")),
175-
str(compare_files.joinpath("b.tar")),
176+
str(compare_files.joinpath(f"a{type}")),
177+
str(compare_files.joinpath(f"b{type}")),
176178
]
177179

178180
monkeypatch.setattr(sys, "argv", argv)

0 commit comments

Comments
 (0)