forked from AzMoo/django-okta-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented group management and make sure test coverage is complete.
- Loading branch information
Matt Magin
committed
Apr 14, 2020
1 parent
8a59360
commit 20aad69
Showing
14 changed files
with
818 additions
and
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[run] | ||
omit = okta_oauth2/tests/* | ||
source = okta_oauth2 |
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
Empty file.
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,29 @@ | ||
from unittest.mock import Mock, patch | ||
|
||
from okta_oauth2.backend import OktaBackend | ||
|
||
|
||
def test_backend_authenticate_requires_code_and_nonce(rf): | ||
""" | ||
the authenticate method on the custom backend requires both | ||
an auth code and a nonce. If either aren't provided then | ||
authenitcate should return None | ||
""" | ||
backend = OktaBackend() | ||
assert backend.authenticate(rf) is None | ||
|
||
|
||
def test_authenticate_returns_a_user(rf, django_user_model): | ||
""" | ||
We can't do the real authentication but we do need to make sure a | ||
real user is returned from the backend authenticate method if the | ||
TokenValidator succeeds, so fake success and see what happens. | ||
""" | ||
user = django_user_model.objects.create_user("testuser", "testuser@example.com") | ||
|
||
with patch( | ||
"okta_oauth2.backend.TokenValidator.tokens_from_auth_code", | ||
Mock(return_value=(user, None)), | ||
): | ||
backend = OktaBackend() | ||
assert backend.authenticate(rf, auth_code="123456", nonce="imanonce") == user |
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,49 @@ | ||
import re | ||
|
||
import pytest | ||
from django.core.exceptions import ImproperlyConfigured | ||
from okta_oauth2.conf import Config | ||
from okta_oauth2.tests.utils import update_okta_settings | ||
|
||
|
||
def test_conf_raises_error_if_no_settings(settings): | ||
""" | ||
if there's no OKTA_AUTH in settings then we should | ||
be raising an ImproperlyConfigured exception. | ||
""" | ||
del settings.OKTA_AUTH | ||
with pytest.raises(ImproperlyConfigured): | ||
Config() | ||
|
||
|
||
def test_public_named_urls_are_built(settings): | ||
""" | ||
We should have reversed url regexes to match against | ||
in our config objects. | ||
""" | ||
settings.OKTA_AUTH = update_okta_settings( | ||
settings.OKTA_AUTH, "PUBLIC_NAMED_URLS", ("named-url",) | ||
) | ||
config = Config() | ||
assert config.public_urls == [ | ||
re.compile("^/named/$"), | ||
re.compile("^/accounts/login/$"), | ||
re.compile("^/accounts/logout/$"), | ||
re.compile("^/accounts/oauth2/callback/$"), | ||
] | ||
|
||
|
||
def test_invalid_public_named_urls_are_ignored(settings): | ||
""" | ||
We don't want to crash if our public named urls don't | ||
exist, instead just skip it. | ||
""" | ||
settings.OKTA_AUTH = update_okta_settings( | ||
settings.OKTA_AUTH, "PUBLIC_NAMED_URLS", ("not-a-valid-url",) | ||
) | ||
config = Config() | ||
assert config.public_urls == [ | ||
re.compile("^/accounts/login/$"), | ||
re.compile("^/accounts/logout/$"), | ||
re.compile("^/accounts/oauth2/callback/$"), | ||
] |
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
Oops, something went wrong.