-
Couldn't load subscription status.
- Fork 816
Disable 255 chars length limit for redirect uri (#902) #903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MattBlack85
merged 3 commits into
django-oauth:master
from
shaddeus:fix-redirect-uri-255-chars-length-limitation
Dec 18, 2020
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,18 @@ | ||
| # Generated by Django 3.1.4 on 2020-12-11 13:14 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('oauth2_provider', '0002_auto_20190406_1805'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name='grant', | ||
| name='redirect_uri', | ||
| field=models.TextField(), | ||
| ), | ||
| ] | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -22,10 +22,15 @@ | |
| UserModel = get_user_model() | ||
|
|
||
|
|
||
| class TestModels(TestCase): | ||
| class BaseTestModels(TestCase): | ||
| def setUp(self): | ||
| self.user = UserModel.objects.create_user("test_user", "[email protected]", "123456") | ||
|
|
||
| def tearDown(self): | ||
| self.user.delete() | ||
|
|
||
|
|
||
| class TestModels(BaseTestModels): | ||
| def test_allow_scopes(self): | ||
| self.client.login(username="test_user", password="123456") | ||
| app = Application.objects.create( | ||
|
|
@@ -103,10 +108,7 @@ def test_scopes_property(self): | |
| OAUTH2_PROVIDER_REFRESH_TOKEN_MODEL="tests.SampleRefreshToken", | ||
| OAUTH2_PROVIDER_GRANT_MODEL="tests.SampleGrant", | ||
| ) | ||
| class TestCustomModels(TestCase): | ||
| def setUp(self): | ||
| self.user = UserModel.objects.create_user("test_user", "[email protected]", "123456") | ||
|
|
||
| class TestCustomModels(BaseTestModels): | ||
| def test_custom_application_model(self): | ||
| """ | ||
| If a custom application model is installed, it should be present in | ||
|
|
@@ -237,7 +239,21 @@ def test_custom_grant_model_not_installed(self): | |
| oauth2_settings.GRANT_MODEL = "oauth2_provider.Grant" | ||
|
|
||
|
|
||
| class TestGrantModel(TestCase): | ||
| class TestGrantModel(BaseTestModels): | ||
| def setUp(self): | ||
| super().setUp() | ||
| self.application = Application.objects.create( | ||
| name="Test Application", | ||
| redirect_uris="", | ||
| user=self.user, | ||
| client_type=Application.CLIENT_CONFIDENTIAL, | ||
| authorization_grant_type=Application.GRANT_AUTHORIZATION_CODE, | ||
| ) | ||
|
|
||
| def tearDown(self): | ||
| self.application.delete() | ||
| super().tearDown() | ||
|
|
||
| def test_str(self): | ||
| grant = Grant(code="test_code") | ||
| self.assertEqual("%s" % grant, grant.code) | ||
|
|
@@ -247,11 +263,26 @@ def test_expires_can_be_none(self): | |
| self.assertIsNone(grant.expires) | ||
| self.assertTrue(grant.is_expired()) | ||
|
|
||
| def test_redirect_uri_can_be_longer_than_255_chars(self): | ||
| long_redirect_uri = "http://example.com/{}".format("authorized/" * 25) | ||
| self.assertTrue(len(long_redirect_uri) > 255) | ||
| grant = Grant.objects.create( | ||
| user=self.user, | ||
| code="test_code", | ||
| application=self.application, | ||
| expires=timezone.now(), | ||
| redirect_uri=long_redirect_uri, | ||
| scope="", | ||
| ) | ||
| grant.refresh_from_db() | ||
|
|
||
| # It would be necessary to run test using another DB engine than sqlite | ||
| # that transform varchar(255) into text data type. | ||
| # https://sqlite.org/datatype3.html#affinity_name_examples | ||
| self.assertEqual(grant.redirect_uri, long_redirect_uri) | ||
|
|
||
| class TestAccessTokenModel(TestCase): | ||
| def setUp(self): | ||
| self.user = UserModel.objects.create_user("test_user", "[email protected]", "123456") | ||
|
|
||
| class TestAccessTokenModel(BaseTestModels): | ||
| def test_str(self): | ||
| access_token = AccessToken(token="test_token") | ||
| self.assertEqual("%s" % access_token, access_token.token) | ||
|
|
@@ -273,15 +304,15 @@ def test_expires_can_be_none(self): | |
| self.assertTrue(access_token.is_expired()) | ||
|
|
||
|
|
||
| class TestRefreshTokenModel(TestCase): | ||
| class TestRefreshTokenModel(BaseTestModels): | ||
| def test_str(self): | ||
| refresh_token = RefreshToken(token="test_token") | ||
| self.assertEqual("%s" % refresh_token, refresh_token.token) | ||
|
|
||
|
|
||
| class TestClearExpired(TestCase): | ||
| class TestClearExpired(BaseTestModels): | ||
| def setUp(self): | ||
| self.user = UserModel.objects.create_user("test_user", "[email protected]", "123456") | ||
| super().setUp() | ||
| # Insert two tokens on database. | ||
| app = Application.objects.create( | ||
| name="test_app", | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.