@davoodmehraban89 / Aram / commits / 59cb141
Fork 0

test(auth): distinguish invalid signed role claims from forbidden year permissions

davoodmehraban89 committed Oct 30, 2026 at 22:26 UTC 59cb141cad81add6523f4fea7a127c8180d080e5
1 file changed +23 -2
backend/tests/test_authenticated_identity.py
+23 -2
@@ -298,7 +298,10 @@ def test_wrong_company_year_or_role_is_denied(auth_client, keys, session, signed
298 response = _scope_request(
299 auth_client, keys[0], year.id, aram_scopes=[signed_grant],
300 )
301 - assert response.status_code == 403
301 + # Role mismatches inside signed claims are an invalid credential
302 + # (401); a valid token for a different company/year is forbidden (403).
303 + expected = 401 if signed_grant["role"] != "mapping_proposer" else 403
304 + assert response.status_code == expected
305 assert "company_code" not in response.text
306 finally:
307 app.dependency_overrides.pop(get_session, None)
@@ -335,7 +338,7 @@ def test_reviewer_must_possess_explicit_reviewer_grant(auth_client, keys, sessio
338 assert _scope_request(
339 auth_client, keys[0], year.id,
340 aram_roles=["mapping_reviewer"], aram_scopes=[_scope(role="mapping_proposer")],
338 - ).status_code == 403
341 + ).status_code == 401
342 assert auth_client.post("/api/v1/mapping/approve").status_code == 404
343 finally:
344 app.dependency_overrides.pop(get_session, None)
@@ -460,3 +463,21 @@ def test_access_check_rejects_uncommitted_fiscal_changes_without_flush(session,
463 )
464 assert scope.company_code == "FIN-OPERATIONS"
465 assert pending in session.new and pending.id is None
466 +
467 +
468 +def test_valid_proposer_cannot_assume_reviewer_role_with_scope_check(session, keys):
469 + from fastapi import HTTPException
470 + from aram_backend.authenticated_identity import verify_access_token
471 + from aram_backend.mapping_year_authorization import require_year_access
472 + year = _year(session)
473 + principal = verify_access_token(
474 + token(keys[0], aram_scopes=[_scope()]),
475 + settings=Settings(auth_issuer=ISSUER, auth_audience=AUDIENCE,
476 + auth_public_key_pem=keys[1]),
477 + )
478 + with pytest.raises(HTTPException) as denied:
479 + require_year_access(
480 + session, principal=principal, year_id=year.id,
481 + required_role="mapping_reviewer",
482 + )
483 + assert denied.value.status_code == 403