Skip to content

Commit 526b0a0

Browse files
committed
validate campaignId
1 parent 9d92cbb commit 526b0a0

File tree

7 files changed

+95
-6
lines changed

7 files changed

+95
-6
lines changed

infrastructure/terraform/modules/backend-api/module_create_routing_config_lambda.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,15 @@ data "aws_iam_policy_document" "create_routing_config_lambda_policy" {
6565
var.kms_key_arn
6666
]
6767
}
68+
69+
statement {
70+
sid = "AllowSSMParameterRead"
71+
effect = "Allow"
72+
73+
actions = [
74+
"ssm:GetParameter",
75+
]
76+
77+
resources = [local.client_ssm_path_pattern]
78+
}
6879
}

infrastructure/terraform/modules/backend-api/module_update_routing_config_lambda.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,15 @@ data "aws_iam_policy_document" "update_routing_config_lambda_policy" {
6565
var.kms_key_arn
6666
]
6767
}
68+
69+
statement {
70+
sid = "AllowSSMParameterRead"
71+
effect = "Allow"
72+
73+
actions = [
74+
"ssm:GetParameter",
75+
]
76+
77+
resources = [local.client_ssm_path_pattern]
78+
}
6879
}

scripts/sandbox_auth.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ if [[ "$get_user_command_exit_code" -ne 0 ]]; then
4747

4848
client_config_param_name="$client_ssm_path_prefix/$notify_client_id"
4949

50-
client_config_param_value="{ "campaignId": "campaign", "features": { "proofing": true } }"
50+
client_config_param_value='{ "campaignIds": ["campaign"], "features": { "proofing": true } }'
5151

5252
if aws ssm get-parameter --name "$client_config_param_name" --with-decryption >/dev/null 2>&1; then
5353
echo "Client config parameter already exists: $client_config_param_name"

tests/test-team/helpers/auth/cognito-auth-helper.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type TestUserStaticDetails = {
3434

3535
type TestUserDynamicDetails = {
3636
email: string;
37+
campaignIds?: string[];
3738
clientId: string;
3839
password: string;
3940
clientName?: string;
@@ -261,6 +262,7 @@ export class CognitoAuthHelper {
261262
const clientConfig: ClientConfiguration | undefined =
262263
testClients[userDetails.clientKey];
263264
const clientName = clientConfig?.name;
265+
const campaignIds = clientConfig?.campaignIds;
264266

265267
const clientAttributes = [
266268
{ Name: 'custom:sbx_client_id', Value: clientId },
@@ -319,6 +321,7 @@ export class CognitoAuthHelper {
319321
userId:
320322
user.User?.Attributes?.find((attr) => attr.Name === 'sub')?.Value ??
321323
'',
324+
campaignIds,
322325
clientId: clientId,
323326
clientKey: userDetails.clientKey,
324327
clientName: clientName,

tests/test-team/helpers/factories/routing-config-factory.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import type {
77
FactoryRoutingConfig,
88
RoutingConfigDbEntry,
99
} from '../../helpers/types';
10+
import { TestUser } from 'helpers/auth/cognito-auth-helper';
1011

1112
export const RoutingConfigFactory = {
1213
create(
13-
user: { userId: string; clientId: string },
14+
user: TestUser,
1415
routingConfig: Partial<RoutingConfig> = {}
1516
): FactoryRoutingConfig {
1617
const apiPayload: CreateUpdateRoutingConfig = {
17-
campaignId: 'campaign-1',
18+
campaignId: user.campaignIds?.[0] ?? 'campaign',
1819
cascade: [
1920
{
2021
cascadeGroups: ['standard'],

tests/test-team/template-mgmt-api-tests/create-routing-configuration.api.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,36 @@ test.describe('POST /v1/routing-configuration', () => {
130130
});
131131
});
132132

133+
test('returns 400 if campaignId is not available for the client', async ({
134+
request,
135+
}) => {
136+
const campaignId = 'not_a_client_campaign';
137+
138+
const response = await request.post(
139+
`${process.env.API_BASE_URL}/v1/routing-configuration`,
140+
{
141+
headers: {
142+
Authorization: await user1.getAccessToken(),
143+
},
144+
data: RoutingConfigFactory.create(user1, {
145+
campaignId,
146+
}).apiPayload,
147+
}
148+
);
149+
150+
const dbgClientCampaigns = JSON.stringify(user1.campaignIds);
151+
expect(user1.campaignIds?.includes(campaignId), dbgClientCampaigns).toBe(
152+
false
153+
);
154+
155+
expect(response.status()).toBe(400);
156+
157+
expect(await response.json()).toEqual({
158+
statusCode: 400,
159+
technicalMessage: 'Invalid campaign ID in request',
160+
});
161+
});
162+
133163
test('ignores status if given - routing config cannot be completed at create time', async ({
134164
request,
135165
}) => {

tests/test-team/template-mgmt-api-tests/update-routing-config.api.spec.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,16 @@ test.describe('PUT /v1/routing-configuration/:routingConfigId', () => {
8484
test('returns 404 if routing config exists but is owned by a different client', async ({
8585
request,
8686
}) => {
87+
const { apiPayload, dbEntry } =
88+
RoutingConfigFactory.create(userDifferentClient);
89+
8790
const updateResponse = await request.put(
88-
`${process.env.API_BASE_URL}/v1/routing-configuration/${routingConfigNoUpdates.dbEntry.id}`,
91+
`${process.env.API_BASE_URL}/v1/routing-configuration/${dbEntry.id}`,
8992
{
9093
headers: {
9194
Authorization: await userDifferentClient.getAccessToken(),
9295
},
93-
data: routingConfigNoUpdates.apiPayload,
96+
data: apiPayload,
9497
}
9598
);
9699

@@ -167,6 +170,36 @@ test.describe('PUT /v1/routing-configuration/:routingConfigId', () => {
167170
});
168171
});
169172

173+
test('returns 400 if campaignId is not available for the client', async ({
174+
request,
175+
}) => {
176+
const campaignId = 'not_a_client_campaign';
177+
178+
const response = await request.put(
179+
`${process.env.API_BASE_URL}/v1/routing-configuration/${routingConfigNoUpdates.dbEntry.id}`,
180+
{
181+
headers: {
182+
Authorization: await user1.getAccessToken(),
183+
},
184+
data: RoutingConfigFactory.create(user1, {
185+
campaignId,
186+
}).apiPayload,
187+
}
188+
);
189+
190+
const dbgClientCampaigns = JSON.stringify(user1.campaignIds);
191+
expect(user1.campaignIds?.includes(campaignId), dbgClientCampaigns).toBe(
192+
false
193+
);
194+
195+
expect(response.status()).toBe(400);
196+
197+
expect(await response.json()).toEqual({
198+
statusCode: 400,
199+
technicalMessage: 'Invalid campaign ID in request',
200+
});
201+
});
202+
170203
test('returns 404 - cannot update a DELETED routing config', async ({
171204
request,
172205
}) => {
@@ -198,7 +231,7 @@ test.describe('PUT /v1/routing-configuration/:routingConfigId', () => {
198231
}) => {
199232
const update = {
200233
...routingConfigSuccessfullyUpdate.apiPayload,
201-
campaignId: 'new campaignId',
234+
name: 'new name',
202235
};
203236

204237
const updateResponse = await request.put(

0 commit comments

Comments
 (0)