@@ -1002,6 +1002,39 @@ def test_refresh_repeating_requests_non_rotating_tokens(self):
10021002 response = self .client .post (reverse ("oauth2_provider:token" ), data = token_request_data , ** auth_headers )
10031003 self .assertEqual (response .status_code , 200 )
10041004
1005+ def test_refresh_with_deleted_token (self ):
1006+ """
1007+ Ensure that using a deleted refresh token returns 400
1008+ """
1009+ self .client .login (username = "test_user" , password = "123456" )
1010+ authorization_code = self .get_auth ()
1011+
1012+ token_request_data = {
1013+ "grant_type" : "authorization_code" ,
1014+ "scope" : "read write" ,
1015+ "code" : authorization_code ,
1016+ "redirect_uri" : "http://example.org" ,
1017+ }
1018+ auth_headers = get_basic_auth_header (self .application .client_id , CLEARTEXT_SECRET )
1019+
1020+ # get a refresh token
1021+ response = self .client .post (reverse ("oauth2_provider:token" ), data = token_request_data , ** auth_headers )
1022+
1023+ content = json .loads (response .content .decode ("utf-8" ))
1024+ rt = content ["refresh_token" ]
1025+
1026+ token_request_data = {
1027+ "grant_type" : "refresh_token" ,
1028+ "refresh_token" : rt ,
1029+ "scope" : "read write" ,
1030+ }
1031+
1032+ # delete the access token
1033+ AccessToken .objects .filter (token = content ["access_token" ]).delete ()
1034+
1035+ response = self .client .post (reverse ("oauth2_provider:token" ), data = token_request_data , ** auth_headers )
1036+ self .assertEqual (response .status_code , 400 )
1037+
10051038 def test_basic_auth_bad_authcode (self ):
10061039 """
10071040 Request an access token using a bad authorization code
0 commit comments