Files
WoW-Hybrid-gateway/tests/engine_account_credentials_test.py
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

93 lines
4.2 KiB
Python

#!/usr/bin/env python3
"""Mock-only inspection proves the one-shot credential payload stays unread."""
from pathlib import Path
import struct
import sys
import unittest
from unittest.mock import patch
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
import engine_wire_host as wire
BASE=0x100000
ACCOUNT=BASE+0x2000
CREDENTIALS=BASE+0x4000
class PublicMemory:
def __init__(self,header,split=False):
self.header=header
self.account=struct.pack('<II13iII',1,1732,*([0]*13),3724,120000)
self.reads=[]
self.closed=False
self.maps=[(ACCOUNT,ACCOUNT+68,'r--p','00000000','mock')]
ends=(CREDENTIALS+12,CREDENTIALS+32) if split else (CREDENTIALS+32,)
low=CREDENTIALS
for high in ends:
self.maps.append((low,high,'r--p','00000000','mock'))
low=high
def read(self,address,size):
self.reads.append((address,size))
if address<CREDENTIALS+132 and address+size>CREDENTIALS+32:
raise AssertionError('Diagnostic attempted to read secret credential payload')
if address==ACCOUNT and size==68:return self.account
if CREDENTIALS<=address and address+size<=CREDENTIALS+32:
if not any(low<=address and address+size<=high for low,high,*_ in self.maps):
raise ValueError('Mock read spans adjacent maps')
return self.header[address-CREDENTIALS:address-CREDENTIALS+size]
raise AssertionError('Unexpected memory access')
def close(self):self.closed=True
class CredentialsInspectionTest(unittest.TestCase):
def inspect(self,*,export=True,split=False,**changes):
fields=dict(abi=1,size=132,state=3,generation=7,username_bytes=0,
password_bytes=0,consumed_generation=7,reserved=0)
fields.update(changes)
memory=PublicMemory(struct.pack('<IIi5I',*fields.values()),split)
exports={'gw_wire_auth_data':ACCOUNT-BASE}
if export:exports['gw_wire_auth_credentials_data']=CREDENTIALS-BASE
try:
with patch.object(wire.host,'Access',return_value=memory),patch.object(wire,'module',return_value=(BASE,dict(exports=exports),{})):
result=wire.inspect_account(123)
finally:
self.assertTrue(memory.closed)
self.assertTrue(all(not(CREDENTIALS<=address<CREDENTIALS+132) or address+size<=CREDENTIALS+32 for address,size in memory.reads))
return result,memory
def test_optional_export_absent(self):
result,memory=self.inspect(export=False)
self.assertNotIn('memory_credentials',result)
self.assertEqual(memory.reads,[(ACCOUNT,68)])
def test_public_fields_only(self):
result,memory=self.inspect()
self.assertEqual(result['memory_credentials'],dict(state=3,generation=7,consumed_generation=7,
username_bytes=0,password_bytes=0,secret_payload_read=False))
self.assertEqual(memory.reads,[(ACCOUNT,68),(CREDENTIALS,32)])
self.assertFalse(any('wipe' in key for key in result['memory_credentials']))
def test_all_published_states_and_length_boundaries(self):
for state in range(-1,4):
with self.subTest(state=state):
result,_=self.inspect(state=state,username_bytes=32,password_bytes=64)
self.assertEqual(result['memory_credentials']['state'],state)
self.assertFalse(result['memory_credentials']['secret_payload_read'])
def test_adjacent_public_maps_remain_header_only(self):
result,memory=self.inspect(split=True)
self.assertEqual(result['memory_credentials']['consumed_generation'],7)
self.assertEqual(memory.reads,[(ACCOUNT,68),(CREDENTIALS,32),(CREDENTIALS,12),(CREDENTIALS+12,20)])
def test_invalid_header_rejected_without_payload_read(self):
for changes in (dict(abi=2),dict(size=131),dict(size=133),dict(state=-2),dict(state=4),
dict(username_bytes=33),dict(password_bytes=65),dict(reserved=1)):
with self.subTest(changes=changes):
with self.assertRaisesRegex(ValueError,'Owned memory credential metadata differs'):
self.inspect(**changes)
if __name__=='__main__':unittest.main()