From 81f5379912e6aa999acddc7f5356efd3f46ccd33 Mon Sep 17 00:00:00 2001 From: Bheesham Persaud Date: Wed, 30 Oct 2024 16:47:58 -0400 Subject: [PATCH] Tests for dashboard.vanity.Router We're now up to 54% test coverage! Jira: OPS-1443 --- tests/data/apps.yml | 39 ++++++++++++++++++++++++++++++++ tests/test_vanity.py | 53 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 tests/data/apps.yml create mode 100644 tests/test_vanity.py diff --git a/tests/data/apps.yml b/tests/data/apps.yml new file mode 100644 index 00000000..7ac0283b --- /dev/null +++ b/tests/data/apps.yml @@ -0,0 +1,39 @@ +# Copied a snapshot from https://github.com/mozilla-iam/sso-dashboard-configuration/ +apps: +- application: + authorized_groups: + - mozilliansorg_netlify-access + authorized_users: [] + client_id: client-id-for-netlify + display: true + logo: netlify.png + name: Netlify + op: auth0 + url: https://api.netlify.com/saml/mozilla-it/init + vanity_url: + - /netlify +- application: + authorized_groups: + - team_moco + - team_mofo + - team_mzla + authorized_users: [] + display: true + logo: accountmanager.png + name: Account Portal + op: auth0 + url: https://login.mozilla.com/ + vanity_url: + - /accountmanager +- application: + authorized_groups: + - mozilliansorg_acoustic_production_access + authorized_users: [] + client_id: client-id-for-acoustic + display: true + logo: acoustic.png + name: Acoustic + op: auth0 + url: https://auth.mozilla.auth0.com/samlp/sBImsybtPPLyWlstD0SC35IwnAafE4nB + vanity_url: + - /acoustic diff --git a/tests/test_vanity.py b/tests/test_vanity.py new file mode 100644 index 00000000..bb1e9df8 --- /dev/null +++ b/tests/test_vanity.py @@ -0,0 +1,53 @@ +from pathlib import Path +import pytest +from flask import Flask +from dashboard import config +from dashboard import vanity +from dashboard.models import tile +from dashboard.op import yaml_loader + + +@pytest.fixture +def externals(monkeypatch): + # Internal to the way dashboard.models.tile.CDNTransfer works. + models_dir = Path(__file__).parent / "models" + monkeypatch.setattr("os.path.dirname", lambda _: models_dir) + # Internal to how Configs work. + monkeypatch.setenv("SSO-DASHBOARD_REDIS_CONNECTOR", "foobar") + monkeypatch.setenv("SSO-DASHBOARD_SECRET_KEY", "deadbeef") + monkeypatch.setenv("SSO-DASHBOARD_S3_BUCKET", "") + monkeypatch.setenv("SSO-DASHBOARD_FORBIDDEN_PAGE_PUBLIC_KEY", "") + monkeypatch.setenv("SSO-DASHBOARD_CDN", "https://localhost") + + +@pytest.fixture +def app_config(externals): + return config.Default() + + +@pytest.fixture +def dashboard_app(app_config): + """ + A mini instance of the app. + """ + app = Flask("dashboard") + app.config.from_object(app_config) + yield app + + +@pytest.fixture +def cdn(app_config): + return tile.CDNTransfer(app_config) + + +@pytest.fixture +def client(dashboard_app): + return dashboard_app.test_client() + + +class TestVanity: + def test_router(self, dashboard_app, cdn, client): + router = vanity.Router(dashboard_app, cdn) + router.setup() + response = client.get("/netlify") + assert response.status_code == 301, "Did not properly redirect vanity URL"