Mirrored from https://github.com/davoodmehraban89/Aram.git
Synced Dec 3, 20:45 UTC
test(auth): cover reviewer-only identity, signature tampering and weak public keys
davoodmehraban89 committed
Oct 30, 2026 at 22:13 UTC
ad66b06bab27ad61040f7a5b4f8cb81923eaf2da
1 file changed
+47
backend/tests/test_authenticated_identity.py
+47
@@ -179,3 +179,50 @@ def test_only_a_read_only_identity_endpoint_is_exposed(auth_client, keys):
179
"/api/v1/auth/me", headers={"Authorization": f"Bearer {token(keys[0])}"}
180
).status_code == 405
181
assert auth_client.get("/api/v1/health").status_code == 200
182
+
183
+
184
+def test_signed_reviewer_role_is_accepted_but_no_approval_action_exists(auth_client, keys):
185
+ response = request(
186
+ auth_client, token(keys[0], sub="independent-reviewer-22",
187
+ aram_roles=["mapping_reviewer"]),
188
+ )
189
+ assert response.status_code == 200
190
+ assert response.json()["roles"] == ["mapping_reviewer"]
191
+ assert auth_client.post(
192
+ "/api/v1/mapping/approve",
193
+ headers={"Authorization": f"Bearer {token(keys[0], aram_roles=['mapping_reviewer'])}"},
194
+ ).status_code == 404
195
+
196
+
197
+def test_token_payload_tampering_invalidates_signature(auth_client, keys):
198
+ import base64
199
+ import json
200
+ signed = token(keys[0])
201
+ header, payload, signature = signed.split(".")
202
+ decoded = json.loads(base64.urlsafe_b64decode(payload + "=" * (-len(payload) % 4)))
203
+ decoded["aram_roles"] = ["mapping_reviewer"]
204
+ tampered_payload = base64.urlsafe_b64encode(
205
+ json.dumps(decoded, separators=(",", ":")).encode()
206
+ ).rstrip(b"=").decode()
207
+ assert request(auth_client, f"{header}.{tampered_payload}.{signature}").status_code == 401
208
+
209
+
210
+def test_weak_rsa_verification_key_is_not_accepted(auth_client, keys):
211
+ weak = rsa.generate_private_key(public_exponent=65537, key_size=1024)
212
+ weak_public_pem = weak.public_key().public_bytes(
213
+ encoding=serialization.Encoding.PEM,
214
+ format=serialization.PublicFormat.SubjectPublicKeyInfo,
215
+ ).decode("ascii")
216
+ app.dependency_overrides[get_settings] = lambda: Settings(
217
+ auth_issuer=ISSUER, auth_audience=AUDIENCE,
218
+ auth_public_key_pem=weak_public_pem,
219
+ )
220
+ assert request(auth_client, token(keys[0])).status_code == 503
221
+
222
+
223
+def test_invalid_or_non_rsa_public_key_disables_identity(auth_client, keys):
224
+ app.dependency_overrides[get_settings] = lambda: Settings(
225
+ auth_issuer=ISSUER, auth_audience=AUDIENCE,
226
+ auth_public_key_pem="not a PEM public key",
227
+ )
228
+ assert request(auth_client, token(keys[0])).status_code == 503