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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug by correctly checking validity of credentials
- Loading branch information
Bill Prin
committed
Sep 16, 2016
1 parent
9f0618d
commit cfe40c0
Showing
3 changed files
with
39 additions
and
11 deletions.
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): | ||
|