-
Notifications
You must be signed in to change notification settings - Fork 5
CCM-22090: Recipient response message retrieval API #1090
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
Open
rhyscoxnhs
wants to merge
16
commits into
release
Choose a base branch
from
feature/CCM-22090
base: release
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b813a53
CCM-22090: Recipient response message retrieval API
rhyscoxnhs 02e52a3
CCM-22090: Fixed lint
rhyscoxnhs 01f518d
CCM-22090: Added documentation
rhyscoxnhs 985db0b
CCM-22090: Revised documentation
rhyscoxnhs 3e55a1b
CCM-22090: PR feedback
rhyscoxnhs a68c892
CCM-22090: PR feedback
rhyscoxnhs 746ebe4
CCM-22090: Migrate app response API to JSON:API format
rhyscoxnhs 52e06fd
CCM-22090: PR feedback
rhyscoxnhs 8daff3d
CCM-22090: Reverted shared file
rhyscoxnhs 87b35ac
CCM-22090: PR feedback
rhyscoxnhs 2c4a7d5
CCM-22090: PR feedback
rhyscoxnhs 38b36ca
CCM-22090: PR feedback
rhyscoxnhs eb7e0bc
CCM-22090: Added message responses to security tests
rhyscoxnhs 7547d56
CCM-22090: Reverted change
rhyscoxnhs d6a9b7e
CCM-22090: PR feedback
rhyscoxnhs c71aca7
CCM-22090: PR feedback
rhyscoxnhs 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <TargetEndpoint name="app-response-target"> | ||
| <PreFlow> | ||
| <Request> | ||
| [% include './partials/Partial.Target.PreFlowRequest.xml' %] | ||
| </Request> | ||
| </PreFlow> | ||
| <Flows> | ||
| [% include './partials/Partial.Flows.GetMessageResponsesEndpoint.xml' %] | ||
| </Flows> | ||
| [% include './partials/Partial.Target.PostFlow.xml' %] | ||
| <FaultRules> | ||
| [% include './partials/Partial.Target.FaultRules.xml' %] | ||
| </FaultRules> | ||
| <HTTPTargetConnection> | ||
| <SSLInfo> | ||
| <Enabled>true</Enabled> | ||
| </SSLInfo> | ||
| <LoadBalancer> | ||
| <Server name="app-response-target"/> | ||
| </LoadBalancer> | ||
| <Path>{requestpath}</Path> | ||
| <Properties> | ||
| <Property name="io.timeout.millis">29000</Property> | ||
| </Properties> | ||
| </HTTPTargetConnection> | ||
| </TargetEndpoint> |
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
36 changes: 36 additions & 0 deletions
36
proxies/shared/partials/Partial.Flows.GetMessageResponsesEndpoint.xml
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,36 @@ | ||
| <Flow name="GetMessageResponsesEndpoint"> | ||
| <Description>Handle get message responses</Description> | ||
| <Request> | ||
| <!-- app-response has no ref-tier backend; fail fast instead of routing to an undefined TargetServer --> | ||
| <Step> | ||
| <Name>RaiseFault.404NotFound</Name> | ||
| <Condition>environment.name = "ref"</Condition> | ||
| </Step> | ||
| <Step> | ||
| <Name>ExtractVariables.MessageResponses.Get.Request</Name> | ||
| </Step> | ||
| <Step> | ||
| <Name>JavaScript.MessageResponses.Get.Validate</Name> | ||
| </Step> | ||
| <Step> | ||
| <Name>RaiseFault.4xxGeneric</Name> | ||
| <Condition>errors != null</Condition> | ||
| </Step> | ||
| <Step> | ||
| <Name>AssignMessage.MessageResponses.Get.Request</Name> | ||
| </Step> | ||
| {% if ENVIRONMENT_TYPE != 'sandbox' %} | ||
| <Step> | ||
| <Name>AssignMessage.AuthenticationDetails</Name> | ||
| </Step> | ||
| {% endif %} | ||
| </Request> | ||
| <Response> | ||
| <Step> | ||
| <Name>AssignMessage.MessageResponses.Get.Response</Name> | ||
| </Step> | ||
| </Response> | ||
| <Condition> | ||
| (proxy.pathsuffix MatchesPath "/v1/message-responses/{messageId}") and (request.verb = "GET") | ||
| </Condition> | ||
| </Flow> |
24 changes: 24 additions & 0 deletions
24
proxies/shared/policies/AssignMessage.MessageResponses.Get.Request.xml
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,24 @@ | ||
| <?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
| <!-- | ||
| Sets the backend request path to /api/response/{messageId} and forwards correlation ID. | ||
| --> | ||
| <AssignMessage async="false" continueOnError="false" enabled="true" name="AssignMessage.MessageResponses.Get.Request"> | ||
| <DisplayName>AssignMessage.MessageResponses.Get.Request</DisplayName> | ||
| <Properties/> | ||
| <AssignTo createNew="false" transport="http" type="request"/> | ||
| <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> | ||
| <AssignVariable> | ||
| <Name>target.copy.pathsuffix</Name> | ||
| <Value>false</Value> | ||
| </AssignVariable> | ||
| <AssignVariable> | ||
| <Name>requestpath</Name> | ||
| <Template>/api/response/{data.messageId}</Template> | ||
| </AssignVariable> | ||
| <Set> | ||
| <Headers> | ||
| <Header name="X-Correlation-Id">{backendCorrelationId}</Header> | ||
| </Headers> | ||
| <Verb>GET</Verb> | ||
| </Set> | ||
| </AssignMessage> |
10 changes: 10 additions & 0 deletions
10
proxies/shared/policies/AssignMessage.MessageResponses.Get.Response.xml
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,10 @@ | ||
| <?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
| <!-- | ||
| Passthrough response policy — no body transformation required for this endpoint. | ||
| --> | ||
| <AssignMessage async="false" continueOnError="false" enabled="true" name="AssignMessage.MessageResponses.Get.Response"> | ||
| <DisplayName>AssignMessage.MessageResponses.Get.Response</DisplayName> | ||
| <Properties/> | ||
| <AssignTo createNew="false" transport="http" type="response"/> | ||
| <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> | ||
| </AssignMessage> |
12 changes: 12 additions & 0 deletions
12
proxies/shared/policies/ExtractVariables.MessageResponses.Get.Request.xml
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,12 @@ | ||
| <?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
| <!-- | ||
| Extracts the messageId from the URI path into data.* flow variables. | ||
| --> | ||
| <ExtractVariables async="false" continueOnError="false" enabled="true" name="ExtractVariables.MessageResponses.Get.Request"> | ||
| <VariablePrefix>data</VariablePrefix> | ||
| <Source>request</Source> | ||
| <URIPath> | ||
| <Pattern ignoreCase="true">/v1/message-responses/{messageId}</Pattern> | ||
| </URIPath> | ||
| <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> | ||
| </ExtractVariables> |
11 changes: 11 additions & 0 deletions
11
proxies/shared/policies/JavaScript.MessageResponses.Get.Validate.xml
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,11 @@ | ||
| <?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
| <!-- | ||
| Validates the messageId extracted from the get message responses request. | ||
| --> | ||
| <Javascript async="false" continueOnError="false" enabled="true" timeLimit="5000" name="JavaScript.MessageResponses.Get.Validate"> | ||
| <DisplayName>JavaScript.MessageResponses.Get.Validate</DisplayName> | ||
| <Properties/> | ||
| <IncludeURL>jsc://helpers/validationErrors.js</IncludeURL> | ||
|
rhyscoxnhs marked this conversation as resolved.
|
||
| <IncludeURL>jsc://helpers/validationChecks.js</IncludeURL> | ||
| <ResourceURL>jsc://MessageResponses.Get.Validate.js</ResourceURL> | ||
| </Javascript> | ||
13 changes: 13 additions & 0 deletions
13
proxies/shared/resources/jsc/MessageResponses.Get.Validate.js
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 @@ | ||
| /* global context, validateUuidParameter */ | ||
|
|
||
| const errors = [] | ||
|
|
||
| validateUuidParameter(errors, context.getVariable("data.messageId"), "messageId"); | ||
|
|
||
| if (errors.length > 0) { | ||
| context.setVariable("generic_status_code", errors[0].status); | ||
| context.setVariable("errors", JSON.stringify(errors)); | ||
| } else { | ||
| context.setVariable("generic_status_code", null); | ||
| context.setVariable("errors", null); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import request from "supertest" | ||
| import * as uuid from 'uuid'; | ||
| import { setup } from './helpers.js' | ||
|
|
||
| const VALID_MESSAGE_ID = '11111111-1111-4111-8111-111111111111'; | ||
| const NOT_FOUND_MESSAGE_ID = '00000000-0000-4000-8000-000000000404'; | ||
| const UUID_VERSIONS = [1, 2, 3, 4, 5, 6, 7, 8]; | ||
|
|
||
| describe('/api/v1/message-responses/:messageId', () => { | ||
| let env; | ||
| let server; | ||
|
|
||
| beforeEach(() => { | ||
| env = process.env; | ||
| server = setup(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| process.env = env; | ||
| server.close(); | ||
| }); | ||
|
|
||
| it('returns a X-Correlation-Id when provided', (done) => { | ||
| const correlationId = uuid.v4(); | ||
| request(server) | ||
| .get(`/api/v1/message-responses/${VALID_MESSAGE_ID}`) | ||
| .set('X-Correlation-Id', correlationId) | ||
| .expect(200) | ||
| .expect('X-Correlation-Id', correlationId, done); | ||
| }); | ||
|
|
||
| it('returns a service ban (403) when the user is banned', (done) => { | ||
| request(server) | ||
| .get(`/api/v1/message-responses/${VALID_MESSAGE_ID}`) | ||
| .set({ Authorization: 'banned' }) | ||
| .expect(403, { | ||
| error: 'Forbidden' | ||
| }) | ||
| .expect('Content-Type', /json/, done); | ||
| }); | ||
|
|
||
| UUID_VERSIONS.forEach((version) => { | ||
| it(`returns a 200 for a valid UUID v${version} messageId`, (done) => { | ||
| const messageId = `11111111-1111-${version}111-8111-111111111111`; | ||
|
|
||
| request(server) | ||
| .get(`/api/v1/message-responses/${messageId}`) | ||
| .expect(200) | ||
| .expect('Content-Type', /json/, done); | ||
| }); | ||
| }); | ||
|
|
||
| it('returns a 404 when no responses are found', (done) => { | ||
| request(server) | ||
| .get(`/api/v1/message-responses/${NOT_FOUND_MESSAGE_ID}`) | ||
| .expect(404, { | ||
| errors: [ | ||
| { | ||
| code: 'CM_NOT_FOUND', | ||
| status: '404', | ||
| title: 'Resource not found', | ||
| detail: 'The resource at the requested URI was not found.' | ||
| } | ||
| ] | ||
| }) | ||
| .expect('Content-Type', /json/, done); | ||
| }); | ||
|
|
||
| it('returns a 415 when the content type is not supported', (done) => { | ||
| request(server) | ||
| .get(`/api/v1/message-responses/${VALID_MESSAGE_ID}`) | ||
| .set('Content-Type', 'text/plain') | ||
| .expect(415, { | ||
| message: 'Unsupported media type.' | ||
| }) | ||
| .expect('Content-Type', /json/, done); | ||
| }); | ||
|
|
||
| it('returns a 429 when the request is rate limited', (done) => { | ||
| request(server) | ||
| .get(`/api/v1/message-responses/${VALID_MESSAGE_ID}`) | ||
| .set('Prefer', 'code=429') | ||
| .expect(429, { | ||
| errors: [ | ||
| { | ||
| code: 'CM_QUOTA', | ||
| status: '429', | ||
| title: 'Too many requests', | ||
| detail: 'You have made too many requests. Re-send the request after the time (in seconds) specified `Retry-After` header.' | ||
| } | ||
| ] | ||
| }) | ||
| .expect('Content-Type', /json/, done); | ||
| }); | ||
|
|
||
| it('returns a 200 with correct response structure for a valid messageId', (done) => { | ||
| request(server) | ||
| .get(`/api/v1/message-responses/${VALID_MESSAGE_ID}`) | ||
| .expect(200) | ||
| .expect('Content-Type', /json/) | ||
| .expect((res) => { | ||
| const { body } = res; | ||
| if (!Array.isArray(body.data)) throw new Error('response must contain a data array'); | ||
| const first = body.data[0]; | ||
| if (!first.id) throw new Error('missing id'); | ||
| if (first.type !== 'RecipientResponse') throw new Error('incorrect type'); | ||
| const { attributes } = first; | ||
| if (attributes.messageId !== VALID_MESSAGE_ID) throw new Error('incorrect messageId'); | ||
| if (!attributes.messageReference) throw new Error('missing messageReference'); | ||
| if (!attributes.code) throw new Error('missing code'); | ||
| if (!attributes.channel) throw new Error('missing channel'); | ||
| if (!attributes.channelStatus) throw new Error('missing channelStatus'); | ||
| if (!attributes.cascadeType) throw new Error('missing cascadeType'); | ||
| if (!attributes.authoredAt) throw new Error('missing authoredAt'); | ||
| if (!attributes.timestamp) throw new Error('missing timestamp'); | ||
| }) | ||
| .end(done); | ||
| }); | ||
| }); |
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
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.