Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge dev into 69 #74

Merged
merged 5 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions backend/src/email.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = {
Expand Down
9 changes: 5 additions & 4 deletions backend/src/openai.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"){
Expand Down
16 changes: 11 additions & 5 deletions backend/test/unit/email.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down