Use source patient identity for breast follow-up
This commit is contained in:
@@ -1,38 +1,26 @@
|
||||
"""Verify the synthetic cohort's opt-in startup and server-side access check."""
|
||||
"""Exercise persistent cohort setup and its optional patient access boundary."""
|
||||
|
||||
import pytest
|
||||
from flask import Flask
|
||||
from flask import Flask, request
|
||||
|
||||
from webapi.cama_runtime import configure_cama_cohort
|
||||
|
||||
|
||||
def test_synthetic_cohort_requires_explicit_configuration(monkeypatch):
|
||||
"""Missing or short secrets must not silently enable patient access."""
|
||||
monkeypatch.delenv('CAMA_COHORT_SYNTHETIC', raising=False)
|
||||
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 'CAMA_COHORT_READER' not in app.config
|
||||
monkeypatch.setenv('CAMA_COHORT_SYNTHETIC', '1')
|
||||
monkeypatch.setenv('CAMA_COHORT_SECRET', 'short')
|
||||
monkeypatch.setenv('CAMA_COHORT_ACCESS_TOKEN', 't' * 32)
|
||||
with pytest.raises(ValueError):
|
||||
configure_cama_cohort(app)
|
||||
monkeypatch.setenv('CAMA_COHORT_SECRET', 's' * 32)
|
||||
monkeypatch.setenv('CAMA_COHORT_ACCESS_TOKEN', 't' * 32 + '";')
|
||||
with pytest.raises(ValueError):
|
||||
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):
|
||||
"""Only requests bearing the configured token can use the cohort patient routes."""
|
||||
monkeypatch.setenv('CAMA_COHORT_SYNTHETIC', '1')
|
||||
monkeypatch.setenv('CAMA_COHORT_SECRET', 's' * 32)
|
||||
"""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}):
|
||||
from flask import request
|
||||
assert app.config['CAMA_COHORT_ACCESS'](request)
|
||||
with app.test_request_context(headers={'X-Cama-Cohort-Token': 'incorrect'}):
|
||||
from flask import request
|
||||
assert not app.config['CAMA_COHORT_ACCESS'](request)
|
||||
|
||||
Reference in New Issue
Block a user