Skip to content

Commit c3ffc81

Browse files
committed
Add assertion to ensure that request has a client attr on _load_application
1 parent aa798df commit c3ffc81

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

oauth2_provider/oauth2_validators.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ def _load_application(self, client_id, request):
9494
If request.client was not set, load application instance for given client_id and store it
9595
in request.client
9696
"""
97+
98+
# we want to be sure that request has the client attribute!
99+
assert hasattr(request, "client"), "'request' instance has no 'client' attribute"
100+
97101
try:
98102
request.client = request.client or Application.objects.get(client_id=client_id)
99103
return request.client

oauth2_provider/tests/test_oauth2_validators.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,6 @@ def test_client_authentication_required(self):
6565
self.application.save()
6666
self.request.client = ''
6767
self.assertTrue(self.validator.client_authentication_required(self.request))
68+
69+
def test_load_application_fails_when_request_has_no_client(self):
70+
self.assertRaises(AssertionError, self.validator.authenticate_client_id, 'client_id', {})

0 commit comments

Comments
 (0)