|
2 | 2 | import os |
3 | 3 |
|
4 | 4 | import pytest |
| 5 | +from cryptojwt.exception import UnsupportedAlgorithm |
5 | 6 | from cryptojwt.jws import jws |
6 | 7 | from cryptojwt.jws.utils import left_hash |
7 | 8 | from cryptojwt.jwt import JWT |
@@ -243,6 +244,24 @@ def test_update_service_context_with_idtoken_missing_nonce(self): |
243 | 244 | with pytest.raises(ValueError): |
244 | 245 | self.service.update_service_context(resp, 'state') |
245 | 246 |
|
| 247 | + @pytest.mark.parametrize("allow_sign_alg_none", [True, False]) |
| 248 | + def test_allow_unsigned_idtoken(self, allow_sign_alg_none): |
| 249 | + req_args = {'response_type': 'code', 'state': 'state', 'nonce': 'nonce'} |
| 250 | + self.service.endpoint = 'https://example.com/authorize' |
| 251 | + self.service.get_request_parameters(request_args=req_args) |
| 252 | + # Build an ID Token |
| 253 | + idt = JWT(ISS_KEY, iss=ISS, lifetime=3600, sign_alg='none') |
| 254 | + payload = {'sub': '123456789', 'aud': ['client_id']} |
| 255 | + _idt = idt.pack(payload) |
| 256 | + self.service.service_context.behaviour["verify_args"] = { |
| 257 | + "allow_sign_alg_none": allow_sign_alg_none |
| 258 | + } |
| 259 | + resp = AuthorizationResponse(state='state', code='code', id_token=_idt) |
| 260 | + if allow_sign_alg_none: |
| 261 | + resp = self.service.parse_response(resp.to_urlencoded()) |
| 262 | + else: |
| 263 | + with pytest.raises(UnsupportedAlgorithm): |
| 264 | + self.service.parse_response(resp.to_urlencoded()) |
246 | 265 |
|
247 | 266 | class TestAuthorizationCallback(object): |
248 | 267 | @pytest.fixture(autouse=True) |
|
0 commit comments