Files
s41r4j-cybot/scripts/test_web_profile.py
T
s41r4j 0f03d49514
CI / contracts (push) Canceled after 0s
Website / deploy (push) Canceled after 0s
CI / test (macos-latest) (push) Canceled after 0s
CI / test (ubuntu-24.04) (push) Canceled after 0s
CI / test (ubuntu-24.04-arm) (push) Canceled after 0s
CI / test (windows-latest) (push) Canceled after 0s
CI / Compact real-tool fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Compact real-tool fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Code analysis fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Code analysis fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Web engine fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Web engine fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Chromium operation fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Chromium operation fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / operation-readiness (push) Canceled after 0s
CI / Supply chain fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Supply chain fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
Initial commit
2026-11-01 09:14:18 +05:30

50 lines
2.3 KiB
Python

import hashlib
import io
from pathlib import Path
import tarfile
import tempfile
import unittest
import web_profile
from patched_go_tools import patch_source
class WebProfileTests(unittest.TestCase):
def test_source_extraction_rejects_escape_links_and_duplicates(self):
with tempfile.TemporaryDirectory() as temp:
root = Path(temp)
for name, kind in [('root/../escape', tarfile.REGTYPE), ('../escape', tarfile.REGTYPE), ('root/link', tarfile.SYMTYPE)]:
archive = root/'input.tar'
with tarfile.open(archive, 'w') as output:
member = tarfile.TarInfo(name); member.type = kind
output.addfile(member)
with self.assertRaisesRegex(RuntimeError, 'Unsafe'):
web_profile.extract_source(archive, root/'output')
with tarfile.open(archive, 'w') as output:
for _ in range(2):
member = tarfile.TarInfo('root/fixture'); member.size = 4
output.addfile(member, io.BytesIO(b'test'))
with self.assertRaisesRegex(RuntimeError, 'Duplicate'):
web_profile.extract_source(archive, root/'output')
self.assertFalse((root/'escape').exists())
def test_both_tls_contexts_must_be_patched_exactly(self):
with tempfile.TemporaryDirectory() as temp:
root = Path(temp); source = root/'transport.rb'
original = b'verify_none\nverify_none\n'
spec = {'sha256': hashlib.sha256(original).hexdigest(), 'replacements': [['verify_none', 'verify_peer', 2]]}
source.write_bytes(original)
records = patch_source(root, {'transport.rb': spec})
self.assertEqual(source.read_bytes(), b'verify_peer\nverify_peer\n')
self.assertEqual(records[0]['after_sha256'], hashlib.sha256(source.read_bytes()).hexdigest())
with self.assertRaisesRegex(RuntimeError, 'input changed'):
patch_source(root, {'transport.rb': spec})
source.write_bytes(original)
spec['replacements'][0][2] = 1
with self.assertRaisesRegex(RuntimeError, 'insertion point'):
patch_source(root, {'transport.rb': spec})
self.assertEqual(source.read_bytes(), original)
if __name__ == '__main__': unittest.main()