This repository has been archived by the owner on Nov 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 430
Fix django authorization redirect by correctly checking validity of credentials #651
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,6 @@ | |
|
||
from oauth2client import client | ||
import oauth2client.contrib.django_util | ||
from oauth2client.contrib.django_util import models | ||
from oauth2client.contrib.django_util import views | ||
from tests.contrib import django_util as tests_django_util | ||
from tests.contrib.django_util import models as tests_models | ||
|
@@ -117,22 +116,50 @@ def test_authorize_works_explicit_return_url(self): | |
response = views.oauth2_authorize(request) | ||
self.assertIsInstance(response, http.HttpResponseRedirect) | ||
|
||
def test_authorized_user_not_logged_in_redirects(self): | ||
def test_authorized_user_no_credentials_redirects(self): | ||
request = self.factory.get('oauth2/oauth2authorize', | ||
data={'return_url': '/return_endpoint'}) | ||
request.session = self.session | ||
|
||
authorized_user = django_models.User.objects.create_user( | ||
username='bill2', email='[email protected]', password='hunter2') | ||
credentials = models.CredentialsField() | ||
|
||
tests_models.CredentialsModel.objects.create( | ||
user_id=authorized_user, | ||
credentials=None) | ||
|
||
request.user = authorized_user | ||
response = views.oauth2_authorize(request) | ||
self.assertIsInstance(response, http.HttpResponseRedirect) | ||
|
||
def test_already_authorized(self): | ||
request = self.factory.get('oauth2/oauth2authorize', | ||
data={'return_url': '/return_endpoint'}) | ||
request.session = self.session | ||
|
||
authorized_user = django_models.User.objects.create_user( | ||
username='bill2', email='[email protected]', password='hunter2') | ||
|
||
credentials = _Credentials() | ||
tests_models.CredentialsModel.objects.create( | ||
user_id=authorized_user, | ||
credentials=credentials) | ||
|
||
request.user = authorized_user | ||
response = views.oauth2_authorize(request) | ||
self.assertIsInstance(response, http.HttpResponseRedirect) | ||
self.assertEqual(response.url, '/return_endpoint') | ||
|
||
|
||
class _Credentials(object): | ||
# Can't use mock when testing Django models | ||
# https://code.djangoproject.com/ticket/25493 | ||
def __init__(self): | ||
self.invalid = False | ||
self.scopes = set() | ||
|
||
def has_scopes(self, _): | ||
return True | ||
|
||
|
||
class Oauth2CallbackTest(tests_django_util.TestWithDjangoEnvironment): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.