Skip to content

Commit 8beabc7

Browse files
committed
tests for #229
1 parent 3b2f248 commit 8beabc7

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

oauth2_provider/tests/test_authorization_code.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from django.utils import timezone
1111

1212
from ..compat import urlparse, parse_qs, urlencode, get_user_model
13-
from ..models import get_application_model, Grant, AccessToken
13+
from ..models import get_application_model, Grant, AccessToken, RefreshToken
1414
from ..settings import oauth2_settings
1515
from ..views import ProtectedResourceView
1616

@@ -547,6 +547,37 @@ def test_refresh(self):
547547
content = json.loads(response.content.decode("utf-8"))
548548
self.assertTrue('invalid_grant' in content.values())
549549

550+
def test_refresh_invalidates_old_tokens(self):
551+
"""
552+
Ensure existing refresh tokens are cleaned up when issuing new ones
553+
"""
554+
self.client.login(username="test_user", password="123456")
555+
authorization_code = self.get_auth()
556+
557+
token_request_data = {
558+
'grant_type': 'authorization_code',
559+
'code': authorization_code,
560+
'redirect_uri': 'http://example.it'
561+
}
562+
auth_headers = self.get_basic_auth_header(self.application.client_id, self.application.client_secret)
563+
564+
response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data, **auth_headers)
565+
content = json.loads(response.content.decode("utf-8"))
566+
567+
rt = content['refresh_token']
568+
at = content['access_token']
569+
570+
token_request_data = {
571+
'grant_type': 'refresh_token',
572+
'refresh_token': rt,
573+
'scope': content['scope'],
574+
}
575+
response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data, **auth_headers)
576+
self.assertEqual(response.status_code, 200)
577+
578+
self.assertFalse(RefreshToken.objects.filter(token=rt).exists())
579+
self.assertFalse(AccessToken.objects.filter(token=at).exists())
580+
550581
def test_refresh_no_scopes(self):
551582
"""
552583
Request an access token using a refresh token without passing any scope

oauth2_provider/tests/test_token_revocation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def test_revoke_refresh_token(self):
118118
response = self.client.post(url)
119119
self.assertEqual(response.status_code, 200)
120120
self.assertFalse(RefreshToken.objects.filter(id=rtok.id).exists())
121+
self.assertFalse(AccessToken.objects.filter(id=rtok.access_token.id).exists())
121122

122123
def test_revoke_token_with_wrong_hint(self):
123124
"""

0 commit comments

Comments
 (0)