mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 05:46:03 +00:00
Restrict Xbox credential IPC and address launch review findings (#1164)
* Restrict Xbox credentials to host backends and lease game launches * Verify mapped PRoot backend images and retry lease heartbeat timeouts * Bound Xbox backend shutdown and isolate service socket lifetimes * Keep unique Xbox service sockets within Unix address limits * Own licensed launch directories and recover abandoned views safely * Serialize Xbox account revocation with sign-in commits and launch authorization
This commit is contained in:
1 parent
f5bba17f53
commit
6bbcf3ad8b
27 files changed
+834
-85
No files matched your search
@@ -19,6 +19,64 @@ class XboxLaunchTest(unittest.TestCase):
|
||||
(folder / '.droiddeck-store.json').write_text(json.dumps({'store': 'gog', 'id': '1'}))
|
||||
self.assertIsNone(xbox['launch'](['/proton', 'waitforexitandrun', str(folder / 'Game.exe')], {}))
|
||||
|
||||
def test_renewal_retries_a_timeout_and_stops_after_rejection(self):
|
||||
stopped = unittest.mock.Mock()
|
||||
stopped.wait.side_effect = [False, False, False, AssertionError('renewed a rejected lease')]
|
||||
ask = unittest.mock.Mock(side_effect=[None, {'ok': True}, {'ok': False}])
|
||||
xbox['renew_lease'](ask, Path('/channel'), 'GAME', 'lease-1', stopped)
|
||||
self.assertEqual(ask.call_count, 3)
|
||||
|
||||
def test_stopping_a_launch_stops_renewal_without_another_request(self):
|
||||
stopped = threading.Event()
|
||||
stopped.set()
|
||||
ask = unittest.mock.Mock()
|
||||
xbox['renew_lease'](ask, Path('/channel'), 'GAME', 'lease-1', stopped)
|
||||
ask.assert_not_called()
|
||||
|
||||
def test_missing_store_detector_keeps_stock_launch(self):
|
||||
for error in (FileNotFoundError('missing'), RuntimeError('module initialization failed')):
|
||||
with self.subTest(error=error), patch('runpy.run_path', side_effect=error):
|
||||
self.assertIsNone(xbox['launch'](['/proton', 'waitforexitandrun', '/Game.exe'], {}))
|
||||
|
||||
def test_launch_uses_prepared_image_and_never_receives_account_credentials(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
root = Path(root)
|
||||
runtime = root / 'runtime/windows'
|
||||
runtime.mkdir(parents=True)
|
||||
for name in xbox['DLLS']:
|
||||
(runtime / name).write_bytes(b'MZ')
|
||||
store = {'find_store_game': lambda argv: (root, {'store': 'xbox', 'id': 'GAME'}),
|
||||
'ask': unittest.mock.Mock(return_value={'ok': True, 'socket': '/service', 'lease': 'lease-1',
|
||||
'exe': '/private/Game.exe', 'playfab': 'game-token'})}
|
||||
close = unittest.mock.Mock()
|
||||
with patch('runpy.run_path', return_value=store), patch.dict(xbox['launch'].__globals__, RUNTIME=runtime.parent), \
|
||||
patch.dict(xbox['launch'].__globals__, bridge=lambda path: (1234, 'key', close)), \
|
||||
patch.dict(xbox['launch'].__globals__, wine=unittest.mock.Mock(return_value=7)):
|
||||
launch = xbox['launch']
|
||||
self.assertEqual(launch(['/proton', 'waitforexitandrun', '/encrypted/Game.exe'],
|
||||
{'BL_LAUNCH_DIR': '/launch', 'DROIDDECK_XBOX_CREDENTIAL_SOCKET': 'stale'}), 7)
|
||||
wine = launch.__globals__['wine']
|
||||
self.assertEqual(wine.call_args.args[0], ['/private/Game.exe'])
|
||||
env = wine.call_args.args[1]
|
||||
self.assertNotIn('DROIDDECK_XBOX_CREDENTIAL_SOCKET', env)
|
||||
self.assertEqual(env['XODUS_XSTS_PLAYFAB'], 'game-token')
|
||||
close.assert_called_once()
|
||||
self.assertEqual(store['ask'].call_args.args[1], {'op': 'xbox-released', 'lease': 'lease-1'})
|
||||
|
||||
def test_bridge_start_failure_still_releases_the_lease(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
root = Path(root)
|
||||
runtime = root / 'windows'
|
||||
runtime.mkdir()
|
||||
for name in xbox['DLLS']:
|
||||
(runtime / name).touch()
|
||||
ask = unittest.mock.Mock(return_value={'ok': True, 'socket': '/service', 'lease': 'lease-1'})
|
||||
with patch('runpy.run_path', return_value={'find_store_game': lambda argv: (root, {'store': 'xbox', 'id': 'GAME'}), 'ask': ask}), \
|
||||
patch.dict(xbox['launch'].__globals__, RUNTIME=root, bridge=unittest.mock.Mock(side_effect=OSError('bind failed'))):
|
||||
with self.assertRaises(OSError):
|
||||
xbox['launch'](['/proton', 'waitforexitandrun', '/Game.exe'], {'BL_LAUNCH_DIR': '/launch'})
|
||||
self.assertEqual(ask.call_args.args[1], {'op': 'xbox-released', 'lease': 'lease-1'})
|
||||
|
||||
def test_bridge_authenticates_before_forwarding(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
path = str(Path(root) / 'service.sock')
|
||||
|
||||
Reference in new issue
Block a user