GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — t3code/.github/scripts/stage-preview-bundle.test.py at main · ScriptedAlchemy/t3code Expand file tree/ Copy pathstage-preview-bundle.test.pyMore file actions 97 lines (84 loc) · 3.75 KB / Copy pathstage-preview-bundle.test.pyFile metadata and controls97 lines (84 loc) · 3.75 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 import importlib.util import stat import tempfile import unittest import zipfile from pathlib import Path from unittest.mock import patch spec = importlib.util.spec_from_file_location( "stage_preview_bundle", Path(__file__).with_name("stage-preview-bundle.py") ) staging = importlib.util.module_from_spec(spec) spec.loader.exec_module(staging) class StagePreviewBundleTests(unittest.TestCase): def setUp(self): self.temp = tempfile.TemporaryDirectory() self.addCleanup(self.temp.cleanup) self.root = Path(self.temp.name) self.archive = self.root / "bundle.zip" self.destination = self.root / "staged" def bundle(self, extra=(), missing=None): with zipfile.ZipFile(self.archive, "w") as bundle: for name in sorted(staging.REQUIRED_FILES - {missing}): bundle.writestr(name, b"bundle data, never executed") for name, content in extra: bundle.writestr(name, content) def stage(self): staging.stage_bundle(self.archive, self.destination) def test_preserves_valid_bundle_layout_and_bytes(self): self.bundle([("server/", b""), ("server/dist/", b""), ("desktop/dist-electron/chunks/helper.cjs", b"chunk")]) self.stage() for name in staging.REQUIRED_FILES: self.assertEqual((self.destination / name).read_bytes(), b"bundle data, never executed") self.assertEqual((self.destination / "desktop/dist-electron/chunks/helper.cjs").read_bytes(), b"chunk") def test_rejects_builder_overwrite_and_unsafe_paths_before_writing(self): for name in [ "desktop/node_modules/electron-builder/cli.js", "desktop/package.json", "server/dist/../../desktop/package.json", "../package.json", "/server/dist/absolute", "server/dist/./alias", "server/dist//alias", "server/dist/back\\slash", "server/dist/file:stream", "server/dist/BIN.MJS", ]: with self.subTest(name=name): self.bundle([(name, b"untrusted")]) with self.assertRaises(ValueError): self.stage() self.assertFalse(self.destination.exists()) def test_rejects_links_and_special_files(self): for mode in [stat.S_IFLNK, stat.S_IFIFO, stat.S_IFCHR]: with self.subTest(mode=mode): entry = zipfile.ZipInfo("server/dist/link") entry.create_system = 3 entry.external_attr = (mode | 0o777) << 16 self.bundle([(entry, b"../../../desktop/node_modules")]) with self.assertRaises(ValueError): self.stage() self.assertFalse(self.destination.exists()) def test_requires_entry_points(self): self.bundle(missing="desktop/dist-electron/main.cjs") with self.assertRaises(ValueError): self.stage() self.assertFalse(self.destination.exists()) def test_bounds_archive_size_expanded_size_and_entry_count(self): for limit in ["MAX_ARCHIVE_BYTES", "MAX_EXPANDED_BYTES", "MAX_ENTRIES"]: with self.subTest(limit=limit), patch.object(staging, limit, 1): self.bundle() with self.assertRaises(ValueError): self.stage() self.assertFalse(self.destination.exists()) def test_refuses_existing_destination(self): self.bundle() self.destination.mkdir() sentinel = self.destination / "trusted" sentinel.write_text("untouched") with self.assertRaises(FileExistsError): self.stage() self.assertEqual(sentinel.read_text(), "untouched") if __name__ == "__main__": unittest.main() |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |