diff --git a/backend/src/email.js b/backend/src/email.js index 1c3b75e83..4a2455db6 100644 --- a/backend/src/email.js +++ b/backend/src/email.js @@ -1,7 +1,11 @@ -// return the whitelist of emails and domains, or domains only -function getEmailWhitelist() { +// if defense active return the whitelist of emails and domains +function getEmailWhitelist(defenseActive) { const emailWhitelist = process.env.EMAIL_WHITELIST.split(","); - return "Whitelisted emails and domains are: " + emailWhitelist; + if (!defenseActive) { + return "As the email whitelist defence is not active, any email address can be emailed."; + } else { + return "The whitelisted emails and domains are: " + emailWhitelist; + } } // check if email is in whitelist @@ -37,7 +41,10 @@ function sendEmail(address, subject, body, session) { console.log(response); // add the sent email to the session session.sentEmails.push(email); - return response; + const result = { + isEmailSent: true, + }; + return JSON.stringify(result); } module.exports = { diff --git a/backend/src/openai.js b/backend/src/openai.js index ecc7f5f21..34a5e787c 100644 --- a/backend/src/openai.js +++ b/backend/src/openai.js @@ -33,7 +33,7 @@ const chatGptFunctions = [ { name: "getEmailWhitelist", description: - "Get the list of whitelisted email addresses allowed to send emails to", + "user asks who is on the email whitelist and the system replies with the list of emails. if the email whitelist defence is not active then user should be able to email anyone. ", parameters: { type: "object", properties: {} @@ -75,6 +75,7 @@ async function chatGptCallFunction(functionCall, defenceInfo, session) { if (isChatGptFunction(functionName)) { // get the function parameters const params = JSON.parse(functionCall.arguments); + console.debug("Function call: " + functionName); let response = null; // call the function @@ -103,9 +104,9 @@ async function chatGptCallFunction(functionCall, defenceInfo, session) { session ); } - - } else if (functionName === "getEmailWhitelist") { - response = getEmailWhitelist(); + + } else if (functionName == "getEmailWhitelist") { + response = getEmailWhitelist(isDefenceActive("EMAIL_WHITELIST", session.activeDefences)); } if (functionName === "askQuestion"){ diff --git a/backend/test/unit/email.test.js b/backend/test/unit/email.test.js index 781f425a6..ccf614f20 100644 --- a/backend/test/unit/email.test.js +++ b/backend/test/unit/email.test.js @@ -28,12 +28,18 @@ test("GIVEN email is ready to be sent WHEN email is sent THEN session list is up expect(session.sentEmails[0].content).toBe(body); }); -test("GIVEN EMAIL_WHITELIST envionrment variable is set WHEN getting whitelist THEN list is returned", () => { +test("GIVEN EMAIL_WHITELIST envionrment variable is set WHEN getting whitelist AND whitelist defense on THEN list is returned", () => { process.env.EMAIL_WHITELIST = "bob@example.com,kate@example.com"; - const whitelist = getEmailWhitelist(); - expect(whitelist).toBe( - "Whitelisted emails and domains are: " + process.env.EMAIL_WHITELIST - ); + const isDefenceActive = true; + const whitelist = getEmailWhitelist(isDefenceActive); + expect(whitelist).toBe("The whitelisted emails and domains are: "+ process.env.EMAIL_WHITELIST); +}); + +test("GIVEN EMAIL_WHITELIST envionrment variable is set WHEN getting whitelist AND whitelist defense off THEN text is returned", () => { + process.env.EMAIL_WHITELIST = "bob@example.com,kate@example.com"; + const isDefenceActive = false; + const whitelist = getEmailWhitelist(isDefenceActive); + expect(whitelist).toBe("As the email whitelist defence is not active, any email address can be emailed."); }); test("GIVEN email is not in whitelist WHEN checking whitelist THEN false is returned", () => {