|
3 | 3 | import base64
|
4 | 4 | import json
|
5 | 5 | import datetime
|
| 6 | +import mock |
6 | 7 |
|
7 | 8 | from django.test import TestCase, RequestFactory
|
8 | 9 | from django.core.urlresolvers import reverse
|
|
11 | 12 | from ..compat import urlparse, parse_qs, urlencode, get_user_model
|
12 | 13 | from ..models import get_application_model, Grant, AccessToken
|
13 | 14 | from ..settings import oauth2_settings
|
| 15 | +from ..oauth2_validators import OAuth2Validator |
14 | 16 | from ..views import ProtectedResourceView
|
15 | 17 |
|
16 | 18 | from .test_utils import TestCaseUtils
|
@@ -495,6 +497,36 @@ def test_refresh_fail_repeating_requests(self):
|
495 | 497 | response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data, **auth_headers)
|
496 | 498 | self.assertEqual(response.status_code, 401)
|
497 | 499 |
|
| 500 | + def test_refresh_repeating_requests_non_rotating_tokens(self): |
| 501 | + """ |
| 502 | + Try refreshing an access token with the same refresh token more than once when not rotating tokens. |
| 503 | + """ |
| 504 | + self.client.login(username="test_user", password="123456") |
| 505 | + authorization_code = self.get_auth() |
| 506 | + |
| 507 | + token_request_data = { |
| 508 | + 'grant_type': 'authorization_code', |
| 509 | + 'code': authorization_code, |
| 510 | + 'redirect_uri': 'http://example.it' |
| 511 | + } |
| 512 | + auth_headers = self.get_basic_auth_header(self.application.client_id, self.application.client_secret) |
| 513 | + |
| 514 | + response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data, **auth_headers) |
| 515 | + content = json.loads(response.content.decode("utf-8")) |
| 516 | + self.assertTrue('refresh_token' in content) |
| 517 | + |
| 518 | + token_request_data = { |
| 519 | + 'grant_type': 'refresh_token', |
| 520 | + 'refresh_token': content['refresh_token'], |
| 521 | + 'scope': content['scope'], |
| 522 | + } |
| 523 | + |
| 524 | + with mock.patch('oauthlib.oauth2.rfc6749.request_validator.RequestValidator.rotate_refresh_token', return_value=False): |
| 525 | + response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data, **auth_headers) |
| 526 | + self.assertEqual(response.status_code, 200) |
| 527 | + response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data, **auth_headers) |
| 528 | + self.assertEqual(response.status_code, 200) |
| 529 | + |
498 | 530 | def test_basic_auth_bad_authcode(self):
|
499 | 531 | """
|
500 | 532 | Request an access token using a bad authorization code
|
|
0 commit comments