From 5ffd76d30cadcd46f054a0f072e135e309ec8a7f Mon Sep 17 00:00:00 2001 From: Hans Ott Date: Mon, 25 Nov 2024 09:55:28 +0100 Subject: [PATCH] Output whether blocking or detection-only mode is enabled --- library/agent/Agent.test.ts | 6 +++++- library/agent/Agent.ts | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/library/agent/Agent.test.ts b/library/agent/Agent.test.ts index b1088d94..11fa810d 100644 --- a/library/agent/Agent.test.ts +++ b/library/agent/Agent.test.ts @@ -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!", "mongodb@6.8.0 is supported!", ]); @@ -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!", "shell-quote@1.8.1 is not supported!", ]); @@ -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!", ]); }); @@ -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...", @@ -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: mongoose@1.0.0", ]); diff --git a/library/agent/Agent.ts b/library/agent/Agent.ts index 06738785..3d83154e 100644 --- a/library/agent/Agent.ts +++ b/library/agent/Agent.ts @@ -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!" + ); + } } } @@ -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) {