Unauthenticated, on every host: package xyz.gabvdl.aiagent (ANDROID_APP_PACKAGE) and the signing certificates' SHA-256 from ANDROID_APP_FINGERPRINTS; nothing configured answers 404. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
55 lines
2.6 KiB
Python
55 lines
2.6 KiB
Python
"""``GET /.well-known/assetlinks.json`` (core/routes.py, 2026-11-28): the
|
|
Android app's Trusted Web Activity — unauthenticated, on every host, from
|
|
``ANDROID_APP_FINGERPRINTS`` / ``ANDROID_APP_PACKAGE``; nothing set → 404."""
|
|
|
|
import os
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
os.environ.setdefault("INTERNAL_API_TOKEN", "tok")
|
|
os.environ.setdefault("GUEST_HOSTS", "guest.example.test")
|
|
os.environ.setdefault("OWNER_HOSTS", "hub.example.test")
|
|
|
|
from fastapi.testclient import TestClient # noqa: E402
|
|
|
|
import main # noqa: E402
|
|
from core import routes as core_routes # noqa: E402
|
|
|
|
|
|
class TestAssetLinks(unittest.TestCase):
|
|
FP = "AB:" * 31 + "CD"
|
|
|
|
def setUp(self):
|
|
self.tc = TestClient(main.app)
|
|
|
|
def test_nothing_configured_is_a_404(self):
|
|
with patch.dict(os.environ, {"ANDROID_APP_FINGERPRINTS": ""}):
|
|
self.assertEqual(self.tc.get("/.well-known/assetlinks.json").status_code, 404)
|
|
with patch.dict(os.environ, {"ANDROID_APP_FINGERPRINTS": "not-a-fingerprint, AB:CD"}):
|
|
self.assertEqual(self.tc.get("/.well-known/assetlinks.json").status_code, 404)
|
|
|
|
def test_the_statement_unauthenticated_on_every_host(self):
|
|
raw = self.FP.replace(":", "").lower() # bare hex is accepted too
|
|
with patch.dict(os.environ, {"ANDROID_APP_FINGERPRINTS": f"{self.FP}, {raw}\n" + "11:" * 31 + "22"}):
|
|
for host in ("admin.example.test", "guest.example.test", "hub.example.test"):
|
|
r = self.tc.get("/.well-known/assetlinks.json", headers={"Host": host})
|
|
self.assertEqual(r.status_code, 200, host)
|
|
self.assertEqual(r.headers["content-type"], "application/json")
|
|
self.assertEqual(r.json(), [{
|
|
"relation": ["delegate_permission/common.handle_all_urls"],
|
|
"target": {"namespace": "android_app", "package_name": "xyz.gabvdl.aiagent",
|
|
"sha256_cert_fingerprints": [self.FP, "11:" * 31 + "22"]}}])
|
|
|
|
def test_the_package_comes_from_the_environment(self):
|
|
with patch.dict(os.environ, {"ANDROID_APP_FINGERPRINTS": self.FP,
|
|
"ANDROID_APP_PACKAGE": "xyz.gabvdl.aiagent.debug"}):
|
|
self.assertEqual(core_routes.assetlinks()[0]["target"]["package_name"],
|
|
"xyz.gabvdl.aiagent.debug")
|
|
with patch.dict(os.environ, {"ANDROID_APP_FINGERPRINTS": self.FP,
|
|
"ANDROID_APP_PACKAGE": "bad package"}):
|
|
self.assertEqual(core_routes.assetlinks(), [])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|