-
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.
- Loading branch information
Showing
6 changed files
with
1,231 additions
and
0 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
559 changes: 559 additions & 0 deletions
559
...ion_multiple_configs/test_use_config_class_from_state_over_config_class_from_session.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
556 changes: 556 additions & 0 deletions
556
tests/cassettes/test_integration_oidc_flow_variants/test_session_refresh.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
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,48 @@ | ||
from django.test import Client | ||
from django.urls import reverse | ||
|
||
import pytest | ||
from requests import Session | ||
|
||
from mozilla_django_oidc_db.models import OpenIDConnectConfig | ||
|
||
from .utils import keycloak_login | ||
|
||
|
||
@pytest.mark.vcr | ||
@pytest.mark.oidcconfig(make_users_staff=True) | ||
def test_use_config_class_from_state_over_config_class_from_session( | ||
keycloak_config: OpenIDConnectConfig, | ||
mock_state_and_nonce, | ||
client: Client, | ||
): | ||
""" | ||
When using two different OIDC configs, ensure that their state doesn't get mixed up. | ||
First, we authenticate in the django admin, this is the config that uses the | ||
session refresh, and the config set up through fixtures. | ||
Second, we have another OIDC config that uses another provider. The state of the | ||
first authentication may not affect the second authentication flow. | ||
""" | ||
session = Session() | ||
# login to the admin | ||
login_url = reverse("login") | ||
django_login_response = client.get(login_url) | ||
redirect_uri = keycloak_login(django_login_response["Location"], session=session) | ||
callback_response = client.get(redirect_uri, follow=True) | ||
# sanity check | ||
assert callback_response.wsgi_request.path == reverse("admin:index") | ||
|
||
# set up an authentication flow & state with another config - all the credentials | ||
# are otherwise the same - the only difference is where the callback redirects after | ||
# succesful authentication | ||
login_url2 = reverse("custom-init-login") | ||
django_login_response2 = client.get(login_url2) | ||
# we expect to still be authenticated in the keycloak session, so we can fetch the | ||
# URL directly - and perform a sanity check! | ||
_response = session.get(django_login_response2["Location"], allow_redirects=False) | ||
redirect_uri2 = _response.headers["Location"] | ||
assert redirect_uri2.startswith("http://testserver/") | ||
callback_response2 = client.get(redirect_uri2, follow=True) | ||
assert callback_response2.wsgi_request.path == "/custom-success-url" |
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