Skip to content

Commit e37e84a

Browse files
fix(windows): apply protocol permissions to brave profile and dump Player.log
1 parent 7e9c683 commit e37e84a

2 files changed

Lines changed: 68 additions & 19 deletions

File tree

sample/Tests/test/test_windows.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from alttester import *
1313

1414
from test import TestConfig, UnityTest
15-
from test_windows_helpers import login, open_sample_app, launch_browser, bring_sample_app_to_foreground, stop_browser, stop_sample_app, logout_with_controlled_browser
15+
from test_windows_helpers import login, open_sample_app, launch_browser, bring_sample_app_to_foreground, stop_browser, stop_sample_app, logout_with_controlled_browser, get_product_name
1616

1717
class WindowsTest(UnityTest):
1818

@@ -127,6 +127,30 @@ def _perform_login(self):
127127
print("[SUCCESS] Login successful")
128128

129129
except Exception as err:
130+
# Dump Player.log tail to help diagnose why the deep-link callback
131+
# wasn't processed (or why Unity failed after receiving it).
132+
try:
133+
import os
134+
product_name = os.getenv("UNITY_APP_NAME", get_product_name())
135+
log_path = os.path.join(
136+
"C:\\Users\\WindowsBuildsdkServi\\AppData\\LocalLow\\Immutable",
137+
product_name,
138+
"Player.log",
139+
)
140+
print(f"Attempting to dump Unity Player.log tail: {log_path}")
141+
if os.path.exists(log_path):
142+
with open(log_path, "r", encoding="utf-8", errors="ignore") as f:
143+
lines = f.read().splitlines()
144+
tail = lines[-250:] if len(lines) > 250 else lines
145+
print("----- Player.log (tail) -----")
146+
for line in tail:
147+
print(line)
148+
print("----- end Player.log (tail) -----")
149+
else:
150+
print("Player.log not found.")
151+
except Exception as e:
152+
print(f"Failed to dump Player.log: {e}")
153+
130154
stop_browser()
131155
raise SystemExit(f"Login failed: {err}")
132156

sample/Tests/test/test_windows_helpers.py

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -660,10 +660,27 @@ def login():
660660

661661
# The "open external protocol" prompt is typically browser UI (not DOM),
662662
# so 0 buttons on /checking is expected. Try:
663+
# - wait for /checking to transition (some runs redirect after a few seconds)
663664
# - wait briefly for Unity success (maybe protocol already fired)
664665
# - click the browser-level prompt via UIAutomation
665666
# - wait again for Unity success
666667
if "auth.immutable.com/checking" in current_url_lower:
668+
# Monitor for URL transitions for ~30 seconds.
669+
for _ in range(15):
670+
time.sleep(2)
671+
try:
672+
current = driver.current_url or ""
673+
print(f"/checking monitor - current URL: {current}")
674+
lower = current.lower()
675+
if "newtab" in lower or "about:blank" in lower:
676+
print("Detected newtab/about:blank; assuming external protocol launch was attempted.")
677+
wait_for_authentication_success_in_unity_logs(timeout_seconds=75)
678+
return
679+
if "auth.immutable.com/checking" not in lower:
680+
break
681+
except Exception:
682+
pass
683+
667684
if wait_for_authentication_success_in_unity_logs(timeout_seconds=10):
668685
return
669686

@@ -810,14 +827,11 @@ def bring_sample_app_to_foreground():
810827
subprocess.run(command, check=True)
811828
time.sleep(10)
812829

813-
def setup_browser_permissions():
814-
"""Set up browser permissions to allow auth.immutable.com to open external applications"""
830+
def setup_browser_permissions(user_data_dir: str):
831+
"""Set up browser profile permissions to allow auth.immutable.com to open external applications."""
815832
print("Setting up browser permissions for auth.immutable.com...")
816-
817-
# Create a browser preferences file to pre-allow the domain
818-
user_data_dir = "C:\\temp\\brave_debug"
819-
if not os.path.exists(user_data_dir):
820-
os.makedirs(user_data_dir, exist_ok=True)
833+
print(f"Using browser profile dir: {user_data_dir}")
834+
os.makedirs(user_data_dir, exist_ok=True)
821835

822836
# Create preferences file that allows auth.immutable.com to open external apps
823837
preferences = {
@@ -864,16 +878,27 @@ def setup_autolaunch_protocol_policy():
864878
# This must be REG_SZ containing JSON.
865879
# Protocol must be lowercase and WITHOUT ':' (e.g. "immutablerunner", not "immutablerunner:").
866880
policy_json = (
867-
'[{"protocol":"immutablerunner","allowed_origins":["https://auth.immutable.com"]}]'
881+
'[{"protocol":"immutablerunner","allowed_origins":["https://auth.immutable.com","https://auth.immutable.com:443"]}]'
868882
)
869883

870884
ps_script = f'''
871-
$key = "HKCU:\\Software\\Policies\\BraveSoftware\\Brave"
872-
if (!(Test-Path $key)) {{
873-
New-Item -Path $key -Force | Out-Null
885+
$json = '{policy_json}'
886+
$paths = @(
887+
"HKCU:\\Software\\Policies\\BraveSoftware\\Brave",
888+
"HKLM:\\Software\\Policies\\BraveSoftware\\Brave"
889+
)
890+
891+
foreach ($key in $paths) {{
892+
try {{
893+
if (!(Test-Path $key)) {{
894+
New-Item -Path $key -Force | Out-Null
895+
}}
896+
New-ItemProperty -Path $key -Name "AutoLaunchProtocolsFromOrigins" -PropertyType String -Value $json -Force | Out-Null
897+
Write-Host "Brave policy AutoLaunchProtocolsFromOrigins set at $key."
898+
}} catch {{
899+
Write-Host "Failed to set policy at $key: $($_.Exception.Message)"
900+
}}
874901
}}
875-
New-ItemProperty -Path $key -Name "AutoLaunchProtocolsFromOrigins" -PropertyType String -Value '{policy_json}' -Force | Out-Null
876-
Write-Host "Brave policy AutoLaunchProtocolsFromOrigins set."
877902
'''
878903

879904
try:
@@ -956,11 +981,6 @@ def setup_protocol_association():
956981
def launch_browser():
957982
print("Starting Brave...")
958983

959-
# Set up browser permissions and protocol association first
960-
setup_browser_permissions()
961-
setup_protocol_association()
962-
setup_autolaunch_protocol_policy()
963-
964984
browser_paths = [
965985
r"C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe"
966986
]
@@ -978,6 +998,11 @@ def launch_browser():
978998
# Create a temporary directory for browser data to ensure clean state
979999
import tempfile
9801000
temp_user_data = tempfile.mkdtemp(prefix='brave_test_')
1001+
1002+
# IMPORTANT: apply permissions to the SAME profile we launch with.
1003+
setup_browser_permissions(user_data_dir=temp_user_data)
1004+
setup_protocol_association()
1005+
setup_autolaunch_protocol_policy()
9811006

9821007
# Launch Brave with CI-friendly flags to handle protocol dialogs automatically
9831008
browser_args = [

0 commit comments

Comments
 (0)