|
5 | 5 |
|
6 | 6 | import jwcrypto.jwk |
7 | 7 | import jwcrypto.jws |
| 8 | +import jwcrypto.jwt |
8 | 9 | import pytest |
9 | 10 |
|
10 | 11 | from keycloak import KeycloakAdmin, KeycloakOpenID |
@@ -379,7 +380,7 @@ def test_decode_token_invalid_token(oid_with_credentials: tuple[KeycloakOpenID, |
379 | 380 | key = jwcrypto.jwk.JWK.from_pem(key.encode("utf-8")) |
380 | 381 |
|
381 | 382 | invalid_access_token = access_token + "a" |
382 | | - with pytest.raises(jwcrypto.jws.InvalidJWSSignature): |
| 383 | + with pytest.raises(jwcrypto.jwt.JWTMissingKey): |
383 | 384 | decoded_invalid_access_token = oid.decode_token(token=invalid_access_token, validate=True) |
384 | 385 |
|
385 | 386 | with pytest.raises(jwcrypto.jws.InvalidJWSSignature): |
@@ -941,7 +942,7 @@ async def test_a_decode_token_invalid_token( |
941 | 942 | key = jwcrypto.jwk.JWK.from_pem(key.encode("utf-8")) |
942 | 943 |
|
943 | 944 | invalid_access_token = access_token + "a" |
944 | | - with pytest.raises(jwcrypto.jws.InvalidJWSSignature): |
| 945 | + with pytest.raises(jwcrypto.jwt.JWTMissingKey): |
945 | 946 | decoded_invalid_access_token = await oid.a_decode_token( |
946 | 947 | token=invalid_access_token, |
947 | 948 | validate=True, |
@@ -1219,3 +1220,54 @@ def test_counter_part() -> None: |
1219 | 1220 | continue |
1220 | 1221 |
|
1221 | 1222 | assert async_method[2:] in sync_methods |
| 1223 | + |
| 1224 | + |
| 1225 | +def test_other_signing_methods( |
| 1226 | + admin: KeycloakAdmin, oid_with_credentials: tuple[KeycloakOpenID, str, str] |
| 1227 | +) -> None: |
| 1228 | + """Test other signing algs.""" |
| 1229 | + oid, username, password = oid_with_credentials |
| 1230 | + |
| 1231 | + admin.change_current_realm(oid.realm_name) |
| 1232 | + client_id = admin.get_client_id(oid.client_id) |
| 1233 | + assert client_id is not None |
| 1234 | + client_def = admin.get_client(client_id) |
| 1235 | + client_def["attributes"].update( |
| 1236 | + { |
| 1237 | + "access.token.signed.response.alg": "RS512", |
| 1238 | + "id.token.signed.response.alg": "RS512", |
| 1239 | + "userinfo.signed.response.alg": "RS512", |
| 1240 | + } |
| 1241 | + ) |
| 1242 | + res = admin.update_client(client_id, client_def) |
| 1243 | + assert res == {} |
| 1244 | + |
| 1245 | + token = oid.token(username, password) |
| 1246 | + res = oid.decode_token(token["access_token"]) |
| 1247 | + assert res != {} |
| 1248 | + |
| 1249 | + |
| 1250 | +@pytest.mark.asyncio |
| 1251 | +async def test_a_other_signing_methods( |
| 1252 | + admin: KeycloakAdmin, oid_with_credentials: tuple[KeycloakOpenID, str, str] |
| 1253 | +) -> None: |
| 1254 | + """Test other signing algs.""" |
| 1255 | + oid, username, password = oid_with_credentials |
| 1256 | + |
| 1257 | + await admin.a_change_current_realm(oid.realm_name) |
| 1258 | + client_id = await admin.a_get_client_id(oid.client_id) |
| 1259 | + assert client_id is not None |
| 1260 | + client_def = await admin.a_get_client(client_id) |
| 1261 | + client_def["attributes"].update( |
| 1262 | + { |
| 1263 | + "access.token.signed.response.alg": "RS512", |
| 1264 | + "id.token.signed.response.alg": "RS512", |
| 1265 | + "userinfo.signed.response.alg": "RS512", |
| 1266 | + } |
| 1267 | + ) |
| 1268 | + res = await admin.a_update_client(client_id, client_def) |
| 1269 | + assert res == {} |
| 1270 | + |
| 1271 | + token = await oid.a_token(username, password) |
| 1272 | + res = await oid.a_decode_token(token["access_token"]) |
| 1273 | + assert res != {} |
0 commit comments