Skip to content

Commit e878a81

Browse files
feature: Include md5 digest on file attachment payload (#249)
1 parent 44f7373 commit e878a81

4 files changed

Lines changed: 12 additions & 5 deletions

File tree

src/lib/vault/mappers/formSubmission.mapper.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ function partialAttachmentFromSubmissionAttachmentsAsJson(
115115

116116
return attachments.map((item) => {
117117
if (
118+
item.id === undefined ||
118119
item.name === undefined ||
119120
item.path === undefined ||
120121
item.scanStatus === undefined
@@ -123,7 +124,8 @@ function partialAttachmentFromSubmissionAttachmentsAsJson(
123124
}
124125

125126
if (
126-
(typeof item.id !== "string" && typeof item.id !== "undefined") ||
127+
(typeof item.md5 !== "string" && typeof item.md5 !== "undefined") ||
128+
typeof item.id !== "string" ||
127129
typeof item.name !== "string" ||
128130
typeof item.path !== "string" ||
129131
typeof item.scanStatus !== "string"
@@ -136,6 +138,7 @@ function partialAttachmentFromSubmissionAttachmentsAsJson(
136138
name: item.name,
137139
path: item.path,
138140
scanStatus: attachmentScanStatusFromScanStatus(item.scanStatus),
141+
md5: item.md5,
139142
};
140143
});
141144
}

src/lib/vault/types/formSubmission.types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ export enum AttachmentScanStatus {
2020
// id is marked as optional to ensure backwards compatibility.
2121
// it can be marked as required in the future once we are sure all attachment responses contain id's
2222
export type PartialAttachment = {
23-
id?: string;
23+
id: string;
2424
name: string;
2525
path: string;
2626
scanStatus: AttachmentScanStatus;
27+
md5?: string;
2728
};
2829

2930
export type FormSubmission = {

src/operations/retrieveSubmission.v1.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ function buildJsonResponse(
100100
isPotentiallyMalicious: isAttachmentPotentiallyMalicious(
101101
attachment.scanStatus,
102102
),
103+
md5: attachment.md5,
103104
})),
104105
}),
105106
});

test/lib/vault/mappers/formSubmission.mapper.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ describe("in formSubmission mapper", () => {
7272
});
7373
});
7474

75-
// This test should be deleted once `PartialAttachment` has its `id` property set to non optional
76-
it("return proper FormSubmission when DynamoDB response is complete and valid (testing backwards compatibility with file attachments not having defined 'id')", () => {
75+
// This test should be deleted once `PartialAttachment` has its `md5` property set to non optional
76+
it("return proper FormSubmission when DynamoDB response is complete and valid (testing backwards compatibility with file attachments not having defined 'md5')", () => {
7777
const formSubmission = mapFormSubmissionFromDynamoDbResponse({
7878
CreatedAt: 1750263415913,
7979
"Status#CreatedAt": "New#1750263415913",
@@ -82,6 +82,7 @@ describe("in formSubmission mapper", () => {
8282
FormSubmissionHash: "5981e9cd2a2f0032e9b8c99eb7bb8841",
8383
SubmissionAttachments: JSON.stringify([
8484
{
85+
id: "test",
8586
name: "output.txt",
8687
path: "filePath",
8788
scanStatus: "NO_THREATS_FOUND",
@@ -97,10 +98,11 @@ describe("in formSubmission mapper", () => {
9798
checksum: "5981e9cd2a2f0032e9b8c99eb7bb8841",
9899
attachments: [
99100
{
100-
id: undefined,
101+
id: "test",
101102
name: "output.txt",
102103
path: "filePath",
103104
scanStatus: AttachmentScanStatus.NoThreatsFound,
105+
md5: undefined,
104106
},
105107
],
106108
});

0 commit comments

Comments
 (0)