Skip to content

Commit 4979783

Browse files
committed
Sem-Ver: feature Add a SubjectDoesNotMatchIssuerException for when the subject does not match the issuer.
Signed-off-by: David Black <[email protected]>
1 parent 7f2dc3c commit 4979783

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

atlassian_jwt_auth/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class JtiUniquenessException(ASAPAuthenticationException):
5757
"""Raise when a JTI is seen more than once. """
5858

5959

60+
class SubjectDoesNotMatchIssuerException(ASAPAuthenticationException):
61+
"""Raise when the subject and issuer differ. """
62+
63+
6064
class NoTokenProvidedError(ASAPAuthenticationException):
6165
"""Raise when no token is provided"""
6266
pass

atlassian_jwt_auth/tests/test_verifier.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,12 @@ def test_verify_jwt_with_non_matching_sub_and_iss(self, m_j_decode):
7070
}
7171
a_jwt = self._jwt_auth_signer.generate_jwt(self._example_aud)
7272
verifier = self._setup_jwt_auth_verifier(self._public_key_pem)
73-
with self.assertRaisesRegexp(ValueError, expected_msg):
74-
verifier.verify_jwt(a_jwt, self._example_aud)
73+
for exception in [
74+
ValueError,
75+
atlassian_jwt_auth.exceptions.SubjectDoesNotMatchIssuerException,
76+
]:
77+
with self.assertRaisesRegexp(exception, expected_msg):
78+
verifier.verify_jwt(a_jwt, self._example_aud)
7579

7680
@mock.patch('atlassian_jwt_auth.verifier.jwt.decode')
7781
def test_verify_jwt_with_jwt_lasting_gt_max_time(self, m_j_decode):

atlassian_jwt_auth/verifier.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ def _decode_jwt(self, a_jwt, key_identifier, jwt_key,
6363

6464
if self._subject_should_match_issuer and (
6565
claims.get('sub') and claims['iss'] != claims['sub']):
66-
raise ValueError('Issuer does not match the subject.')
66+
raise exceptions.SubjectDoesNotMatchIssuerException(
67+
'Issuer does not match the subject.')
6768

6869
_aud = claims['aud']
6970
_exp = int(claims['exp'])

0 commit comments

Comments
 (0)