Sync shared snapshot from 8bbaf3c
This commit is contained in:
1 parent
346f6f839f
commit
55b224bc48
4 files changed
+33
-7
No files matched your search
@@ -95,6 +95,7 @@ auth_client = AuthClient("") # pending: no URL yet, still safe to use
|
||||
core_config = CoreConfigStore(CoreConfigInfo(auth_guard_url=""))
|
||||
core_config.on_update(lambda info: auth_client.set_base_url(info.auth_guard_url))
|
||||
|
||||
|
||||
# in your framework's route for PUT /api/core-services/internal:
|
||||
async def push_core_services(request):
|
||||
if request.headers.get("X-Internal-Auth") != SECRET:
|
||||
@@ -128,19 +129,27 @@ completed" claim flag, and optionally a "require login" toggle) and calls
|
||||
from shared_backend.authclient import AuthClient
|
||||
from shared_backend.authproxy import ProxyStore, build_auth_router
|
||||
|
||||
|
||||
class MyStore(ProxyStore):
|
||||
async def login_required(self) -> bool: return True
|
||||
async def set_login_required(self, required: bool) -> None: pass
|
||||
async def login_required(self) -> bool:
|
||||
return True
|
||||
|
||||
async def set_login_required(self, required: bool) -> None:
|
||||
pass
|
||||
|
||||
async def is_setup_claimed(self) -> bool: ... # your own table
|
||||
async def try_claim_setup(self) -> bool: ... # your own table
|
||||
async def unclaim_setup(self) -> None: ... # your own table
|
||||
|
||||
|
||||
def get_client(request):
|
||||
return request.app.state.auth_client # AuthClient | None, or None in auth-disabled mode
|
||||
|
||||
|
||||
def get_store(request):
|
||||
return request.app.state.auth_store
|
||||
|
||||
|
||||
app.include_router(
|
||||
build_auth_router(get_client, get_store, legacy_cookie_name="myproject_session"),
|
||||
prefix="/api/auth",
|
||||
|
||||
@@ -574,7 +574,10 @@ def build_auth_router(
|
||||
store: ProxyStore = Depends(get_store), # noqa: B008
|
||||
) -> dict[str, bool]:
|
||||
nonlocal login_required_override
|
||||
if not configured_internal_secret or request.headers.get("X-Internal-Auth") != configured_internal_secret:
|
||||
if (
|
||||
not configured_internal_secret
|
||||
or request.headers.get("X-Internal-Auth") != configured_internal_secret
|
||||
):
|
||||
raise HTTPException(status_code=401, detail="internal service authentication required")
|
||||
await store.set_login_required(req.loginRequired)
|
||||
login_required_override = req.loginRequired
|
||||
|
||||
@@ -123,7 +123,9 @@ class AccessSettingsTests(unittest.TestCase):
|
||||
|
||||
def test_internal_update_disables_login_and_uses_admin_identity(self) -> None:
|
||||
store = _FakeStore(login_required=True)
|
||||
client = TestClient(_build_app(store, _FakeClient(setup_required=False), internal_secret="secret"))
|
||||
client = TestClient(
|
||||
_build_app(store, _FakeClient(setup_required=False), internal_secret="secret")
|
||||
)
|
||||
|
||||
response = client.put(
|
||||
"/api/auth/access/internal",
|
||||
|
||||
@@ -5,7 +5,12 @@ from shared_backend.coreconfig import Info, Store
|
||||
|
||||
class StoreDefaultsTests(unittest.TestCase):
|
||||
def test_seeds_from_fallback(self):
|
||||
store = Store(Info(auth_guard_url="http://auth.example.com", carrier_node_url="http://carrier.example.com"))
|
||||
store = Store(
|
||||
Info(
|
||||
auth_guard_url="http://auth.example.com",
|
||||
carrier_node_url="http://carrier.example.com",
|
||||
)
|
||||
)
|
||||
info = store.get()
|
||||
self.assertEqual(info.auth_guard_url, "http://auth.example.com")
|
||||
self.assertEqual(info.carrier_node_url, "http://carrier.example.com")
|
||||
@@ -20,7 +25,12 @@ class StoreDefaultsTests(unittest.TestCase):
|
||||
|
||||
class StoreSetTests(unittest.TestCase):
|
||||
def test_partial_push_does_not_clobber_other_field(self):
|
||||
store = Store(Info(auth_guard_url="http://auth.example.com", carrier_node_url="http://carrier.example.com"))
|
||||
store = Store(
|
||||
Info(
|
||||
auth_guard_url="http://auth.example.com",
|
||||
carrier_node_url="http://carrier.example.com",
|
||||
)
|
||||
)
|
||||
store.set(Info(carrier_node_url="http://carrier2.example.com"))
|
||||
info = store.get()
|
||||
self.assertEqual(info.auth_guard_url, "http://auth.example.com")
|
||||
@@ -46,7 +56,9 @@ class StoreSetTests(unittest.TestCase):
|
||||
"carrierNodeUrls": ["http://carrier.example.com", "http://carrier2.example.com"],
|
||||
}
|
||||
info = Info.from_json(payload)
|
||||
self.assertEqual(info.carrier_node_urls, ["http://carrier.example.com", "http://carrier2.example.com"])
|
||||
self.assertEqual(
|
||||
info.carrier_node_urls, ["http://carrier.example.com", "http://carrier2.example.com"]
|
||||
)
|
||||
self.assertEqual(info.to_json()["carrierNodeUrl"], "http://carrier.example.com")
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user