@@ -163,6 +163,14 @@ def test_request_subject_does_not_need_to_match_issuer_from_settings(self):
163163 self .test_settings ['ASAP_SUBJECT_SHOULD_MATCH_ISSUER' ] = False
164164 self .check_response ('needed' , 'one' , 200 , subject = 'different_than_is' )
165165
166+ def test_request_subject_and_issue_not_matching (self ):
167+ self .check_response (
168+ 'needed' ,
169+ 'Subject and Issuer do not match' ,
170+ 401 ,
171+ subject = 'different_than_is' ,
172+ )
173+
166174
167175class TestAsapDecorator (DjangoAsapMixin , RS256KeyTestMixin , SimpleTestCase ):
168176 def test_request_with_valid_token_is_allowed (self ):
@@ -294,10 +302,14 @@ def test_request_subject_does_need_to_match_issuer_override_settings(self):
294302 with override_settings (** dict (
295303 self .test_settings , ASAP_SUBJECT_SHOULD_MATCH_ISSUER = False )):
296304 message = 'Issuer does not match the subject'
297- with self .assertRaisesRegexp (ValueError , message ):
298- response = self .client .get (
299- reverse ('subject_does_need_to_match_issuer' ),
300- HTTP_AUTHORIZATION = b'Bearer ' + token )
305+ response = self .client .get (
306+ reverse ('subject_does_need_to_match_issuer' ),
307+ HTTP_AUTHORIZATION = b'Bearer ' + token )
308+ self .assertContains (
309+ response ,
310+ 'Unauthorized: Subject and Issuer do not match' ,
311+ status_code = 401
312+ )
301313
302314 def test_request_subject_does_not_need_to_match_issuer_from_settings (self ):
303315 token = create_token (
0 commit comments