Files
WebApi/tests/test_cama_runtime.py
T
2026-11-13 17:38:19 -06:00

27 lines
1.2 KiB
Python

"""Exercise persistent cohort setup and its optional patient access boundary."""
from flask import Flask, request
from webapi.cama_runtime import configure_cama_cohort
def test_missing_or_invalid_token_does_not_prevent_startup(monkeypatch):
"""A malformed optional credential leaves the reader registered and access denied."""
monkeypatch.setenv('CAMA_COHORT_ACCESS_TOKEN', 'short')
app = Flask(__name__)
configure_cama_cohort(app)
assert callable(app.config['CAMA_COHORT_READER'])
with app.test_request_context(headers={'X-Cama-Cohort-Token': 'short'}):
assert not app.config['CAMA_COHORT_ACCESS'](request)
def test_access_token_is_checked_on_the_server(monkeypatch):
"""The retained proxy credential gates patient routes until a shared boundary is available."""
monkeypatch.setenv('CAMA_COHORT_ACCESS_TOKEN', 't' * 32)
app = Flask(__name__)
configure_cama_cohort(app)
with app.test_request_context(headers={'X-Cama-Cohort-Token': 't' * 32}):
assert app.config['CAMA_COHORT_ACCESS'](request)
with app.test_request_context(headers={'X-Cama-Cohort-Token': 'incorrect'}):
assert not app.config['CAMA_COHORT_ACCESS'](request)