|
13 | 13 |
|
14 | 14 | from oauthlib.oauth2 import BackendApplicationServer |
15 | 15 |
|
16 | | -from ..models import get_application_model |
| 16 | +from ..models import get_application_model, AccessToken |
17 | 17 | from ..oauth2_validators import OAuth2Validator |
18 | 18 | from ..settings import oauth2_settings |
19 | 19 | from ..views import ProtectedResourceView |
@@ -93,6 +93,17 @@ def test_client_credential_does_not_issue_refresh_token(self): |
93 | 93 | content = json.loads(response.content.decode("utf-8")) |
94 | 94 | self.assertNotIn("refresh_token", content) |
95 | 95 |
|
| 96 | + def test_client_credential_user_is_none_on_access_token(self): |
| 97 | + token_request_data = {'grant_type': 'client_credentials'} |
| 98 | + auth_headers = self.get_basic_auth_header(self.application.client_id, self.application.client_secret) |
| 99 | + |
| 100 | + response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data, **auth_headers) |
| 101 | + self.assertEqual(response.status_code, 200) |
| 102 | + |
| 103 | + content = json.loads(response.content.decode("utf-8")) |
| 104 | + access_token = AccessToken.objects.get(token=content["access_token"]) |
| 105 | + self.assertIsNone(access_token.user) |
| 106 | + |
96 | 107 |
|
97 | 108 | class TestExtendedRequest(BaseTest): |
98 | 109 | @classmethod |
@@ -130,7 +141,7 @@ def get_scopes(self): |
130 | 141 |
|
131 | 142 | valid, r = test_view.verify_request(request) |
132 | 143 | self.assertTrue(valid) |
133 | | - self.assertEqual(r.user, self.dev_user) |
| 144 | + self.assertIsNone(r.user) |
134 | 145 | self.assertEqual(r.client, self.application) |
135 | 146 | self.assertEqual(r.scopes, ['read', 'write']) |
136 | 147 |
|
|
0 commit comments