about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorClaude Sonnet 4.62026-09-02 17:12:09 +0000
committerFrederick Muriuki Muriithi2026-09-02 12:14:32 -0500
commit88b88bb52602f85de335de0bc45fabfcc7072b2d (patch)
treeeb0472e1d08d5f4b0c1d826956bd5f0c53905910 /tests
parent1ad5a66b33cd880234937fe2e069a09887698265 (diff)
downloadgn-integration-tests-88b88bb52602f85de335de0bc45fabfcc7072b2d.tar.gz
test(gn2): add auth-flow tests — unauthenticated redirect checks (Part 1)
Two tests covering @login_required enforcement on the metadata-edit
blueprint (prefix: /datasets/).  No credentials required — these fire
as part of the gn2 auth_flow suite.

  test_unauthenticated_display_phenotype_redirects
    GET /datasets/<dataset_id>/traits/<name> → 301/302 without session

  test_unauthenticated_update_phenotype_redirects
    POST /datasets/<dataset_id>/traits/<name> → 301/302 without session

Co-Authored-By: Frederick Muriuki Muriithi <fmuriit1@uthsc.edu>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_gn2_auth_flow.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/test_gn2_auth_flow.py b/tests/test_gn2_auth_flow.py
new file mode 100644
index 0000000..f6beddb
--- /dev/null
+++ b/tests/test_gn2_auth_flow.py
@@ -0,0 +1,61 @@
+"""
+Auth-flow integration tests for genenetwork2 protected endpoints.
+
+Part 1 — Unauthenticated redirect checks:
+    GN2's @login_required decorator redirects unauthenticated requests to the
+    home page ("/").  These tests verify that all protected endpoints in the
+    metadata-edit blueprint enforce that guard.  No credentials are required.
+
+Part 2 — gn-auth contract tests (auth_flow, credentials required):
+    GN2 calls back to gn-auth's POST /auth/data/authorisation and
+    GET /auth/resource/system/roles per-request.  These tests verify the
+    contracts that gn2 depends on.
+
+Blueprint prefix: /datasets/ (registered in wqflask/__init__.py)
+
+Run all:
+    pytest -m "gn2 and auth_flow"
+
+Run unauthenticated only (no credentials needed):
+    pytest -m "gn2 and auth_flow" -k "unauthenticated"
+"""
+import pytest
+
+pytestmark = [pytest.mark.gn2, pytest.mark.auth_flow]
+
+# Known-good values reused from the smoke test suite.
+_DATASET_ID = "HC_M2_0606_P"
+_TRAIT_NAME = "1435395_s_at"
+_RESOURCE_ID = "00000000-0000-0000-0000-000000000000"  # arbitrary; rejected before DB lookup
+_DIFF_NAME = "some-diff-name"
+
+
+# ---------------------------------------------------------------------------
+# Part 1: unauthenticated redirect — @login_required enforcement
+# ---------------------------------------------------------------------------
+
+def test_unauthenticated_display_phenotype_redirects(gn2_url, http):
+    """GET /datasets/<dataset_id>/traits/<name> redirects to / without a session."""
+    resp = http.get(
+        f"{gn2_url}/datasets/{_DATASET_ID}/traits/{_TRAIT_NAME}",
+        timeout=30,
+        allow_redirects=False,
+    )
+    assert resp.status_code in (301, 302), (
+        f"Expected redirect for unauthenticated phenotype-display, "
+        f"got {resp.status_code}: {resp.text[:200]}"
+    )
+
+
+def test_unauthenticated_update_phenotype_redirects(gn2_url, http):
+    """POST /datasets/<dataset_id>/traits/<name> redirects to / without a session."""
+    resp = http.post(
+        f"{gn2_url}/datasets/{_DATASET_ID}/traits/{_TRAIT_NAME}",
+        data={},
+        timeout=30,
+        allow_redirects=False,
+    )
+    assert resp.status_code in (301, 302), (
+        f"Expected redirect for unauthenticated phenotype-update, "
+        f"got {resp.status_code}: {resp.text[:200]}"
+    )