Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/google/adk/cli/trigger_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ async def __call__(self, request: Request) -> None:
)
if self._allowed_emails:
if (
not claims.get("email_verified")
claims.get("email_verified") is not True
or claims.get("email") not in self._allowed_emails
):
raise HTTPException(
Expand Down
63 changes: 63 additions & 0 deletions tests/unittests/cli/test_trigger_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,69 @@ def _ok(token, request, audience):
)
assert resp.status_code == 403

@pytest.mark.parametrize("endpoint,payload", _TRIGGER_ENDPOINTS_AND_PAYLOADS)
@pytest.mark.parametrize("email_verified", ["false", "true", 1])
def test_rejects_non_boolean_email_verified(
self, client_oidc_emails, monkeypatch, endpoint, payload, email_verified
):
"""The claim must be the boolean True; a truthy non-boolean is not verified."""

def _ok(token, request, audience):
return {
"aud": audience,
"email": "allowed@project.iam",
"email_verified": email_verified,
}

monkeypatch.setattr(
trigger_routes_module.google_id_token,
"verify_oauth2_token",
_ok,
)
resp = client_oidc_emails.post(
endpoint,
json=payload,
headers={"Authorization": "Bearer some.jwt.value"},
)
assert resp.status_code == 403
assert "Untrusted token principal" in resp.json()["detail"]

@pytest.mark.parametrize("endpoint,payload", _TRIGGER_ENDPOINTS_AND_PAYLOADS)
@pytest.mark.parametrize(
"email_verified_claim",
[{}, {"email_verified": None}],
ids=["missing", "none"],
)
def test_rejects_missing_or_null_email_verified(
self,
client_oidc_emails,
monkeypatch,
endpoint,
payload,
email_verified_claim,
):
"""An absent or null email_verified claim is not verified."""

def _ok(token, request, audience):
return {
"aud": audience,
"email": "allowed@project.iam",
**email_verified_claim,
}

monkeypatch.setattr(
trigger_routes_module.google_id_token,
"verify_oauth2_token",
_ok,
)
resp = client_oidc_emails.post(
endpoint,
json=payload,
headers={"Authorization": "Bearer some.jwt.value"},
)
assert resp.status_code == 403
assert "Untrusted token principal" in resp.json()["detail"]

@pytest.mark.parametrize("endpoint,payload", _TRIGGER_ENDPOINTS_AND_PAYLOADS)
def test_accepts_allowed_email(
self, client_oidc_emails, monkeypatch, endpoint, payload
Expand Down
Loading