generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
CCM-15215 - Sign callback payloads #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,224
−707
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
bcbdd9e
CCM-15215 - Sign callback payloads
rhyscoxnhs c29d03d
CCM-15215 - Adjusted terraform config
rhyscoxnhs 504409b
CCM-15215 - PR feedback
rhyscoxnhs bc16bee
Feedback: Set env vars in index.component.test before module import
mjewildnhs 0e63036
Feedback: Invalid JSON handling
mjewildnhs 61641c1
Trivy: Override fast-xml-parser version
mjewildnhs 6f655ff
Add the headers to the event pipeline template
mjewildnhs c2e5a9d
Feedback: validate APPLICATIONS_MAP_PARAMETER and cleanup application…
mjewildnhs 7f9b2bd
Feedback: refactor client config load so cache can be used in both si…
mjewildnhs c31683c
Feedback: replace crypto-js dependency
mjewildnhs 4c2c81d
Log SQS send in integration tests at info level for easier debugging
mjewildnhs 607c188
Remove unnecessary deploy_mock_webhook override now we've configured …
mjewildnhs 8756f84
fixup! Feedback: Set env vars in index.component.test before module i…
mjewildnhs 00292ff
Assert hmac signature is received in mock webhook
mjewildnhs 5b48e62
Default project and component vars in ITs as they won't change
mjewildnhs 07b514e
minor comment changes
cgitim 0224e72
remove TODO
cgitim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
infrastructure/terraform/components/callbacks/ssm_parameter_applications_map.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| resource "aws_ssm_parameter" "applications_map" { | ||
| name = local.applications_map_parameter_name | ||
| type = "SecureString" | ||
| key_id = module.kms.key_arn | ||
|
|
||
| value = var.deploy_mock_webhook ? jsonencode({ | ||
| "mock-client" = "mock-application-id" | ||
| }) : jsonencode({}) | ||
|
|
||
| lifecycle { | ||
| ignore_changes = [value] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
lambdas/client-transform-filter-lambda/src/__tests__/services/payload-signer.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { createHmac } from "node:crypto"; | ||
| import type { ClientCallbackPayload } from "@nhs-notify-client-callbacks/models"; | ||
| import { signPayload } from "services/payload-signer"; | ||
|
|
||
| const makePayload = (id = "msg-1") => | ||
| ({ data: [{ id }] }) as unknown as ClientCallbackPayload; | ||
|
|
||
| describe("signPayload", () => { | ||
| it("produces the expected HMAC-SHA256 hex string", () => { | ||
| const payload = makePayload(); | ||
| const applicationId = "app-id-1"; | ||
| const apiKey = "api-key-1"; | ||
|
|
||
| const expected = createHmac("sha256", `${applicationId}.${apiKey}`) | ||
| .update(JSON.stringify(payload)) | ||
| .digest("hex"); | ||
|
|
||
| expect(signPayload(payload, applicationId, apiKey)).toBe(expected); | ||
| }); | ||
|
|
||
| it("returns a non-empty hex string", () => { | ||
| const result = signPayload(makePayload(), "app-id", "api-key"); | ||
| expect(result).toMatch(/^[0-9a-f]+$/); | ||
| }); | ||
|
|
||
| it("produces different signatures for different payloads", () => { | ||
| const apiKey = "key"; | ||
| const appId = "app"; | ||
| expect(signPayload(makePayload("msg-1"), appId, apiKey)).not.toBe( | ||
| signPayload(makePayload("msg-2"), appId, apiKey), | ||
| ); | ||
| }); | ||
|
|
||
| it("produces different signatures for different applicationIds", () => { | ||
| const payload = makePayload(); | ||
| const apiKey = "key"; | ||
| expect(signPayload(payload, "app-1", apiKey)).not.toBe( | ||
| signPayload(payload, "app-2", apiKey), | ||
| ); | ||
| }); | ||
|
|
||
| it("produces different signatures for different apiKeys", () => { | ||
| const payload = makePayload(); | ||
| const appId = "app"; | ||
| expect(signPayload(payload, appId, "key-1")).not.toBe( | ||
| signPayload(payload, appId, "key-2"), | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.