OpenBao opens the login with cmd.exe /c start, so the xdg-open launcher never ran. The attended PATH now supplies cmd.exe for that one allowlisted URL and opens it in the empty Playwright Chromium profile. Assistant: grok Assistant-Session: 01a198fa-fd27-7e41-a0a2-57355c3e4efd
48 lines
2.9 KiB
Python
48 lines
2.9 KiB
Python
import runpy
|
|
from pathlib import Path
|
|
import unittest
|
|
from urllib.parse import urlencode
|
|
launcher=runpy.run_path(str(Path(__file__).resolve().parents[1]/'scripts/operator-browser/xdg-open'))
|
|
allowed=launcher['allowed']
|
|
launch_argv=launcher['launch_argv']
|
|
class BrowserBoundary(unittest.TestCase):
|
|
def test_approved_flow(self):
|
|
self.assertTrue(allowed('https://kc.coulomb.social/authorize?'+urlencode({'redirect_uri':'http://localhost:8250/oidc/callback','state':'test'})))
|
|
def test_other_destination_rejected(self):
|
|
for host in ['evil.example','kc.coulomb.social.evil.example','user@kc.coulomb.social']:
|
|
self.assertFalse(allowed('https://'+host+'/?'+urlencode({'redirect_uri':'http://localhost:8250/oidc/callback'})))
|
|
def test_unapproved_callback_rejected(self):
|
|
self.assertFalse(allowed('https://kc.coulomb.social/?'+urlencode({'redirect_uri':'https://evil.example'})))
|
|
def test_duplicate_callback_rejected(self):
|
|
self.assertFalse(allowed('https://kc.coulomb.social/?redirect_uri=http://localhost:8250/oidc/callback&redirect_uri=https://evil.example'))
|
|
def test_launch_uses_empty_profile(self):
|
|
url='https://kc.coulomb.social/authorize?'+urlencode({'redirect_uri':'http://localhost:8250/oidc/callback'})
|
|
browser='/cache/ms-playwright/chromium-1234/chrome-linux64/chrome'
|
|
argv=launch_argv(browser, '/tmp/fresh-profile', url)
|
|
self.assertEqual(argv[0], browser)
|
|
self.assertIn('--user-data-dir=/tmp/fresh-profile', argv)
|
|
self.assertEqual(argv[-1], url)
|
|
self.assertNotIn('--headless', argv)
|
|
joined=' '.join(argv)
|
|
for banned in ('explorer.exe', 'powershell', 'msedge', 'firefox', '/mnt/c/'):
|
|
self.assertNotIn(banned, joined)
|
|
def test_chromium_comes_from_the_playwright_pin(self):
|
|
import json
|
|
import tempfile
|
|
from pathlib import Path
|
|
with tempfile.TemporaryDirectory() as raw:
|
|
root=Path(raw)
|
|
spec=root/'browsers.json'
|
|
spec.write_text(json.dumps({'browsers':[{'name':'chromium','revision':'1234'},{'name':'firefox','revision':'1538'}]}))
|
|
binary=root/'chromium-1234'/'chrome-linux64'/'chrome'
|
|
binary.parent.mkdir(parents=True)
|
|
binary.write_text('')
|
|
binary.chmod(0o755)
|
|
self.assertEqual(launcher['chromium_executable'](spec, root), str(binary))
|
|
self.assertEqual(launcher['chromium_executable'](root/'missing.json', root), '')
|
|
def test_wsl_cmd_start_is_the_login_opener(self):
|
|
url='https://kc.coulomb.social/authorize?'+urlencode({'redirect_uri':'http://127.0.0.1:8250/oidc/callback','state':'test'})
|
|
escaped=url.replace('&','^&')
|
|
self.assertEqual(launcher['classify_cmd'](['/c','start',escaped]), ('open', url))
|
|
self.assertEqual(launcher['classify_cmd'](['/c','start','https://evil.example/']), ('reject', ''))
|
|
self.assertEqual(launcher['classify_cmd'](['/c','dir']), ('delegate', ''))
|