Use shared access for synthetic breast follow-up

This commit is contained in:
Angel Capetillo Zavala
2026-11-13 17:54:56 -06:00
parent 9c0e03f947
commit 46eb3dfc31
9 changed files with 35 additions and 71 deletions
+9 -22
View File
@@ -1,38 +1,25 @@
"""Exercise persistent cohort setup and its optional patient access boundary."""
"""Verify default persistent cohort setup with retained legacy configuration."""
from flask import Flask, request
from flask import Flask
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')
def test_default_reader_uses_shared_persistence(monkeypatch):
"""The reader is registered without special cohort environment variables."""
for key in ('CAMA_COHORT_SYNTHETIC', 'CAMA_COHORT_SECRET', 'CAMA_COHORT_ACCESS_TOKEN'):
monkeypatch.delenv(key, raising=False)
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)
assert 'CAMA_COHORT_ACCESS' not in app.config
def test_application_starts_with_retained_obsolete_configuration(monkeypatch):
"""Old synthetic settings or a bad token cannot prevent the health endpoint starting."""
"""Retained synthetic settings cannot prevent the health endpoint starting."""
monkeypatch.setenv('CAMA_COHORT_SYNTHETIC', '1')
monkeypatch.delenv('CAMA_COHORT_SECRET', raising=False)
monkeypatch.setenv('CAMA_COHORT_ACCESS_TOKEN', 'invalid')
from webapi import create_app
client = create_app().test_client()
assert client.get('/health').get_json() == {'status': 'ok'}
assert client.get('/cama/seguimiento').status_code == 403
assert create_app().test_client().get('/health').get_json() == {'status': 'ok'}