fix(security): harden Contact Us sender confirmations

This commit is contained in:
2026-11-09 13:06:22 +00:00
parent b821dc2092
commit 3c0a9ef721
7 changed files with 811 additions and 17 deletions
+77 -1
View File
@@ -208,7 +208,21 @@ test("document delete blob flows use signer hash", async () => {
axios,
BASE_URL: "",
consoleLogger: logger.consoleLogger,
hashAPIPath: () => "&hash=fallback"
hashAPIPath: () => "&hash=fallback",
postSignedFileJson: async (queryUrl, data, config = {}) => {
const hashResponse = await axios.get(
"/api/endpoint/gethash_api?path=" + encodeURIComponent(queryUrl)
);
const response = await axios({
method: "post",
url: queryUrl + hashResponse.data.hash,
data,
...config
});
return response.data;
}
});
const one = await document.deleteAwaitingSubmissionsFromBlob(
@@ -384,6 +398,68 @@ test("notify/sendEmail logs and rethrows on failure", async () => {
assert.strictEqual(logger.calls.length, 1);
});
test("notify/sendContactUsConfirmation posts only the dedicated payload", async () => {
const axios = createAxiosMock();
const logger = createLoggerMock();
axios.requestHandler = async () => ({ data: { sent: true } });
const notify = loadServiceModule("notifyDirectService.js", {
axios,
consoleLogger: logger.consoleLogger
});
const formValues = {
contactEmail: "person@example.com",
contactSubject: "Questions about Planning legislation or policy",
contactbody: "Please review https://example.invalid",
typeOfContact: "plq",
ignored: "not sent"
};
const result = await notify.sendContactUsConfirmation(formValues, "cy");
assert.deepStrictEqual(normalize(result), { sent: true });
assert.strictEqual(
axios.calls[0].config.url,
"/api/email/contactus-confirmation"
);
assert.strictEqual(axios.calls[0].config.method, "post");
assert.deepStrictEqual(normalize(axios.calls[0].config.data), {
contactEmail: "person@example.com",
contactSubject: "Questions about Planning legislation or policy",
contactbody: "Please review https://example.invalid",
typeOfContact: "plq",
language: "cy"
});
});
test("notify/sendContactUsConfirmation logs and rethrows on failure", async () => {
const axios = createAxiosMock();
const logger = createLoggerMock();
const error = createAxiosError(400, "Bad Request");
axios.requestHandler = async () => Promise.reject(error);
const notify = loadServiceModule("notifyDirectService.js", {
axios,
consoleLogger: logger.consoleLogger
});
await assert.rejects(
notify.sendContactUsConfirmation(
{
contactEmail: "person@example.com",
contactSubject: "Other enquiry for PEDW",
contactbody: "Message",
typeOfContact: "other"
},
"en"
),
(thrown) => thrown === error
);
assert.strictEqual(logger.calls.length, 1);
});
test("integration/createCRMTask posts payload and returns data", async () => {
const axios = createAxiosMock();
const logger = createLoggerMock();