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
@@ -479,12 +480,6 @@ def test_refresh_repeating_requests_non_rotating_tokens(self):
479
480
"""
480
481
Try refreshing an access token with the same refresh token more than once when not rotating tokens.
481
482
"""
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
483
self .client .login (username = "test_user" , password = "123456" )
489
484
authorization_code = self .get_auth ()
490
485
@@ -504,13 +499,12 @@ def rotate_refresh_token(self, request):
504
499
'refresh_token' : content ['refresh_token' ],
505
500
'scope' : content ['scope' ],
506
501
}
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
502
513
- oauth2_settings .OAUTH2_VALIDATOR_CLASS = validator_class
503
+ with mock .patch ('oauthlib.request_validator.RequestValidator.rotate_refresh_token' , return_value = False ):
504
+ response = self .client .post (reverse ('oauth2_provider:token' ), data = token_request_data , ** auth_headers )
505
+ self .assertEqual (response .status_code , 200 )
506
+ response = self .client .post (reverse ('oauth2_provider:token' ), data = token_request_data , ** auth_headers )
507
+ self .assertEqual (response .status_code , 200 )
514
508
515
509
def test_basic_auth_bad_authcode (self ):
516
510
"""
0 commit comments