Skip to content

Commit

Permalink
OJ-2837: chore - removed unneccessary tests and updated function base…
Browse files Browse the repository at this point in the history
…d on GH suggestions
  • Loading branch information
MarieseMikely committed Nov 26, 2024
1 parent 1929e9c commit 7be459e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 125 deletions.
51 changes: 30 additions & 21 deletions integration-tests/api-gateway/check/check-happy.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { checkEndpoint, createSession } from "../endpoints";
import { checkEndpoint, createMultipleNamesSession, createSession } from "../endpoints";
import {
clearAttemptsTable,
clearItemsFromTables,
Expand All @@ -19,26 +19,26 @@ describe("Given the session and NINO is valid", () => {
UserAttemptsTable: string;
}>;

afterEach(async () => {
output = await stackOutputs(process.env.STACK_NAME);
personIDTableName = `person-identity-${output.CommonStackName}`;
sessionTableName = `session-${output.CommonStackName}`;
await clearItemsFromTables(
{
tableName: personIDTableName,
items: { sessionId: sessionId },
},
{
tableName: `${output.NinoUsersTable}`,
items: { sessionId: sessionId },
},
{
tableName: sessionTableName,
items: { sessionId: sessionId },
}
);
await clearAttemptsTable(sessionId, `${output.UserAttemptsTable}`);
});
// afterEach(async () => {
// output = await stackOutputs(process.env.STACK_NAME);
// personIDTableName = `person-identity-${output.CommonStackName}`;
// sessionTableName = `session-${output.CommonStackName}`;
// await clearItemsFromTables(
// {
// tableName: personIDTableName,
// items: { sessionId: sessionId },
// },
// {
// tableName: `${output.NinoUsersTable}`,
// items: { sessionId: sessionId },
// },
// {
// tableName: sessionTableName,
// items: { sessionId: sessionId },
// }
// );
// await clearAttemptsTable(sessionId, `${output.UserAttemptsTable}`);
// });

it("Should receive a 200 response when /check endpoint is called without optional headers", async () => {
const session = await createSession();
Expand All @@ -61,6 +61,15 @@ describe("Given the session and NINO is valid", () => {
expect(checkData).toEqual(200);
});

it.only("Should receive a 200 response when /check endpoint is called using multiple named user", async () => {
const session = await createMultipleNamesSession();
const sessionData = await session.json();
sessionId = sessionData.session_id;
const check = await checkEndpoint({ "session-id": sessionId }, NINO);
const checkData = check.status;
expect(checkData).toEqual(200);
});

it("should 500 when provided with JS in the session header", async () => {
const maliciousSessionId = `<script>alert('Attack!');</script>`;
const check = await checkEndpoint(
Expand Down
63 changes: 0 additions & 63 deletions integration-tests/api-gateway/check/check-multiple-name.test.ts

This file was deleted.

35 changes: 21 additions & 14 deletions integration-tests/api-gateway/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let preOutput: Partial<{
PrivateApiGatewayId: string;
}>;

export const createPayload = async (useMultipleNames: boolean = false) => {
export const createPayload = async (sharedClaimsUpdate?: any) => {
publicEncryptionKeyBase64 =
(await getSSMParameter(
"/check-hmrc-cri-api/test/publicEncryptionKeyBase64"
Expand All @@ -29,16 +29,12 @@ export const createPayload = async (useMultipleNames: boolean = false) => {
preOutput = await stackOutputs(process.env.STACK_NAME);
privateAPI = `${preOutput.PrivateApiGatewayId}`;
const correctClaimSet = await getClaimSet();

if (useMultipleNames = true){
const name = correctClaimSet.shared_claims.name[0].nameParts
name.push(
{ type: "GivenName", value: "Peter"},
{ type: "GivenName", value: "Syed Habib"},
{ type: "FamilyName", value: "Martin-Joy"}
)
const updateClaimset = {
...correctClaimSet,
...sharedClaimsUpdate,
name: sharedClaimsUpdate?.name || correctClaimSet.shared_claims.name
}

console.log("update shared claims: ", JSON.stringify(updateClaimset.name))
const audience = correctClaimSet.aud;
const payload = {
clientId: CLIENT_ID,
Expand All @@ -48,14 +44,14 @@ export const createPayload = async (useMultipleNames: boolean = false) => {
publicEncryptionKeyBase64: publicEncryptionKeyBase64,
privateSigningKey: privateSigningKey,
issuer: CLIENT_URL,
claimSet: correctClaimSet,
claimSet: updateClaimset
} as unknown as Payload;
const ipvCoreAuthorizationUrl = await getJarAuthorizationPayload(payload);
return ipvCoreAuthorizationUrl;
};

export const createSession = async (): Promise<Response> => {
const ipvCoreAuthorizationUrl = await createPayload(false);
const ipvCoreAuthorizationUrl = await createPayload();
const sessionApiUrl = `https://${privateAPI}.execute-api.eu-west-2.amazonaws.com/${environment}/session`;
const sessionResponse = await fetch(sessionApiUrl, {
method: "POST",
Expand All @@ -70,7 +66,7 @@ export const createSession = async (): Promise<Response> => {
};

export const createInvalidSession = async (): Promise<Response> => {
const ipvCoreAuthorizationUrl = await createPayload(false);
const ipvCoreAuthorizationUrl = await createPayload();
const sessionApiUrl = `https://${privateAPI}.execute-api.eu-west-2.amazonaws.com/${environment}/session`;
const sessionResponse = await fetch(sessionApiUrl, {
method: "POST",
Expand All @@ -85,7 +81,18 @@ export const createInvalidSession = async (): Promise<Response> => {
};

export const createMultipleNamesSession = async (): Promise<Response> => {
const ipvCoreAuthorizationUrl = await createPayload(true);
const ipvCoreAuthorizationUrl = await createPayload({
name: [
{
nameParts: [
{ type: "GivenName", value: "Peter"},
{ type: "GivenName", value: "Syed Habib"},
{ type: "FamilyName", value: "Martin-Joy"}
]
}
]
});
console.log(ipvCoreAuthorizationUrl, " URL")
const sessionApiUrl = `https://${privateAPI}.execute-api.eu-west-2.amazonaws.com/${environment}/session`;
const sessionResponse = await fetch(sessionApiUrl, {
method: "POST",
Expand Down

This file was deleted.

0 comments on commit 7be459e

Please sign in to comment.