diff --git a/e2e/dex/config-dev.yaml b/e2e/dex/config-dev.yaml deleted file mode 100644 index 277c631b9..000000000 --- a/e2e/dex/config-dev.yaml +++ /dev/null @@ -1,21 +0,0 @@ -enablePasswordDB: true -issuer: http://127.0.0.1:5556/dex -logger: - level: debug -staticClients: -- id: example-app - name: Example App - redirectURIs: - - http://localhost:37791/source/oauth/callback/dex/ - secret: ZXhhbXBsZS1hcHAtc2VjcmV0 -staticPasswords: -- email: admin@example.com - hash: $2a$10$2b2cU8CPhOTaGrs1HRQuAueS7JTT5ZHsHSzYiFPm1leZck7Mc8T4W - userID: 08a8684b-db88-4b73-90a9-3cd1661f5466 - username: admin -storage: - config: - file: /tmp/dex.db - type: sqlite3 -web: - http: 0.0.0.0:5556 diff --git a/e2e/test_sources_oauth.py b/e2e/test_sources_oauth.py index 40b8e8022..c0339f83d 100644 --- a/e2e/test_sources_oauth.py +++ b/e2e/test_sources_oauth.py @@ -31,14 +31,36 @@ class TestSourceOAuth(SeleniumTestCase): def prepare_dex_config(self): """Since Dex does not document which environment variables can be used to configure clients""" + config = { + "enablePasswordDB": True, + "issuer": "http://127.0.0.1:5556/dex", + "logger": {"level": "debug"}, + "staticClients": [ + { + "id": "example-app", + "name": "Example App", + "redirectURIs": [ + self.url( + "passbook_sources_oauth:oauth-client-callback", + source_slug="dex", + ) + ], + "secret": self.client_secret, + } + ], + "staticPasswords": [ + { + "email": "admin@example.com", + # hash for password + "hash": "$2a$10$2b2cU8CPhOTaGrs1HRQuAueS7JTT5ZHsHSzYiFPm1leZck7Mc8T4W", + "userID": "08a8684b-db88-4b73-90a9-3cd1661f5466", + "username": "admin", + } + ], + "storage": {"config": {"file": "/tmp/dex.db"}, "type": "sqlite3"}, + "web": {"http": "0.0.0.0:5556"}, + } config_file = "./e2e/dex/config-dev.yaml" - with open(config_file, "r+") as _file: - config = safe_load(_file) - client = config.get("staticClients")[0] - client["redirectURIs"][0] = self.url( - "passbook_sources_oauth:oauth-client-callback", source_slug="dex" - ) - client["secret"] = self.client_secret with open(config_file, "w+") as _file: safe_dump(config, _file) @@ -71,12 +93,8 @@ class TestSourceOAuth(SeleniumTestCase): return container sleep(1) - def tearDown(self): - self.container.kill() - super().tearDown() - - def test_oauth_oidc(self): - """test OAuth Source With With OIDC""" + def create_objects(self): + """Create required objects""" sleep(1) # Bootstrap all needed objects authentication_flow = Flow.objects.get(slug="default-source-authentication") @@ -95,6 +113,13 @@ class TestSourceOAuth(SeleniumTestCase): consumer_secret=self.client_secret, ) + def tearDown(self): + self.container.kill() + super().tearDown() + + def test_oauth_enroll(self): + """test OAuth Source With With OIDC""" + self.create_objects() self.driver.get(self.live_server_url) self.wait.until( diff --git a/passbook/sources/oauth/views/callback.py b/passbook/sources/oauth/views/callback.py index 1f547029c..a38781958 100644 --- a/passbook/sources/oauth/views/callback.py +++ b/passbook/sources/oauth/views/callback.py @@ -1,5 +1,5 @@ """OAuth Callback Views""" -from typing import Any, Callable, Dict, Optional +from typing import Any, Dict, Optional from django.conf import settings from django.contrib import messages @@ -7,7 +7,7 @@ from django.http import Http404, HttpRequest, HttpResponse from django.shortcuts import redirect from django.urls import reverse from django.utils.translation import ugettext as _ -from django.views.generic import RedirectView, View +from django.views.generic import View from structlog import get_logger from passbook.audit.models import Event, EventAction @@ -22,7 +22,6 @@ from passbook.flows.views import SESSION_KEY_PLAN from passbook.lib.utils.urls import redirect_with_qs from passbook.policies.utils import delete_none_keys from passbook.sources.oauth.auth import AuthorizedServiceBackend -from passbook.sources.oauth.clients import BaseOAuthClient, get_client from passbook.sources.oauth.models import OAuthSource, UserOAuthSourceConnection from passbook.sources.oauth.views.base import OAuthClientMixin from passbook.stages.password.stage import PLAN_CONTEXT_AUTHENTICATION_BACKEND diff --git a/passbook/sources/oauth/views/redirect.py b/passbook/sources/oauth/views/redirect.py index fc18ce8eb..a4ff16d25 100644 --- a/passbook/sources/oauth/views/redirect.py +++ b/passbook/sources/oauth/views/redirect.py @@ -1,32 +1,13 @@ """OAuth Redirect Views""" -from typing import Any, Callable, Dict, Optional +from typing import Any, Dict -from django.conf import settings -from django.contrib import messages -from django.http import Http404, HttpRequest, HttpResponse -from django.shortcuts import redirect +from django.http import Http404 from django.urls import reverse -from django.utils.translation import ugettext as _ -from django.views.generic import RedirectView, View +from django.views.generic import RedirectView from structlog import get_logger -from passbook.audit.models import Event, EventAction -from passbook.core.models import User -from passbook.flows.models import Flow -from passbook.flows.planner import ( - PLAN_CONTEXT_PENDING_USER, - PLAN_CONTEXT_SSO, - FlowPlanner, -) -from passbook.flows.views import SESSION_KEY_PLAN -from passbook.lib.utils.urls import redirect_with_qs -from passbook.policies.utils import delete_none_keys -from passbook.sources.oauth.auth import AuthorizedServiceBackend -from passbook.sources.oauth.clients import BaseOAuthClient, get_client -from passbook.sources.oauth.models import OAuthSource, UserOAuthSourceConnection +from passbook.sources.oauth.models import OAuthSource from passbook.sources.oauth.views.base import OAuthClientMixin -from passbook.stages.password.stage import PLAN_CONTEXT_AUTHENTICATION_BACKEND -from passbook.stages.prompt.stage import PLAN_CONTEXT_PROMPT LOGGER = get_logger()