883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
25 lines
1.7 KiB
Python
25 lines
1.7 KiB
Python
"""Actual C++ request/output guards; no storage or client is opened by these cases."""
|
|
from pathlib import Path
|
|
import subprocess,tempfile,unittest
|
|
BINARY=Path(__file__).resolve().parents[1]/'build/casc-content-key-batch'
|
|
@unittest.skipUnless(BINARY.is_file(),'Build the existing CascLib content-key tool with batch support first')
|
|
class BatchGuardTest(unittest.TestCase):
|
|
def run_rejected(self,request,expected,*,existing=False):
|
|
with tempfile.TemporaryDirectory()as directory:
|
|
root=Path(directory);requests=root/'requests.txt';requests.write_text(request);out=root/'out';out.mkdir()
|
|
sentinel=out/('a'*32+'.bin')
|
|
if existing:sentinel.write_bytes(b'preserve')
|
|
result=subprocess.run([str(BINARY),'--export-ckeys','/nonexistent-storage-must-not-open',str(requests),str(out)],capture_output=True,text=True)
|
|
self.assertNotEqual(result.returncode,0);self.assertIn(expected,result.stderr)
|
|
self.assertNotIn('Cannot open local CASC storage',result.stderr)
|
|
if existing:self.assertEqual(sentinel.read_bytes(),b'preserve')
|
|
else:self.assertEqual(list(out.iterdir()),[])
|
|
def test_invalid_and_duplicate_keys_or_sizes_reject_before_storage(self):
|
|
for request in ['a'*31+' 10\n','g'*32+' 10\n','A'*32+' 10\n','a'*32+' 0\n','a'*32+' 67108865\n','a'*32+' 10 extra\n','a'*32+' 10\n'+'a'*32+' 10\n']:
|
|
with self.subTest(request=request):self.run_rejected(request,'required'if request.startswith(('g','A'))else'Invalid/duplicate')
|
|
def test_existing_payload_is_preserved_before_storage(self):
|
|
self.run_rejected('a'*32+' 10\n','Existing content output preserved',existing=True)
|
|
def test_request_count_and_bytes_remain_bounded(self):
|
|
self.run_rejected(('a'*32+' 1\n')*12000,'request byte bound')
|
|
if __name__=='__main__':unittest.main()
|