|
11 | 11 | from ..compat import urlparse, parse_qs, urlencode, get_user_model
|
12 | 12 | from ..models import get_application_model, Grant, AccessToken
|
13 | 13 | from ..settings import oauth2_settings
|
| 14 | +from ..oauth2_validators import OAuth2Validator |
14 | 15 | from ..views import ProtectedResourceView
|
15 | 16 |
|
16 | 17 | from .test_utils import TestCaseUtils
|
@@ -474,6 +475,43 @@ def test_refresh_fail_repeating_requests(self):
|
474 | 475 | response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data, **auth_headers)
|
475 | 476 | self.assertEqual(response.status_code, 401)
|
476 | 477 |
|
| 478 | + def test_refresh_repeating_requests_non_rotating_tokens(self): |
| 479 | + """ |
| 480 | + Try refreshing an access token with the same refresh token more than once when not rotating tokens. |
| 481 | + """ |
| 482 | + class NonRotatingOAuth2Validator(OAuth2Validator): |
| 483 | + def rotate_refresh_token(self, request): |
| 484 | + return False |
| 485 | + validator_class = oauth2_settings.OAUTH2_VALIDATOR_CLASS |
| 486 | + oauth2_settings.OAUTH2_VALIDATOR_CLASS = NonRotatingOAuth2Validator |
| 487 | + |
| 488 | + self.client.login(username="test_user", password="123456") |
| 489 | + authorization_code = self.get_auth() |
| 490 | + |
| 491 | + token_request_data = { |
| 492 | + 'grant_type': 'authorization_code', |
| 493 | + 'code': authorization_code, |
| 494 | + 'redirect_uri': 'http://example.it' |
| 495 | + } |
| 496 | + auth_headers = self.get_basic_auth_header(self.application.client_id, self.application.client_secret) |
| 497 | + |
| 498 | + response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data, **auth_headers) |
| 499 | + content = json.loads(response.content.decode("utf-8")) |
| 500 | + self.assertTrue('refresh_token' in content) |
| 501 | + |
| 502 | + token_request_data = { |
| 503 | + 'grant_type': 'refresh_token', |
| 504 | + 'refresh_token': content['refresh_token'], |
| 505 | + 'scope': content['scope'], |
| 506 | + } |
| 507 | + |
| 508 | + response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data, **auth_headers) |
| 509 | + self.assertEqual(response.status_code, 200) |
| 510 | + response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data, **auth_headers) |
| 511 | + self.assertEqual(response.status_code, 200) |
| 512 | + |
| 513 | + oauth2_settings.OAUTH2_VALIDATOR_CLASS = validator_class |
| 514 | + |
477 | 515 | def test_basic_auth_bad_authcode(self):
|
478 | 516 | """
|
479 | 517 | Request an access token using a bad authorization code
|
|
0 commit comments