Skip to content
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

Pin oauth_tools version #340

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 31 additions & 24 deletions tests/integration/test_grafana_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

import logging
from pathlib import Path
from helpers import oci_image

import os
Expand All @@ -17,19 +18,18 @@
from playwright.async_api._generated import Page, BrowserContext
from pytest_operator.plugin import OpsTest

from oauth_tools.dex import ExternalIdpManager
from oauth_tools.oauth_test_helper import (
from oauth_tools import (
deploy_identity_bundle,
get_reverse_proxy_app_url,
complete_external_idp_login,
complete_auth_code_login,
access_application_login_page,
click_on_sign_in_button_by_text,
verify_page_loads,
get_cookie_from_browser_by_name,
ExternalIdpService,
)
from oauth_tools.conftest import * # noqa
from oauth_tools.constants import EXTERNAL_USER_EMAIL, APPS

pytest_plugins = ["oauth_tools.fixtures"]
logger = logging.getLogger(__name__)

tester_resources = {
Expand All @@ -45,11 +45,19 @@

@pytest.mark.skip_if_deployed
@pytest.mark.abort_on_fail
async def test_build_and_deploy(ops_test: OpsTest, grafana_charm):
async def test_build_and_deploy(
ops_test: OpsTest,
grafana_charm: Path,
hydra_app_name: str,
public_traefik_app_name: str,
self_signed_certificates_app_name: str,
ext_idp_service: ExternalIdpService,
):
# Instantiating the ExternalIdpManager object deploys the external identity provider.
external_idp_manager = ExternalIdpManager(ops_test=ops_test)

await deploy_identity_bundle(ops_test=ops_test, external_idp_manager=external_idp_manager)
await deploy_identity_bundle(
ops_test=ops_test, bundle_channel="0.2/edge", ext_idp_service=ext_idp_service
)

# Deploy grafana
await ops_test.model.deploy(
Expand All @@ -60,15 +68,15 @@ async def test_build_and_deploy(ops_test: OpsTest, grafana_charm):
)

# Integrate grafana with the identity bundle
await ops_test.model.integrate("grafana:oauth", APPS.HYDRA)
await ops_test.model.integrate("grafana:ingress", APPS.TRAEFIK_PUBLIC)
await ops_test.model.integrate("grafana:receive-ca-cert", APPS.SELF_SIGNED_CERTIFICATES)
await ops_test.model.integrate("grafana:oauth", hydra_app_name)
await ops_test.model.integrate("grafana:ingress", public_traefik_app_name)
await ops_test.model.integrate("grafana:receive-ca-cert", self_signed_certificates_app_name)

await ops_test.model.wait_for_idle(
apps=[
APPS.HYDRA,
APPS.TRAEFIK_PUBLIC,
APPS.SELF_SIGNED_CERTIFICATES,
hydra_app_name,
public_traefik_app_name,
self_signed_certificates_app_name,
"grafana",
],
status="active",
Expand All @@ -79,11 +87,14 @@ async def test_build_and_deploy(ops_test: OpsTest, grafana_charm):


async def test_oauth_login_with_identity_bundle(
ops_test: OpsTest, page: Page, context: BrowserContext
ops_test: OpsTest,
page: Page,
context: BrowserContext,
public_traefik_app_name: str,
user_email: str,
ext_idp_service: ExternalIdpService,
) -> None:
external_idp_manager = ExternalIdpManager(ops_test=ops_test)

grafana_proxy = await get_reverse_proxy_app_url(ops_test, APPS.TRAEFIK_PUBLIC, "grafana")
grafana_proxy = await get_reverse_proxy_app_url(ops_test, public_traefik_app_name, "grafana")
redirect_login = os.path.join(grafana_proxy, "login")

await access_application_login_page(
Expand All @@ -94,9 +105,7 @@ async def test_oauth_login_with_identity_bundle(
page=page, text="Sign in with external identity provider"
)

await complete_external_idp_login(
page=page, ops_test=ops_test, external_idp_manager=external_idp_manager
)
await complete_auth_code_login(page=page, ops_test=ops_test, ext_idp_service=ext_idp_service)

redirect_url = os.path.join(grafana_proxy, "?*")
await verify_page_loads(page=page, url=redirect_url)
Expand All @@ -112,6 +121,4 @@ async def test_oauth_login_with_identity_bundle(
verify=False,
)
assert request.status_code == 200
assert request.json()["email"] == EXTERNAL_USER_EMAIL

external_idp_manager.remove_idp_service()
assert request.json()["email"] == user_email
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ deps =
juju<=3.3.0,>=3.0
pytest<8.2.0 # https://github.com/pytest-dev/pytest/issues/12263
pytest-operator
pytest-playwright
lightkube
git+https://github.com/canonical/iam-bundle@671a33419869fab1fe63d81873b41f6b181498e3#egg=oauth_tools
git+https://github.com/canonical/iam-bundle@oauth_tools-v0.1.0#egg=oauth_tools
commands =
playwright install
pytest -vv --tb native --log-cli-level=INFO --color=yes -s {posargs} {toxinidir}/tests/integration
Loading