Skip to content

Commit 7d55be9

Browse files
authored
Fix: [AEA-0000] - Use the APIM required header, rather than the one notify want us to use. Also, parameterise notify enable flags (#1884)
## Summary - ⚠️ Potential issues that might be caused by this change ### Details In order to test our callback endpoint, we need to be able to actually use it. Since there's a mismatch between notify's spec, and APIM's capabilities, I'm making it align with APIM for now just so we can see how things behave. Also, moves the notification enabling flags to deployment parameters, and disables them both by default for prod/int
1 parent 4633233 commit 7d55be9

11 files changed

Lines changed: 82 additions & 32 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ jobs:
115115
ENABLE_ALERTS: true
116116
RUN_REGRESSION_TEST: true
117117
STATE_MACHINE_LOG_LEVEL: ALL
118+
ENABLE_NOTIFICATIONS_INTERNAL: true
119+
ENABLE_NOTIFICATIONS_EXTERNAL: false
118120
secrets:
119121
CLOUD_FORMATION_DEPLOY_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_DEPLOY_ROLE }}
120122
DEV_CLOUD_FORMATION_CHECK_VERSION_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_CHECK_VERSION_ROLE }}
@@ -144,6 +146,8 @@ jobs:
144146
DEPLOY_CHECK_PRESCRIPTION_STATUS_UPDATE: true
145147
RUN_REGRESSION_TEST: false
146148
STATE_MACHINE_LOG_LEVEL: ALL
149+
ENABLE_NOTIFICATIONS_INTERNAL: false
150+
ENABLE_NOTIFICATIONS_EXTERNAL: false
147151
secrets:
148152
REGRESSION_TESTS_PEM: ${{ secrets.REGRESSION_TESTS_PEM }}
149153
CLOUD_FORMATION_DEPLOY_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_DEPLOY_ROLE }}
@@ -170,6 +174,8 @@ jobs:
170174
ENABLE_ALERTS: true
171175
RUN_REGRESSION_TEST: true
172176
STATE_MACHINE_LOG_LEVEL: ALL
177+
ENABLE_NOTIFICATIONS_INTERNAL: false
178+
ENABLE_NOTIFICATIONS_EXTERNAL: false
173179
secrets:
174180
REGRESSION_TESTS_PEM: ${{ secrets.REGRESSION_TESTS_PEM }}
175181
CLOUD_FORMATION_DEPLOY_ROLE: ${{ secrets.QA_CLOUD_FORMATION_DEPLOY_ROLE }}

.github/workflows/pull_request.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ jobs:
7878
ENABLE_ALERTS: false
7979
RUN_REGRESSION_TEST: true
8080
STATE_MACHINE_LOG_LEVEL: ALL
81+
ENABLE_NOTIFICATIONS_INTERNAL: true
82+
ENABLE_NOTIFICATIONS_EXTERNAL: false
8183
secrets:
8284
CLOUD_FORMATION_DEPLOY_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_DEPLOY_ROLE }}
8385
PROXYGEN_ROLE: ${{ secrets.PROXYGEN_PTL_ROLE }}
@@ -103,6 +105,8 @@ jobs:
103105
DEPLOY_CHECK_PRESCRIPTION_STATUS_UPDATE: true
104106
RUN_REGRESSION_TEST: false
105107
STATE_MACHINE_LOG_LEVEL: ALL
108+
ENABLE_NOTIFICATIONS_INTERNAL: false
109+
ENABLE_NOTIFICATIONS_EXTERNAL: false
106110
secrets:
107111
CLOUD_FORMATION_DEPLOY_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_DEPLOY_ROLE }}
108112
PROXYGEN_ROLE: ${{ secrets.PROXYGEN_PTL_ROLE }}

.github/workflows/release.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ jobs:
134134
ENABLE_ALERTS: true
135135
RUN_REGRESSION_TEST: true
136136
STATE_MACHINE_LOG_LEVEL: ALL
137+
ENABLE_NOTIFICATIONS_INTERNAL: false
138+
ENABLE_NOTIFICATIONS_EXTERNAL: false
137139
secrets:
138140
CLOUD_FORMATION_DEPLOY_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_DEPLOY_ROLE }}
139141
DEV_CLOUD_FORMATION_CHECK_VERSION_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_CHECK_VERSION_ROLE }}
@@ -163,6 +165,8 @@ jobs:
163165
DEPLOY_CHECK_PRESCRIPTION_STATUS_UPDATE: true
164166
RUN_REGRESSION_TEST: false
165167
STATE_MACHINE_LOG_LEVEL: ALL
168+
ENABLE_NOTIFICATIONS_INTERNAL: false
169+
ENABLE_NOTIFICATIONS_EXTERNAL: false
166170
secrets:
167171
CLOUD_FORMATION_DEPLOY_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_DEPLOY_ROLE }}
168172
PROXYGEN_ROLE: ${{ secrets.PROXYGEN_PTL_ROLE }}
@@ -197,6 +201,8 @@ jobs:
197201
ENABLE_ALERTS: true
198202
RUN_REGRESSION_TEST: false
199203
STATE_MACHINE_LOG_LEVEL: ERROR
204+
ENABLE_NOTIFICATIONS_INTERNAL: false
205+
ENABLE_NOTIFICATIONS_EXTERNAL: false
200206
secrets:
201207
CLOUD_FORMATION_DEPLOY_ROLE: ${{ secrets.REF_CLOUD_FORMATION_DEPLOY_ROLE }}
202208
PROXYGEN_ROLE: ${{ secrets.PROXYGEN_PTL_ROLE }}
@@ -231,6 +237,8 @@ jobs:
231237
ENABLE_ALERTS: true
232238
RUN_REGRESSION_TEST: true
233239
STATE_MACHINE_LOG_LEVEL: ALL
240+
ENABLE_NOTIFICATIONS_INTERNAL: false
241+
ENABLE_NOTIFICATIONS_EXTERNAL: false
234242
secrets:
235243
CLOUD_FORMATION_DEPLOY_ROLE: ${{ secrets.QA_CLOUD_FORMATION_DEPLOY_ROLE }}
236244
PROXYGEN_ROLE: ${{ secrets.PROXYGEN_PTL_ROLE }}
@@ -260,6 +268,8 @@ jobs:
260268
ENABLE_ALERTS: true
261269
RUN_REGRESSION_TEST: true
262270
STATE_MACHINE_LOG_LEVEL: ALL
271+
ENABLE_NOTIFICATIONS_INTERNAL: false
272+
ENABLE_NOTIFICATIONS_EXTERNAL: false
263273
secrets:
264274
CLOUD_FORMATION_DEPLOY_ROLE: ${{ secrets.INT_CLOUD_FORMATION_DEPLOY_ROLE }}
265275
DEV_CLOUD_FORMATION_CHECK_VERSION_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_CHECK_VERSION_ROLE }}
@@ -289,6 +299,8 @@ jobs:
289299
DEPLOY_CHECK_PRESCRIPTION_STATUS_UPDATE: true
290300
RUN_REGRESSION_TEST: false
291301
STATE_MACHINE_LOG_LEVEL: ALL
302+
ENABLE_NOTIFICATIONS_INTERNAL: false
303+
ENABLE_NOTIFICATIONS_EXTERNAL: false
292304
secrets:
293305
CLOUD_FORMATION_DEPLOY_ROLE: ${{ secrets.INT_CLOUD_FORMATION_DEPLOY_ROLE }}
294306
PROXYGEN_ROLE: ${{ secrets.PROXYGEN_PROD_ROLE }}
@@ -325,6 +337,8 @@ jobs:
325337
ENABLE_ALERTS: true
326338
RUN_REGRESSION_TEST: false
327339
STATE_MACHINE_LOG_LEVEL: ERROR
340+
ENABLE_NOTIFICATIONS_INTERNAL: false
341+
ENABLE_NOTIFICATIONS_EXTERNAL: false
328342
secrets:
329343
CLOUD_FORMATION_DEPLOY_ROLE: ${{ secrets.PROD_CLOUD_FORMATION_DEPLOY_ROLE }}
330344
DEV_CLOUD_FORMATION_CHECK_VERSION_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_CHECK_VERSION_ROLE }}

.github/workflows/run_release_code_and_api.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ on:
7070
STATE_MACHINE_LOG_LEVEL:
7171
required: true
7272
type: string
73+
ENABLE_NOTIFICATIONS_INTERNAL:
74+
required: false
75+
type: boolean
76+
default: false
77+
ENABLE_NOTIFICATIONS_EXTERNAL:
78+
required: false
79+
type: boolean
80+
default: false
7381
secrets:
7482
CLOUD_FORMATION_DEPLOY_ROLE:
7583
required: true
@@ -155,6 +163,8 @@ jobs:
155163
DEPLOY_CHECK_PRESCRIPTION_STATUS_UPDATE: ${{ inputs.DEPLOY_CHECK_PRESCRIPTION_STATUS_UPDATE }}
156164
ENABLE_ALERTS: ${{ inputs.ENABLE_ALERTS }}
157165
STATE_MACHINE_LOG_LEVEL: ${{ inputs.STATE_MACHINE_LOG_LEVEL }}
166+
ENABLE_NOTIFICATIONS_INTERNAL: ${{ inputs.ENABLE_NOTIFICATIONS_INTERNAL }}
167+
ENABLE_NOTIFICATIONS_EXTERNAL: ${{ inputs.ENABLE_NOTIFICATIONS_EXTERNAL }}
158168
run: ./release_code.sh
159169

160170
- name: get mtls secrets

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ sam-deploy-package: guard-artifact_bucket guard-artifact_bucket_prefix guard-sta
9797
Environment=$$TARGET_ENVIRONMENT \
9898
DeployCheckPrescriptionStatusUpdate=$$DEPLOY_CHECK_PRESCRIPTION_STATUS_UPDATE \
9999
EnableAlerts=$$ENABLE_ALERTS \
100-
StateMachineLogLevel=$$STATE_MACHINE_LOG_LEVEL
100+
StateMachineLogLevel=$$STATE_MACHINE_LOG_LEVEL \
101+
EnableNotificationsInternal=$$ENABLE_NOTIFICATIONS_INTERNAL \
102+
EnableNotificationsExternal=$$ENABLE_NOTIFICATIONS_EXTERNAL
101103

102104
compile-node:
103105
npx tsc --build tsconfig.build.json

SAMtemplates/functions/main.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Parameters:
5151
NotifyAPIBaseURLParam:
5252
Type: AWS::SSM::Parameter::Name<String>
5353

54-
EnableNotificationExternalLinkParam:
54+
EnableNotificationsExternalParam:
5555
Type: AWS::SSM::Parameter::Name<String>
5656

5757
EnableNotificationsInternalParam:
@@ -407,7 +407,7 @@ Resources:
407407
KID_SECRET: secrets-PSU-Notify-Application-Name
408408
NHS_NOTIFY_ROUTING_ID_PARAM: !Ref NotifyRoutingPlanIDParam
409409
NOTIFY_API_BASE_URL_PARAM: !Ref NotifyAPIBaseURLParam
410-
MAKE_REAL_NOTIFY_REQUESTS_PARAM: !Ref EnableNotificationExternalLinkParam
410+
MAKE_REAL_NOTIFY_REQUESTS_PARAM: !Ref EnableNotificationsExternalParam
411411
Events:
412412
ScheduleEvent:
413413
Type: ScheduleV2

SAMtemplates/main_template.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ Parameters:
8989
StateMachineLogLevel:
9090
Type: String
9191

92+
EnableNotificationsInternal:
93+
Type: String
94+
Default: false
95+
AllowedValues:
96+
- true
97+
- false
98+
99+
EnableNotificationsExternal:
100+
Type: String
101+
Default: false
102+
AllowedValues:
103+
- true
104+
- false
105+
92106
Resources:
93107
Secrets:
94108
Type: AWS::Serverless::Application
@@ -104,6 +118,8 @@ Resources:
104118
Parameters:
105119
StackName: !Ref AWS::StackName
106120
Environment: !Ref Environment
121+
EnableNotificationsInternalValue: !Ref EnableNotificationsInternal
122+
EnableNotificationsExternalValue: !Ref EnableNotificationsExternal
107123

108124
Tables:
109125
Type: AWS::Serverless::Application
@@ -159,7 +175,7 @@ Resources:
159175
BlockedSiteODSCodesParam: !GetAtt Parameters.Outputs.BlockedSiteODSCodesParameterName
160176
NotifyRoutingPlanIDParam: !GetAtt Parameters.Outputs.NotifyRoutingPlanIDParameterName
161177
NotifyAPIBaseURLParam: !GetAtt Parameters.Outputs.NotifyAPIBaseURLParameterName
162-
EnableNotificationExternalLinkParam: !GetAtt Parameters.Outputs.EnableNotificationExternalLinkName
178+
EnableNotificationsExternalParam: !GetAtt Parameters.Outputs.EnableNotificationsExternalName
163179
EnableNotificationsInternalParam: !GetAtt Parameters.Outputs.EnableNotificationsInternalName
164180
LogLevel: !Ref LogLevel
165181
LogRetentionInDays: !Ref LogRetentionInDays

SAMtemplates/parameters/main.yaml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ Parameters:
99
Environment:
1010
Type: String
1111

12+
EnableNotificationsInternalValue:
13+
Type: String
14+
Default: false
15+
AllowedValues:
16+
- true
17+
- false
18+
19+
EnableNotificationsExternalValue:
20+
Type: String
21+
Default: false
22+
AllowedValues:
23+
- true
24+
- false
25+
1226
Conditions:
1327
IsProd: !Equals [ !Ref Environment, prod ]
1428

@@ -83,21 +97,21 @@ Resources:
8397
# Non-prod API URL (sandbox) (INT environment: https://int.api.service.nhs.uk/comms)
8498
- https://sandbox.api.service.nhs.uk/comms
8599

86-
EnableNotificationExternalLink:
100+
EnableNotificationsExternal:
87101
Type: AWS::SSM::Parameter
88102
Properties:
89-
Name: !Sub ${StackName}-EnableNotificationExternalLink
103+
Name: !Sub ${StackName}-EnableNotificationsExternal
90104
Description: "Toggle on or off if we make real requests to the NHS notify service"
91105
Type: String
92-
Value: "false"
106+
Value: !Ref EnableNotificationsExternalValue
93107

94108
EnableNotificationsInternal:
95109
Type: AWS::SSM::Parameter
96110
Properties:
97111
Name: !Sub ${StackName}-EnableNotificationsInternal
98112
Description: "Toggle the notifications integration entirely"
99113
Type: String
100-
Value: "true"
114+
Value: !Ref EnableNotificationsInternalValue
101115

102116
GetNotificationsParameterPolicy:
103117
Type: AWS::IAM::ManagedPolicy
@@ -116,7 +130,7 @@ Resources:
116130
- !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${StackName}-PSUNotifyBlockedSiteODSCodes
117131
- !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${StackName}-PSUNotifyRoutingPlanID
118132
- !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${StackName}-PSUNotifyApiBaseUrl
119-
- !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${StackName}-EnableNotificationExternalLink
133+
- !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${StackName}-EnableNotificationsExternal
120134
- !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${StackName}-EnableNotificationsInternal
121135

122136

@@ -151,11 +165,11 @@ Outputs:
151165
Export:
152166
Name: !Sub ${StackName}-PSUNotifyApiBaseUrlParam
153167

154-
EnableNotificationExternalLinkName:
168+
EnableNotificationsExternalName:
155169
Description: "Name of the SSM parameter holding the Notify API Base URL"
156-
Value: !Ref EnableNotificationExternalLink
170+
Value: !Ref EnableNotificationsExternal
157171
Export:
158-
Name: !Sub ${StackName}-EnableNotificationExternalLinkName
172+
Name: !Sub ${StackName}-EnableNotificationsExternalName
159173

160174
EnableNotificationsInternalName:
161175
Description: "Name of the SSM parameter holding the Notify API Base URL"

packages/nhsNotifyUpdateCallback/src/helpers.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ export async function checkSignature(logger: Logger, event: APIGatewayProxyEvent
8989
return response(401, {message: "No x-hmac-sha256-signature given"})
9090
}
9191

92-
const givenApiKey = event.headers["x-api-key"]
93-
if (!givenApiKey) {
94-
logger.error("No x-api-key header given")
95-
return response(401, {message: "No x-api-key header given"})
96-
}
97-
9892
// Compute the HMAC-SHA256 hash of the combination of the request body and the secret value
9993
const secretValue = `${APP_NAME}.${API_KEY}`
10094
const payload = event.body ?? ""

packages/nhsNotifyUpdateCallback/tests/testHelpers.test.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,35 +66,25 @@ describe("helpers.ts", () => {
6666

6767
describe("checkSignature()", () => {
6868
let logger: Logger
69-
let validHeaders: { "x-request-id": string; "x-api-key": string; "x-hmac-sha256-signature": string }
69+
let validHeaders: { "x-request-id": string; "apikey": string; "x-hmac-sha256-signature": string }
7070
beforeEach(() => {
7171
logger = new Logger({serviceName: "nhsNotifyUpdateCallback"})
7272
validHeaders = {
7373
"x-request-id": "requestid",
74-
"x-api-key": "api-key",
74+
"apikey": "api-key", // TODO: Should be x-api-key
7575
"x-hmac-sha256-signature": "deadbeef"
7676
}
7777
})
7878

7979
it("401 when missing signature header", async () => {
80-
const ev = generateMockEvent("{}", {"x-api-key": "foobar", "x-request-id": "rid"})
80+
const ev = generateMockEvent("{}", {"apikey": "foobar", "x-request-id": "rid"}) // TODO: Should be x-api-key
8181
const resp = await checkSignature(logger, ev)
8282
expect(resp).toEqual({
8383
statusCode: 401,
8484
body: JSON.stringify({message: "No x-hmac-sha256-signature given"})
8585
})
8686
})
8787

88-
it("401 when missing API key header", async () => {
89-
const ev = generateMockEvent("{}", {"x-hmac-sha256-signature": "foobar", "x-request-id": "rid"})
90-
const resp = await checkSignature(logger, ev)
91-
92-
expect(resp).toEqual({
93-
statusCode: 401,
94-
body: JSON.stringify({message: "No x-api-key header given"})
95-
})
96-
})
97-
9888
it("403 when signature hex is malformed", async () => {
9989
const headers = {
10090
...validHeaders,

0 commit comments

Comments
 (0)