File tree Expand file tree Collapse file tree 4 files changed +30
-5
lines changed Expand file tree Collapse file tree 4 files changed +30
-5
lines changed Original file line number Diff line number Diff line change 2
2
3
3
[tool .poetry ]
4
4
name = " cryptojwt"
5
- version = " 1.9.3 "
5
+ version = " 1.9.4 "
6
6
description = " Python implementation of JWT, JWE, JWS and JWK"
7
7
authors = [" Roland Hedberg <roland@catalogix.se>" ]
8
8
license = " Apache-2.0"
Original file line number Diff line number Diff line change 40
40
41
41
LOGGER = logging .getLogger (__name__ )
42
42
43
+ JWKS_CONTENT_TYPES = set (["application/json" , "application/jwk-set+json" ])
44
+
43
45
# def raise_exception(excep, descr, error='service_error'):
44
46
# _err = json.dumps({'error': error, 'error_description': descr})
45
47
# raise excep(_err, 'application/json')
@@ -528,8 +530,8 @@ def _parse_remote_response(self, response):
528
530
"""
529
531
# Check if the content type is the right one.
530
532
try :
531
- if not check_content_type (response .headers ["Content-Type" ], "application/json" ):
532
- LOGGER .warning ("Wrong Content_type (%s)" , response .headers ["Content-Type" ])
533
+ if not check_content_type (response .headers ["Content-Type" ], JWKS_CONTENT_TYPES ):
534
+ LOGGER .warning ("Wrong Content-Type (%s)" , response .headers ["Content-Type" ])
533
535
except KeyError :
534
536
pass
535
537
Original file line number Diff line number Diff line change @@ -262,12 +262,17 @@ def httpc_params_loader(httpc_params):
262
262
return httpc_params
263
263
264
264
265
- def check_content_type (content_type , mime_type ):
265
+ def check_content_type (content_type : str , mime_type : str | list [ str ] | set [ str ] ):
266
266
"""Return True if the content type contains the MIME type"""
267
267
msg = EmailMessage ()
268
268
msg ["content-type" ] = content_type
269
269
mt = msg .get_content_type ()
270
- return mime_type == mt
270
+ if isinstance (mime_type , str ):
271
+ return mt == mime_type
272
+ elif isinstance (mime_type , (list , set )):
273
+ return mt in mime_type
274
+ else :
275
+ raise ValueError ("Invalid MIME type argument" )
271
276
272
277
273
278
def is_compact_jws (token ):
Original file line number Diff line number Diff line change
1
+ import pytest
2
+
1
3
from cryptojwt .utils import check_content_type
2
4
3
5
@@ -15,3 +17,19 @@ def test_check_content_type():
15
17
)
16
18
is False
17
19
)
20
+ assert (
21
+ check_content_type (
22
+ content_type = "application/jwk-set+json;charset=UTF-8" ,
23
+ mime_type = "application/application/jwk-set+json" ,
24
+ )
25
+ is False
26
+ )
27
+ assert (
28
+ check_content_type (
29
+ content_type = "application/jwk-set+json;charset=UTF-8" ,
30
+ mime_type = set (["application/application/jwk-set+json" , "application/json" ]),
31
+ )
32
+ is False
33
+ )
34
+ with pytest .raises (ValueError ):
35
+ check_content_type (content_type = "application/jwk-set+json;charset=UTF-8" , mime_type = 42 )
You can’t perform that action at this time.
0 commit comments