fix(security): harden Contact Us sender confirmations
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user