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

Fixed getEmailWhitelist defence #124

Merged
merged 1 commit into from
Aug 14, 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
4 changes: 2 additions & 2 deletions backend/src/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function getEmailWhitelistValues(defences) {
}

// if defense active return the whitelist of emails and domains
function askEmailWhitelist(defences) {
function getEmailWhitelist(defences) {
if (!isDefenceActive("EMAIL_WHITELIST", defences)) {
return "As the email whitelist defence is not active, any email address can be emailed.";
} else {
Expand Down Expand Up @@ -56,7 +56,7 @@ function sendEmail(address, subject, body, session) {
}

module.exports = {
askEmailWhitelist,
getEmailWhitelist,
isEmailInWhitelist,
sendEmail,
};
8 changes: 3 additions & 5 deletions backend/src/openai.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { Configuration, OpenAIApi } = require("openai");
const { isDefenceActive, getSystemRole } = require("./defence");
const { sendEmail, askEmailWhitelist, isEmailInWhitelist } = require("./email");
const { sendEmail, getEmailWhitelist, isEmailInWhitelist } = require("./email");
const {
initQAModel,
initPromptEvaluationModel,
Expand Down Expand Up @@ -37,7 +37,7 @@ const chatGptFunctions = [
},
},
{
name: "askEmailWhitelist",
name: "getEmailWhitelist",
description:
"user asks who is on the email whitelist and the system replies with the list of emails.",
parameters: {
Expand Down Expand Up @@ -161,9 +161,7 @@ async function chatGptCallFunction(functionCall, defenceInfo, session) {
);
}
} else if (functionName == "getEmailWhitelist") {
response = getEmailWhitelist(
isDefenceActive("EMAIL_WHITELIST", session.defences)
);
response = getEmailWhitelist(session.defences);
}
if (functionName === "askQuestion") {
console.debug("Asking question: " + params.question);
Expand Down
6 changes: 3 additions & 3 deletions backend/test/unit/email.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {
askEmailWhitelist,
getEmailWhitelist,
isEmailInWhitelist,
sendEmail,
} = require("../../src/email");
Expand Down Expand Up @@ -42,7 +42,7 @@ test("GIVEN EMAIL_WHITELIST envionrment variable is set WHEN getting whitelist A
],
},
];
const whitelist = askEmailWhitelist(defences);
const whitelist = getEmailWhitelist(defences);
expect(whitelist).toBe(
"The whitelisted emails and domains are: " + process.env.EMAIL_WHITELIST
);
Expand All @@ -62,7 +62,7 @@ test("GIVEN EMAIL_WHITELIST envionrment variable is set WHEN getting whitelist A
],
},
];
const response = askEmailWhitelist(defences);
const response = getEmailWhitelist(defences);
expect(response).toBe(
"As the email whitelist defence is not active, any email address can be emailed."
);
Expand Down