mirror of
https://github.com/gadgethd/ukmesh.git
synced 2026-12-06 11:14:26 +00:00
50 lines
2.8 KiB
Python
50 lines
2.8 KiB
Python
"""The mixed verifier can only run a previously built, exact artifact."""
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
import mixed_client
|
|
from common import command, digest, write_json
|
|
|
|
|
|
class CompiledClientTests(unittest.TestCase):
|
|
@unittest.skipUnless((mixed_client.REPO / 'backend/node_modules/.bin/tsc').is_file(),
|
|
'the compiled-entrypoint test uses the installed backend compiler')
|
|
def test_real_compiled_entrypoint_reaches_the_loopback_guard_without_loader(self):
|
|
with tempfile.TemporaryDirectory(prefix='.soak-client-', dir=mixed_client.REPO / 'backend') as build, \
|
|
tempfile.TemporaryDirectory() as run:
|
|
entry = mixed_client.compile_client(Path(build), Path(run))
|
|
self.assertEqual(mixed_client.verify_client(entry, Path(run)), digest(entry))
|
|
result = command(['node', str(entry)], check=False,
|
|
environment_overrides={'DATABASE_URL': 'postgresql://fixture@remote.invalid/fixture'})
|
|
self.assertEqual(result.returncode, 1)
|
|
self.assertIn(b'sample tools require an explicit loopback', result.stderr)
|
|
|
|
def test_manifest_binds_entrypoint_helpers_sources_and_locked_dependencies(self):
|
|
with tempfile.TemporaryDirectory() as temp, patch.object(mixed_client, 'REPO', Path(temp)):
|
|
root = Path(temp)
|
|
build = root / 'backend/.soak-client-owned123'
|
|
entry = build / 'tools/soakDatabaseLookups.js'
|
|
source = root / 'backend/src/tools/soakDatabaseLookups.ts'
|
|
lock = root / 'backend/package-lock.json'
|
|
helper = entry.parent / 'soakSocket.js'
|
|
for file in (entry, source, lock, helper):
|
|
file.parent.mkdir(parents=True, exist_ok=True)
|
|
file.write_text('fixture ' + file.name)
|
|
write_json(root / 'mixed-client-build.json', {
|
|
'files': mixed_client.output_digests(build), 'executableSha256': digest(entry),
|
|
'sourceSha256': digest(source), 'lockSha256': digest(lock)})
|
|
self.assertEqual(mixed_client.verify_client(entry, root), digest(entry))
|
|
for file in (entry, helper, source, lock):
|
|
with self.subTest(file=file.name):
|
|
before = file.read_bytes()
|
|
file.write_bytes(before + b'changed')
|
|
with self.assertRaises(ValueError):
|
|
mixed_client.verify_client(entry, root)
|
|
file.write_bytes(before)
|
|
for path in (root / 'backend/dist/tools/soakDatabaseLookups.js',
|
|
Path('/tools/soakDatabaseLookups.js'),
|
|
build / 'tools/fullStackTraffic.js'):
|
|
self.assertFalse(mixed_client.compiled_entry(path))
|