This repository has been archived by the owner on Jan 4, 2022. It is now read-only.
forked from jazzband/django-oauth-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'revoke-keys' of github.com:solvebio/django-oauth-toolki…
…t into davecap-revoke-keys
- Loading branch information
Showing
7 changed files
with
187 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,119 @@ | ||
from __future__ import unicode_literals | ||
|
||
import datetime | ||
|
||
from django.test import TestCase, RequestFactory | ||
from django.core.urlresolvers import reverse | ||
from django.utils import timezone | ||
|
||
from ..compat import urlencode, get_user_model | ||
from ..models import get_application_model, AccessToken, RefreshToken | ||
from ..settings import oauth2_settings | ||
|
||
from .test_utils import TestCaseUtils | ||
|
||
|
||
Application = get_application_model() | ||
UserModel = get_user_model() | ||
|
||
|
||
class BaseTest(TestCaseUtils, TestCase): | ||
def setUp(self): | ||
self.factory = RequestFactory() | ||
self.test_user = UserModel.objects.create_user("test_user", "[email protected]", "123456") | ||
self.dev_user = UserModel.objects.create_user("dev_user", "[email protected]", "123456") | ||
|
||
self.application = Application( | ||
name="Test Application", | ||
redirect_uris="http://localhost http://example.com http://example.it", | ||
user=self.dev_user, | ||
client_type=Application.CLIENT_CONFIDENTIAL, | ||
authorization_grant_type=Application.GRANT_AUTHORIZATION_CODE, | ||
) | ||
self.application.save() | ||
|
||
oauth2_settings._SCOPES = ['read', 'write'] | ||
|
||
def tearDown(self): | ||
self.application.delete() | ||
self.test_user.delete() | ||
self.dev_user.delete() | ||
|
||
|
||
class TestRevocationView(BaseTest): | ||
def test_revoke_access_token(self): | ||
""" | ||
""" | ||
tok = AccessToken.objects.create(user=self.test_user, token='1234567890', | ||
application=self.application, | ||
expires=timezone.now()+datetime.timedelta(days=1), | ||
scope='read write') | ||
query_string = urlencode({ | ||
'client_id': self.application.client_id, | ||
'client_secret': self.application.client_secret, | ||
'token': tok.token, | ||
}) | ||
url = "{url}?{qs}".format(url=reverse('oauth2_provider:revoke-token'), qs=query_string) | ||
response = self.client.post(url) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertFalse(AccessToken.objects.filter(id=tok.id).exists()) | ||
|
||
def test_revoke_access_token_with_hint(self): | ||
""" | ||
""" | ||
tok = AccessToken.objects.create(user=self.test_user, token='1234567890', | ||
application=self.application, | ||
expires=timezone.now()+datetime.timedelta(days=1), | ||
scope='read write') | ||
query_string = urlencode({ | ||
'client_id': self.application.client_id, | ||
'client_secret': self.application.client_secret, | ||
'token': tok.token, | ||
'token_type_hint': 'access_token' | ||
}) | ||
url = "{url}?{qs}".format(url=reverse('oauth2_provider:revoke-token'), qs=query_string) | ||
response = self.client.post(url) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertFalse(AccessToken.objects.filter(id=tok.id).exists()) | ||
|
||
def test_revoke_access_token_with_invalid_hint(self): | ||
""" | ||
""" | ||
tok = AccessToken.objects.create(user=self.test_user, token='1234567890', | ||
application=self.application, | ||
expires=timezone.now()+datetime.timedelta(days=1), | ||
scope='read write') | ||
# invalid hint should have no effect | ||
query_string = urlencode({ | ||
'client_id': self.application.client_id, | ||
'client_secret': self.application.client_secret, | ||
'token': tok.token, | ||
'token_type_hint': 'bad_hint' | ||
}) | ||
url = "{url}?{qs}".format(url=reverse('oauth2_provider:revoke-token'), qs=query_string) | ||
response = self.client.post(url) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertFalse(AccessToken.objects.filter(id=tok.id).exists()) | ||
|
||
def test_revoke_refresh_token(self): | ||
""" | ||
""" | ||
tok = AccessToken.objects.create(user=self.test_user, token='1234567890', | ||
application=self.application, | ||
expires=timezone.now()+datetime.timedelta(days=1), | ||
scope='read write') | ||
rtok = RefreshToken.objects.create(user=self.test_user, token='999999999', | ||
application=self.application, access_token=tok) | ||
query_string = urlencode({ | ||
'client_id': self.application.client_id, | ||
'client_secret': self.application.client_secret, | ||
'token': rtok.token, | ||
}) | ||
url = "{url}?{qs}".format(url=reverse('oauth2_provider:revoke-token'), qs=query_string) | ||
response = self.client.post(url) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertFalse(RefreshToken.objects.filter(id=rtok.id).exists()) |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .base import AuthorizationView, TokenView | ||
from .base import AuthorizationView, TokenView, RevokeTokenView | ||
from .application import ApplicationRegistration, ApplicationDetail, ApplicationList, \ | ||
ApplicationDelete, ApplicationUpdate | ||
from .generic import ProtectedResourceView, ScopedProtectedResourceView, ReadWriteScopedResourceView |
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