@aikidosec/firewall
Version:
Zen by Aikido is an embedded Application Firewall that autonomously protects Node.js apps against common and critical attacks, provides rate limiting, detects malicious traffic (including bots), and more.
27 lines (26 loc) • 1.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTestAgent = createTestAgent;
const Agent_1 = require("../agent/Agent");
const AgentSingleton_1 = require("../agent/AgentSingleton");
const FetchListsAPIForTesting_1 = require("../agent/api/FetchListsAPIForTesting");
const ReportingAPIForTesting_1 = require("../agent/api/ReportingAPIForTesting");
const LoggerNoop_1 = require("../agent/logger/LoggerNoop");
const wrap_1 = require("./wrap");
/**
* Create a test agent for testing purposes
*/
function createTestAgent(opts) {
var _a, _b, _c, _d, _e;
if ((_a = opts === null || opts === void 0 ? void 0 : opts.suppressConsoleLog) !== null && _a !== void 0 ? _a : true) {
(0, wrap_1.wrap)(console, "log", function log() {
return function log() { };
});
}
const agent = new Agent_1.Agent((_b = opts === null || opts === void 0 ? void 0 : opts.block) !== null && _b !== void 0 ? _b : true, (_c = opts === null || opts === void 0 ? void 0 : opts.logger) !== null && _c !== void 0 ? _c : new LoggerNoop_1.LoggerNoop(), (_d = opts === null || opts === void 0 ? void 0 : opts.api) !== null && _d !== void 0 ? _d : new ReportingAPIForTesting_1.ReportingAPIForTesting(), opts === null || opts === void 0 ? void 0 : opts.token, // Defaults to undefined
opts === null || opts === void 0 ? void 0 : opts.serverless, // Defaults to undefined
false, // During tests this is controlled by the AIKIDO_TEST_NEW_INSTRUMENTATION env var
(_e = opts === null || opts === void 0 ? void 0 : opts.fetchListsAPI) !== null && _e !== void 0 ? _e : new FetchListsAPIForTesting_1.FetchListsAPIForTesting());
(0, AgentSingleton_1.setInstance)(agent);
return agent;
}