|
1 | 1 | #!/usr/bin/env python3 |
2 | | -"""Adversarial inspector-output fixtures; real binary proof runs separately.""" |
| 2 | +"""Make gate and inspector-output fixtures; real binary proof runs separately.""" |
3 | 3 | import os |
4 | 4 | from pathlib import Path |
| 5 | +import shutil |
5 | 6 | import subprocess |
6 | 7 | import tempfile |
7 | 8 | import unittest |
8 | 9 |
|
9 | 10 | SOURCE = Path(__file__).resolve().parent.parent |
10 | 11 |
|
| 12 | +class MakeGateFixtures(unittest.TestCase): |
| 13 | + """Run the production recipe with GNU make and controlled build/inspector outputs.""" |
| 14 | + |
| 15 | + def gate(self, suffix='', mode='no', linker='CXX', dependency=None, |
| 16 | + symbols='', build_fails=False): |
| 17 | + make = shutil.which('gmake') or shutil.which('make') |
| 18 | + self.assertIsNotNone(make, 'GNU make is required for native linkage gate tests') |
| 19 | + recipe = (SOURCE / 'Makefile.am').read_text().split( |
| 20 | + '\ncheck-v3-native-linkage:\n', 1)[1].split('\n\n', 1)[0] |
| 21 | + if dependency is None: |
| 22 | + dependency = 'KERNEL32.dll' if suffix else '/usr/lib/libc++.1.dylib' |
| 23 | + with tempfile.TemporaryDirectory() as directory: |
| 24 | + root = Path(directory).resolve() |
| 25 | + for name in ['src', 'test', 'tools']: |
| 26 | + (root / name).mkdir() |
| 27 | + (root / 'src/Makefile').write_text( |
| 28 | + 'libhttpserver.la:\n' |
| 29 | + f'\tlibtool --tag={linker} --mode=link -o libhttpserver.la archive\n') |
| 30 | + # Like Automake, expose only the configured executable target. |
| 31 | + (root / 'test/Makefile').write_text( |
| 32 | + 'native_linkage$(EXEEXT):\n' |
| 33 | + + ('\t@exit 1\n' if build_fails else |
| 34 | + '\t@mkdir -p .libs ../src/.libs\n' |
| 35 | + '\t@printf "#!/bin/sh\\nexit 0\\n" > .libs/$@\n' |
| 36 | + '\t@chmod +x .libs/$@\n' |
| 37 | + '\t@touch ../src/.libs/libhttpserver_v3core.a\n')) |
| 38 | + inspectors = {'nm': symbols} |
| 39 | + if suffix: |
| 40 | + inspectors.update(uname='MINGW64_NT-10.0', objdump=( |
| 41 | + 'fixture.exe: file format pei-x86-64\n' |
| 42 | + + '\n'.join(' DLL Name: ' + n for n in dependency.splitlines()))) |
| 43 | + else: |
| 44 | + inspectors['otool'] = 'fixture:\n' + dependency |
| 45 | + for name, output in inspectors.items(): |
| 46 | + path = root / 'tools' / name |
| 47 | + path.write_text("#!/bin/sh\ncat <<'OUTPUT'\n" + output + '\nOUTPUT\n') |
| 48 | + path.chmod(0o755) |
| 49 | + env = dict(os.environ, PATH=str(root / 'tools') + os.pathsep + os.environ['PATH']) |
| 50 | + return subprocess.run( |
| 51 | + [make, '--no-print-directory', '-f', '-', 'check-v3-native-linkage', |
| 52 | + 'top_srcdir=' + str(SOURCE), 'top_builddir=' + str(root), |
| 53 | + 'abs_top_builddir=' + str(root), 'EXEEXT=' + suffix, |
| 54 | + 'enable_v3_tls=' + mode], |
| 55 | + input='check-v3-native-linkage:\n' + recipe + '\n', cwd=root, |
| 56 | + env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) |
| 57 | + |
| 58 | + def test_configured_executable_suffix_reaches_real_audit(self): |
| 59 | + for suffix in ['', '.exe']: |
| 60 | + with self.subTest(suffix=suffix): |
| 61 | + result = self.gate(suffix=suffix) |
| 62 | + self.assertEqual(0, result.returncode, result.stdout) |
| 63 | + self.assertIn('A1 PASS', result.stdout) |
| 64 | + self.assertIn('A2 PASS', result.stdout) |
| 65 | + |
| 66 | + def test_configured_tls_mode_reaches_real_audit(self): |
| 67 | + for suffix, dependency in [('', '/tmp/libssl.3.dylib'), ('.exe', 'libssl-3.dll')]: |
| 68 | + for mode in ['yes', 'no']: |
| 69 | + with self.subTest(suffix=suffix, mode=mode): |
| 70 | + result = self.gate(suffix=suffix, dependency=dependency, mode=mode) |
| 71 | + self.assertEqual(mode == 'yes', result.returncode == 0, result.stdout) |
| 72 | + self.assertIn('A2 PASS' if mode == 'yes' else 'TLS-off load dependency', |
| 73 | + result.stdout) |
| 74 | + |
| 75 | + def test_cxx_linker_gate_stops_before_audit(self): |
| 76 | + result = self.gate(linker='CC') |
| 77 | + self.assertNotEqual(0, result.returncode) |
| 78 | + self.assertIn('aggregate must use the C++ linker', result.stdout) |
| 79 | + self.assertNotIn('A1 PASS', result.stdout) |
| 80 | + |
| 81 | + def test_build_failure_stops_before_audit(self): |
| 82 | + result = self.gate(build_fails=True) |
| 83 | + self.assertNotEqual(0, result.returncode) |
| 84 | + self.assertNotIn('A1 PASS', result.stdout) |
| 85 | + |
| 86 | + def test_static_provider_rejection_propagates(self): |
| 87 | + result = self.gate(symbols=' U _SSL_set_quic_tls_cbs') |
| 88 | + self.assertNotEqual(0, result.returncode) |
| 89 | + self.assertIn('A1 PASS', result.stdout) |
| 90 | + self.assertIn('TLS-off provider symbols', result.stdout) |
| 91 | + self.assertNotIn('A2 PASS', result.stdout) |
| 92 | + |
11 | 93 | class AuditFixtures(unittest.TestCase): |
12 | 94 | def audit(self, dependency=None, symbols='', mode='no', binary=True, archive=True, windows=False): |
13 | 95 | if dependency is None: |
|
0 commit comments