Skip to content

Commit 1037481

Browse files
authored
Sem-Ver: feature Add and use a specific exception, JtiUniqunessException, for when a JTI is used more than once.
Signed-off-by: David Black <[email protected]>
1 parent dcd1d6c commit 1037481

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
@@ -53,6 +53,10 @@ class KeyIdentifierException(ASAPAuthenticationException):
5353
"""Raise when there are issues validating the key identifier"""
5454

5555

56+
class JtiUniqunessException(ASAPAuthenticationException):
57+
"""Raise when a JTI is seen more than once. """
58+
59+
5660
class NoTokenProvidedError(ASAPAuthenticationException):
5761
"""Raise when no token is provided"""
5862
pass

atlassian_jwt_auth/tests/test_verifier.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import mock
55

66
import atlassian_jwt_auth
7+
import atlassian_jwt_auth.exceptions
78
from atlassian_jwt_auth.tests import utils
89

910

@@ -98,8 +99,10 @@ def test_verify_jwt_with_jwt_with_already_seen_jti(self):
9899
self.assertIsNotNone(verifier.verify_jwt(
99100
a_jwt,
100101
self._example_aud))
101-
with self.assertRaisesRegexp(ValueError, 'has already been used'):
102-
verifier.verify_jwt(a_jwt, self._example_aud)
102+
for exception in [ValueError,
103+
atlassian_jwt_auth.exceptions.JtiUniqunessException]:
104+
with self.assertRaisesRegexp(exception, 'has already been used'):
105+
verifier.verify_jwt(a_jwt, self._example_aud)
103106

104107
def test_verify_jwt_with_already_seen_jti_with_uniqueness_disabled(self):
105108
""" tests that verify_jwt accepts a jwt if the jti

atlassian_jwt_auth/verifier.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from atlassian_jwt_auth import algorithms
66
from atlassian_jwt_auth import key
7+
from atlassian_jwt_auth import exceptions
78

89

910
class JWTAuthVerifier(object):
@@ -79,7 +80,8 @@ def _decode_jwt(self, a_jwt, key_identifier, jwt_key,
7980
def _check_jti(self, jti):
8081
"""Checks that the given jti has not been already been used."""
8182
if jti in self._seen_jti:
82-
raise ValueError("The jti, '%s', has already been used." % jti)
83+
raise exceptions.JtiUniqunessException(
84+
"The jti, '%s', has already been used." % jti)
8385
self._seen_jti[jti] = None
8486
while len(self._seen_jti) > 1000:
8587
self._seen_jti.popitem(last=False)

0 commit comments

Comments
 (0)