diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 11:43:14 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 11:43:14 -0500 |
| commit | a7e9fca8b929dca0b8b68e8fbda91beedf5efb9e (patch) | |
| tree | a1886d6c71f18fe9d9d6971cb2819fcc47c22664 | |
| parent | a9f9a52cf30590dfc4dee4998e6e702f9987a062 (diff) | |
| parent | e8594fc3ea732bd7bdba730d7e1f643257654ed5 (diff) | |
Merge pull request #2235 from Vonsek
| -rw-r--r-- | tests/test_manifest_verifier.py | 24 | ||||
| -rw-r--r-- | tools/manifest_verifier.py | 2 |
2 files changed, 24 insertions, 2 deletions
diff --git a/tests/test_manifest_verifier.py b/tests/test_manifest_verifier.py index 5c3d055be..c6faa4be5 100644 --- a/tests/test_manifest_verifier.py +++ b/tests/test_manifest_verifier.py | |||
| @@ -12,11 +12,12 @@ import hashlib | |||
| 12 | import io | 12 | import io |
| 13 | import json | 13 | import json |
| 14 | import os | 14 | import os |
| 15 | import posixpath | ||
| 15 | import subprocess | 16 | import subprocess |
| 16 | import sys | 17 | import sys |
| 17 | import tempfile | 18 | import tempfile |
| 18 | import unittest | 19 | import unittest |
| 19 | from unittest.mock import patch | 20 | from unittest.mock import Mock, patch |
| 20 | 21 | ||
| 21 | ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 22 | ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 22 | TOOL = os.path.join(ROOT, "tools", "manifest_verifier.py") | 23 | TOOL = os.path.join(ROOT, "tools", "manifest_verifier.py") |
| @@ -101,6 +102,27 @@ class TestManifestVerifier(unittest.TestCase): | |||
| 101 | for rel in items: | 102 | for rel in items: |
| 102 | self.assertNotIn("\\", rel) | 103 | self.assertNotIn("\\", rel) |
| 103 | 104 | ||
| 105 | def test_posix_backslash_filename_cannot_match_a_nested_path(self) -> None: | ||
| 106 | payload = b"same bytes as the expected file" | ||
| 107 | nested = "nested/echo.bin" | ||
| 108 | literal_name = r"nested\echo.bin" | ||
| 109 | self.write_manifest(self.manifest_path, {nested: payload}) | ||
| 110 | |||
| 111 | # Simulate POSIX directory entries even on Windows, where a filename cannot contain a literal backslash. | ||
| 112 | target = "/target" | ||
| 113 | posix_os = Mock(sep="/", path=Mock(wraps=posixpath)) | ||
| 114 | posix_os.path.isdir.return_value = True | ||
| 115 | posix_os.path.isfile.side_effect = os.path.isfile | ||
| 116 | posix_os.path.getsize.return_value = len(payload) | ||
| 117 | posix_os.walk.return_value = [(target, [], [literal_name])] | ||
| 118 | with (patch.object(mv, "os", posix_os), | ||
| 119 | patch.object(mv, "sha256_file", return_value=hashlib.sha256(payload).hexdigest()) as hash_file): | ||
| 120 | report = mv.verify_manifest(target, self.manifest_path) | ||
| 121 | self.assertFalse(report.passed) | ||
| 122 | self.assertEqual(report.missing, [nested]) | ||
| 123 | self.assertEqual(report.untracked, [literal_name]) | ||
| 124 | hash_file.assert_not_called() | ||
| 125 | |||
| 104 | def test_load_manifest_valid_and_case_insensitive(self) -> None: | 126 | def test_load_manifest_valid_and_case_insensitive(self) -> None: |
| 105 | manifest_upper = os.path.join(self.root, "manifest_upper.json") | 127 | manifest_upper = os.path.join(self.root, "manifest_upper.json") |
| 106 | self.write_manifest(manifest_upper, self.payloads, upper_hash=True) | 128 | self.write_manifest(manifest_upper, self.payloads, upper_hash=True) |
diff --git a/tools/manifest_verifier.py b/tools/manifest_verifier.py index 6e595de4a..c2e0ef011 100644 --- a/tools/manifest_verifier.py +++ b/tools/manifest_verifier.py | |||
| @@ -79,7 +79,7 @@ def walk(target_dir: str, *, exclude: str | None = None): | |||
| 79 | if contains_manifest and os.path.normcase(name) == excluded_name: | 79 | if contains_manifest and os.path.normcase(name) == excluded_name: |
| 80 | continue | 80 | continue |
| 81 | abs_p = os.path.join(root, name) | 81 | abs_p = os.path.join(root, name) |
| 82 | rel_p = os.path.relpath(abs_p, target_dir).replace("\\", "/") | 82 | rel_p = os.path.relpath(abs_p, target_dir).replace(os.sep, "/") |
| 83 | yield rel_p, abs_p | 83 | yield rel_p, abs_p |
| 84 | 84 | ||
| 85 | 85 | ||