Files
WoW-Hybrid-gateway/tests/launcher_account_switch_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

112 lines
7.9 KiB
Python

#!/usr/bin/env python3
"""Two manual presses only; mocked original-entry/native acknowledgments."""
import copy,io,json,sys,tempfile,unittest,importlib.util,os
from pathlib import Path
from types import SimpleNamespace
from unittest.mock import patch
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
import forever_launcher_backend as b
import native_manual_login as manual
class Controller:
def __init__(self):self.calls=[];self.refuse=False;self.finalize_bad=False
def rpc(self,operation,**kw):
self.calls.append(operation)
if operation=='inspect-wire-account':return dict(state=4,error=0,auth_result=0,discovery_result=0,transport_result=0)
if operation=='observe-original-relogin-intent':return 'armed'
if operation=='request-native-session-retirement':return dict(expected_credentials_generation=1,owner=99)
if operation=='inspect-native-session-retirement':return dict(state=3 if self.refuse else 2,result=-1 if self.refuse else 0,completed_credentials_generation=1,next_credentials_generation=2,owner=99)
if operation=='finalize-native-session-retirement':return dict(state=2,result=0,completed_credentials_generation=1,next_credentials_generation=2,owner=99,ready_for_fresh_original_login=not self.finalize_bad)
raise AssertionError(operation)
def wait(self,predicate,_):
result=predicate()
if not result:raise RuntimeError('fixture timeout')
return result
class Switch(unittest.TestCase):
def setUp(self):
self.tmp=tempfile.TemporaryDirectory();self.root=Path(self.tmp.name);(self.root/'runtime').mkdir(mode=0o700);self.c=Controller();self.events=[]
self.trace=dict(status='real-callback-observed-only',hardware_registers_restored=True,metadata=dict(kind='fresh-observed-original-login-intent',credential_bytes_read=False,credential_descriptors_read=False,authentication_attempted=False,native_state_written=False))
self.read_count=0
def trace(*_):
self.read_count+=1
return dict(status='hardware-breakpoint-armed')if self.read_count==1 else self.trace
self.patches=[patch.object(b,'ROOT',self.root),patch.object(manual,'read_trace',side_effect=trace),patch.object(b,'emit',side_effect=lambda phase,message,**kw:self.events.append((phase,message,kw)))]
for p in self.patches:p.start()
def tearDown(self):
for p in reversed(self.patches):p.stop()
self.tmp.cleanup()
def run_switch(self):return b.retire_for_manual_login(SimpleNamespace(endpoint_profile='local-explicit'),123,self.c,dict(closed=1,error=15,world_auth=0,world=dict(login_sent=1,self_create=True)))
def test_real_ack_only_returns_new_generation_no_auth(self):
self.assertEqual(self.run_switch(),2)
self.assertEqual(self.c.calls,['inspect-wire-account','inspect-wire-account','observe-original-relogin-intent','request-native-session-retirement','inspect-native-session-retirement','finalize-native-session-retirement'])
saved=json.loads(next((self.root/'runtime').glob('closed-account-generation-*.json')).read_text());self.assertEqual(saved['previous']['pipe']['error'],15)
self.assertFalse(saved['automatic_authentication_attempted'])
self.assertEqual(self.events[0][2]['manual_login_stage'],'switch-intent')
def test_missing_restoration_never_requests_reset(self):
self.trace['hardware_registers_restored']=False
self.assertRaises(ValueError,self.run_switch);self.assertNotIn('request-native-session-retirement',self.c.calls)
def test_observation_with_input_read_never_requests_reset(self):
self.trace['metadata']['credential_bytes_read']=True
self.assertRaises(ValueError,self.run_switch);self.assertNotIn('request-native-session-retirement',self.c.calls)
def test_native_refusal_never_arms_fresh_capture(self):
self.c.refuse=True;self.assertRaises(ValueError,self.run_switch);self.assertNotIn('finalize-native-session-retirement',self.c.calls)
def test_failed_finalize_cannot_claim_ready(self):
self.c.finalize_bad=True;self.assertRaises(ValueError,self.run_switch)
self.assertFalse(any(e[2].get('manual_login_stage')=='switch-capture'for e in self.events))
def test_second_ready_message_requires_actually_armed_report(self):
report=dict(phase='awaiting-user-login',authentication_armed=True,retirement_generation=2)
log=b.StatusLog(io.StringIO(),report);log.write('Original Login is armed for local-explicit. Enter your account and password yourself in the existing game form, then press Enter once. No automatic submission or retry.\n')
self.assertEqual(self.events[-1][2]['manual_login_stage'],'switch-capture');self.assertIn('Re-enter',self.events[-1][1])
class Frontend(unittest.TestCase):
def setUp(self):
root=Path(__file__).resolve().parents[1]
spec=importlib.util.spec_from_file_location('switch_frontend',root/'launcher/launcher.py');self.ui=importlib.util.module_from_spec(spec);spec.loader.exec_module(self.ui)
def test_stages_are_bounded_and_login_only(self):
base=dict(schema=1,phase='login',message='bounded')
for stage in ('switch-intent','switch-capture'):
self.assertIsNotNone(self.ui.public_event(json.dumps(dict(base,manual_login_stage=stage))))
for change in ({'manual_login_stage':'arbitrary'},{'manual_login_stage':'switch-intent','phase':'world'}):
self.assertIsNone(self.ui.public_event(json.dumps(dict(base,**change))))
def test_two_dialogs_have_distinct_fixed_instructions(self):
with patch.dict(os.environ,DISPLAY=':fixture'),patch.object(self.ui.shutil,'which',return_value='/fixture/kdialog'):
panel=self.ui.LoginReadinessPanel()
with patch.object(self.ui.subprocess,'Popen')as spawn:
spawn.return_value.poll.return_value=0
panel.update(dict(phase='login',message='untrustedignored',manual_login_stage='switch-intent'))
first=spawn.call_args.args[0][4]
panel.update(dict(phase='login',message='untrustedignored',manual_login_stage='switch-capture'))
second=spawn.call_args.args[0][4]
self.assertEqual(spawn.call_count,2);self.assertIn('first press',first);self.assertIn('Previous session cleared',second)
self.assertNotIn('untrustedignored',first+second);self.assertIn('clears the password',first);self.assertIn('Re-enter',second)
def test_packaging_closure_includes_new_helpers(self):
import linux_client_package
closure=linux_client_package.ops_closure(Path(__file__).resolve().parents[1])
self.assertIn('ops/engine_session_retirement.py',closure);self.assertIn('ops/launcher_account_generation.py',closure)
class FreshRoster(unittest.TestCase):
def check(self,fresh):
from native_manual_login_test import FakeController,account,realm
c=FakeController();c.account=account(realm(),prepared=True);c.consumer=True
original=c.rpc;clock=[0.0];opened=[False]
def rpc(operation,**kw):
value=original(operation,**kw)
if operation=='inspect-engine-session':
value['netclient']['packet_host']=dict(received=101 if fresh and opened[0]else 100,opcode='0x5e0003')
return value
c.rpc=rpc;action=c.action
def opened_action(operation):
result=action(operation)
if operation=='open-native-engine-realm-with-pipe':opened[0]=True
return result
c.action=opened_action
report=dict(retirement_generation=2)
popup=SimpleNamespace(try_ack=lambda *_:dict(in_memory_capture_obtained=False),retire_world=lambda:None)
with patch.object(manual,'binding_for'),patch.object(manual,'BootstrapPopupAck',return_value=popup),patch.object(manual.time,'monotonic',side_effect=lambda:clock[0]),patch.object(manual.time,'sleep',side_effect=lambda n:clock.__setitem__(0,clock[0]+n)):
result=manual.character_selection(c,123,c.account,'local-explicit',report,observe_ui=False,readiness_timeout=1)
return result,report
def test_old_true_marker_and_counter_never_claim_new_roster(self):
result,report=self.check(False);self.assertEqual(result,2);self.assertFalse(report['authenticated_character_roster_available'])
def test_new_original_roster_dispatch_allows_real_source_roster(self):
result,report=self.check(True);self.assertEqual(result,0);self.assertTrue(report['authenticated_character_roster_available']);self.assertFalse(report['actual_character_selection_verified'])
if __name__=='__main__':unittest.main()