@@ -40,7 +40,12 @@ vi.mock("../../src/config", async (importOriginal) => {
4040 }
4141} )
4242
43- function createSpec ( ) {
43+ type SpecOverrides = {
44+ securitySchemes ?: Record < string , unknown > ,
45+ paths ?: Record < string , unknown >
46+ }
47+
48+ function createSpec ( overrides : SpecOverrides = { } ) {
4449 return {
4550 info : { title : "EPS API" , version : "0.0.1" } ,
4651 "x-nhsd-apim" : {
@@ -52,10 +57,9 @@ function createSpec() {
5257 "target-attributes" : { app : "eps" }
5358 } ,
5459 components : {
55- securitySchemes : {
56- "nhs-cis2-aal3" : { }
57- }
60+ securitySchemes : overrides . securitySchemes || { "nhs-cis2-aal3" : { } }
5861 } ,
62+ paths : overrides . paths || { } ,
5963 servers : [ ]
6064 }
6165}
@@ -80,6 +84,7 @@ function buildConfig(overrides: Partial<ApiConfig> = {}): ApiConfig {
8084 clientPrivateKeyExportName : "clientKey" ,
8185 proxygenPrivateKeyExportName : "proxygenKey" ,
8286 proxygenKid : "kid-123" ,
87+ hiddenPaths : [ ] ,
8388 ...overrides
8489 }
8590}
@@ -211,6 +216,60 @@ describe("deployApi", () => {
211216 . toBe ( "https://sandbox.api.service.nhs.uk/eps" )
212217 } )
213218
219+ test ( "replaces all supported security scheme refs" , async ( ) => {
220+ const spec = createSpec ( {
221+ securitySchemes : {
222+ "nhs-cis2-aal3" : { } ,
223+ "nhs-login-p9" : { } ,
224+ "app-level3" : { } ,
225+ "app-level0" : { }
226+ }
227+ } )
228+ await deployApi (
229+ buildConfig ( {
230+ specification : JSON . stringify ( spec ) ,
231+ apigeeEnvironment : "prod" ,
232+ awsEnvironment : "prod" ,
233+ stackName : "eps-prod-stack" ,
234+ proxygenKid : "kid-prod"
235+ } ) ,
236+ false
237+ )
238+ const specPayload = payloadFromCall ( 1 )
239+ const schemes = [
240+ "nhs-cis2-aal3" ,
241+ "nhs-login-p9" ,
242+ "app-level3" ,
243+ "app-level0"
244+ ]
245+ for ( const scheme of schemes ) {
246+ expect ( specPayload . specDefinition . components . securitySchemes [ scheme ] . $ref )
247+ . toBe ( `https://proxygen.prod.api.platform.nhs.uk/components/securitySchemes/${ scheme } ` )
248+ }
249+ } )
250+
251+ test ( "removes hidden paths from published spec" , async ( ) => {
252+ const spec = createSpec ( {
253+ paths : {
254+ "/visible" : { get : { } } ,
255+ "/hidden" : { post : { } }
256+ }
257+ } )
258+ await deployApi (
259+ buildConfig ( {
260+ specification : JSON . stringify ( spec ) ,
261+ apigeeEnvironment : "int" ,
262+ stackName : "eps-int-stack" ,
263+ proxygenKid : "kid-int" ,
264+ hiddenPaths : [ "/hidden" ]
265+ } ) ,
266+ false
267+ )
268+ const publishPayload = payloadFromCall ( 2 )
269+ expect ( publishPayload . specDefinition . paths [ "/hidden" ] ) . toBeUndefined ( )
270+ expect ( publishPayload . specDefinition . paths [ "/visible" ] ) . toBeDefined ( )
271+ } )
272+
214273 test ( "dry run only logs intended invocations" , async ( ) => {
215274 const logSpy = vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => undefined )
216275
0 commit comments