Skip to content

Commit bb7d8c2

Browse files
committed
more specific regex
1 parent f012342 commit bb7d8c2

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

tests/test-team/template-mgmt-e2e-tests/template-mgmt-letter-full.e2e.spec.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,26 @@ test.describe('letter complete e2e journey', () => {
181181
);
182182

183183
expect(pdfHrefs.length).toBeGreaterThan(0);
184-
for (const href of pdfHrefs) expect(href).toContain(templateId);
185184

186185
const downloadBucketMetadata = await Promise.all(
187186
pdfHrefs.map((href) => {
188-
const [downloadBucketPath] =
187+
const [, downloadBucketPath] =
189188
(href as string).match(
190-
// eslint-disable-next-line security/detect-unsafe-regex, sonarjs/slow-regex
191-
/((?:[^/]+\/){3}[^/]+)\/?$/
189+
// eslint-disable-next-line security/detect-non-literal-regexp
190+
new RegExp(
191+
`/templates/files/(${user.userId}/proofs/${templateId}/[^/]+)/?$`
192+
)
192193
) ?? [];
193194

195+
if (!downloadBucketPath) {
196+
throw new Error(
197+
`Could not determine bucket path based on URL: ${href}`
198+
);
199+
}
200+
194201
return templateStorageHelper.getS3Metadata(
195202
process.env.TEMPLATES_DOWNLOAD_BUCKET_NAME,
196-
downloadBucketPath!
203+
downloadBucketPath
197204
);
198205
})
199206
);

0 commit comments

Comments
 (0)