@@ -92,6 +92,84 @@ def get_eligibility_status(
9292 raise ValueError
9393
9494
95+ def test_security_headers_present_on_successful_response (app : Flask , client : FlaskClient ):
96+ """Test that security headers are present on successful eligibility check response."""
97+ # Given
98+ with (
99+ get_app_container (app ).override .service (EligibilityService , new = FakeEligibilityService ()),
100+ get_app_container (app ).override .service (AuditService , new = FakeAuditService ()),
101+ ):
102+ # When
103+ headers = {"nhs-login-nhs-number" : "9876543210" }
104+ response = client .get ("/patient-check/9876543210" , headers = headers )
105+
106+ # Then
107+ assert_that (
108+ response ,
109+ is_response ()
110+ .with_status_code (HTTPStatus .OK )
111+ .with_headers (
112+ has_entries (
113+ {
114+ "Cache-Control" : "no-store, private" ,
115+ "Strict-Transport-Security" : "max-age=31536000; includeSubDomains" ,
116+ "X-Content-Type-Options" : "nosniff" ,
117+ }
118+ )
119+ ),
120+ )
121+
122+
123+ def test_security_headers_present_on_error_response (app : Flask , client : FlaskClient ):
124+ """Test that security headers are present on error response."""
125+ # Given
126+ with (
127+ get_app_container (app ).override .service (EligibilityService , new = FakeUnknownPersonEligibilityService ()),
128+ get_app_container (app ).override .service (AuditService , new = FakeAuditService ()),
129+ ):
130+ # When
131+ headers = {"nhs-login-nhs-number" : "9876543210" }
132+ response = client .get ("/patient-check/9876543210" , headers = headers )
133+
134+ # Then
135+ assert_that (
136+ response ,
137+ is_response ()
138+ .with_status_code (HTTPStatus .NOT_FOUND )
139+ .with_headers (
140+ has_entries (
141+ {
142+ "Cache-Control" : "no-store, private" ,
143+ "Strict-Transport-Security" : "max-age=31536000; includeSubDomains" ,
144+ "X-Content-Type-Options" : "nosniff" ,
145+ }
146+ )
147+ ),
148+ )
149+
150+
151+ def test_security_headers_present_on_status_endpoint (client : FlaskClient ):
152+ """Test that security headers are present on health check endpoint."""
153+ # When
154+ response = client .get ("/patient-check/_status" )
155+
156+ # Then
157+ assert_that (
158+ response ,
159+ is_response ()
160+ .with_status_code (HTTPStatus .OK )
161+ .with_headers (
162+ has_entries (
163+ {
164+ "Cache-Control" : "no-store, private" ,
165+ "Strict-Transport-Security" : "max-age=31536000; includeSubDomains" ,
166+ "X-Content-Type-Options" : "nosniff" ,
167+ }
168+ )
169+ ),
170+ )
171+
172+
95173def test_nhs_number_given (app : Flask , client : FlaskClient ):
96174 # Given
97175 with (
0 commit comments