883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
137 lines
6.3 KiB
Python
137 lines
6.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Resume a genuine pending realm choice without a second login submission."""
|
|
import importlib.util
|
|
import io
|
|
import json
|
|
import sys
|
|
import tempfile
|
|
import types
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import Mock, patch
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / 'ops'))
|
|
import launcher_trace_journal as journal_module
|
|
import native_client_lifecycle as lifecycle
|
|
import native_engine_character_test as engine_test
|
|
import native_manual_login as manual
|
|
|
|
spec = importlib.util.spec_from_file_location('pending_realm_backend', ROOT / 'ops/forever_launcher_backend.py')
|
|
backend = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(backend)
|
|
|
|
|
|
class PendingRealmResume(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(self.tmp.cleanup)
|
|
self.root = Path(self.tmp.name)
|
|
(self.root / 'runtime').mkdir()
|
|
self.pid = 987654321
|
|
(self.root / 'runtime/native-client.pid').write_text(str(self.pid))
|
|
(self.root / 'runtime/engine-poll-binding.json').write_text(json.dumps({
|
|
'pid': self.pid, 'endpoint_profile': 'local-explicit', 'restored': False,
|
|
}))
|
|
self.args = types.SimpleNamespace(existing_client_pid=self.pid,
|
|
endpoint_profile='local-explicit', character_guid=None)
|
|
self.pending = dict(state=5, server_proof_verified=1, auth_result=0,
|
|
discovery_result=0, error=0, auth_port=3724, realm_count=1,
|
|
realms=[dict(index=0, flags=0, address='127.0.0.1:8090')],
|
|
selected_index=-1, transport_prepared=0,
|
|
source_ui=dict(available=True, enabled=True))
|
|
self.ready = dict(self.pending, state=2, selected_index=0, transport_prepared=1)
|
|
self.controller = Mock()
|
|
self.controller.rpc.return_value = self.pending
|
|
self.journal = Mock()
|
|
real_path = type(Path())
|
|
pid = self.pid
|
|
class NoProcPath(real_path):
|
|
def exists(path):
|
|
if str(path) == '/proc/' + str(pid):
|
|
return False
|
|
return super().exists()
|
|
self.stack = [
|
|
patch.object(backend, 'ROOT', self.root),
|
|
patch.object(backend, 'Path', NoProcPath),
|
|
patch.object(backend, 'emit'),
|
|
patch.object(backend, 'finish_native_client', return_value=0),
|
|
patch.object(backend, 'remember_verified_realm', return_value=False),
|
|
patch.object(engine_test, 'Controller', return_value=self.controller),
|
|
patch.object(lifecycle, 'read_launch', return_value={'pid': self.pid}),
|
|
patch.object(manual, 'binding_for'),
|
|
patch.object(journal_module.TraceJournal, 'from_release', return_value=self.journal),
|
|
]
|
|
for item in self.stack:
|
|
item.start()
|
|
self.addCleanup(item.stop)
|
|
|
|
def test_existing_genuine_pending_realm_resumes_without_login(self):
|
|
def selected(controller, pid, account, profile, report, **kwargs):
|
|
self.assertEqual(account, self.ready)
|
|
report['authenticated_character_roster_available'] = True
|
|
return 0
|
|
with patch.object(backend, 'wait_native_ui_realm', return_value=self.ready) as wait, \
|
|
patch.object(manual, 'character_selection', side_effect=selected) as characters, \
|
|
patch.object(manual, 'run') as login:
|
|
self.assertEqual(backend.supervise(self.args, io.StringIO()), 0)
|
|
wait.assert_called_once_with(self.controller, self.pending, 'local-explicit')
|
|
characters.assert_called_once()
|
|
login.assert_not_called()
|
|
|
|
def test_pending_realm_without_server_proof_is_not_resumed(self):
|
|
self.pending['server_proof_verified'] = 0
|
|
with patch.object(backend, 'wait_native_ui_realm') as wait, \
|
|
patch.object(manual, 'run') as login:
|
|
with self.assertRaises(ValueError):
|
|
backend.supervise(self.args, io.StringIO())
|
|
wait.assert_not_called()
|
|
login.assert_not_called()
|
|
|
|
def test_pending_realm_without_native_ui_uses_existing_selector(self):
|
|
self.pending['source_ui'] = dict(available=False, enabled=False)
|
|
self.controller.wait.return_value = self.ready
|
|
def selected(controller, pid, account, profile, report, **kwargs):
|
|
report['authenticated_character_roster_available'] = True
|
|
return 0
|
|
with patch.object(backend, 'select_pending_realm', return_value=0) as choose, \
|
|
patch.object(manual, 'character_selection', side_effect=selected), \
|
|
patch.object(manual, 'run') as login:
|
|
self.assertEqual(backend.supervise(self.args, io.StringIO()), 0)
|
|
choose.assert_called_once_with(self.controller, self.pending, 'local-explicit')
|
|
login.assert_not_called()
|
|
|
|
def test_existing_prepared_realm_does_not_repeat_login(self):
|
|
self.controller.rpc.return_value = self.ready
|
|
with patch.object(manual, 'require_realm') as validate, \
|
|
patch.object(manual, 'character_selection') as characters, \
|
|
patch.object(manual, 'run') as login:
|
|
self.assertEqual(backend.supervise(self.args, io.StringIO()), 0)
|
|
validate.assert_called_once_with(self.ready, 0, 'local-explicit')
|
|
characters.assert_not_called()
|
|
login.assert_not_called()
|
|
|
|
def test_existing_idle_binding_resumes_armed_observer_without_rearming(self):
|
|
self.controller.rpc.return_value = dict(state=0)
|
|
def observe(args, report):
|
|
self.assertTrue(args.resume_armed)
|
|
self.assertFalse(args.arm)
|
|
report['authenticated_character_roster_available'] = True
|
|
report['account'] = self.ready
|
|
return 0
|
|
with patch.object(manual, 'run', side_effect=observe) as login, \
|
|
patch.object(backend.threading, 'Thread'):
|
|
self.assertEqual(backend.supervise(self.args, io.StringIO()), 0)
|
|
login.assert_called_once()
|
|
|
|
def test_inflight_authentication_is_not_rearmed(self):
|
|
self.controller.rpc.return_value = dict(self.pending, state=1, server_proof_verified=0)
|
|
with patch.object(manual, 'run') as login:
|
|
with self.assertRaises(ValueError):
|
|
backend.supervise(self.args, io.StringIO())
|
|
login.assert_not_called()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|