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

Output whether blocking or detection-only mode is enabled #461

Open
wants to merge 1 commit into
base: beta
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion library/agent/Agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ t.test("it sends started event", async (t) => {

t.same(logger.getMessages(), [
"Starting agent...",
"Blocking mode enabled, requests will be blocked!",
"Found token, reporting enabled!",
"[email protected] is supported!",
]);
Expand Down Expand Up @@ -106,6 +107,7 @@ t.test("it logs if package is supported or not", async () => {

t.same(logger.getMessages(), [
"Starting agent...",
"Blocking mode enabled, requests will be blocked!",
"Found token, reporting enabled!",
"[email protected] is not supported!",
]);
Expand All @@ -124,7 +126,7 @@ t.test("it starts in non-blocking mode", async () => {

t.same(logger.getMessages(), [
"Starting agent...",
"Dry mode enabled, no requests will be blocked!",
"Detection-only mode enabled, no requests will be blocked!",
"Found token, reporting enabled!",
]);
});
Expand Down Expand Up @@ -549,6 +551,7 @@ t.test("it logs when failed to report event", async () => {

t.same(logger.getMessages(), [
"Starting agent...",
"Blocking mode enabled, requests will be blocked!",
"Found token, reporting enabled!",
"Failed to start agent",
"Heartbeat...",
Expand All @@ -571,6 +574,7 @@ t.test("unable to prevent prototype pollution", async () => {
agent.unableToPreventPrototypePollution({ mongoose: "1.0.0" });
t.same(logger.getMessages(), [
"Starting agent...",
"Blocking mode enabled, requests will be blocked!",
"Found token, reporting enabled!",
"Unable to prevent prototype pollution, incompatible packages found: [email protected]",
]);
Expand Down
18 changes: 13 additions & 5 deletions library/agent/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,13 @@ export class Agent {
if (typeof response.block === "boolean") {
if (response.block !== this.block) {
this.block = response.block;
this.logger.log(
`Block mode has been set to ${this.block ? "on" : "off"}`
);
if (this.block) {
this.logger.log("Blocking mode enabled, requests will be blocked!");
} else {
this.logger.log(
"Detection-only mode enabled, no requests will be blocked!"
);
}
}
}

Expand Down Expand Up @@ -394,8 +398,12 @@ export class Agent {

this.logger.log("Starting agent...");

if (!this.block) {
this.logger.log("Dry mode enabled, no requests will be blocked!");
if (this.block) {
this.logger.log("Blocking mode enabled, requests will be blocked!");
} else {
this.logger.log(
"Detection-only mode enabled, no requests will be blocked!"
);
}

if (this.token) {
Expand Down
Loading