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

Report stats about blocked requests #505

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
201 changes: 201 additions & 0 deletions library/agent/InspectionStatistics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ t.test("it resets stats", async () => {
total: 0,
blocked: 0,
},
blocked: {
total: 0,
allowedIpsRoute: 0,
userAgent: 0,
ipBlocklist: 0,
userBlocked: 0,
},
rateLimited: 0,
},
});

Expand All @@ -54,6 +62,14 @@ t.test("it resets stats", async () => {
total: 0,
blocked: 0,
},
blocked: {
total: 0,
allowedIpsRoute: 0,
userAgent: 0,
ipBlocklist: 0,
userBlocked: 0,
},
rateLimited: 0,
},
});

Expand All @@ -80,6 +96,14 @@ t.test("it keeps track of amount of calls", async () => {
total: 0,
blocked: 0,
},
blocked: {
total: 0,
allowedIpsRoute: 0,
userAgent: 0,
ipBlocklist: 0,
userBlocked: 0,
},
rateLimited: 0,
},
});

Expand Down Expand Up @@ -112,6 +136,14 @@ t.test("it keeps track of amount of calls", async () => {
total: 0,
blocked: 0,
},
blocked: {
total: 0,
allowedIpsRoute: 0,
userAgent: 0,
ipBlocklist: 0,
userBlocked: 0,
},
rateLimited: 0,
},
});

Expand Down Expand Up @@ -144,6 +176,14 @@ t.test("it keeps track of amount of calls", async () => {
total: 0,
blocked: 0,
},
blocked: {
total: 0,
allowedIpsRoute: 0,
userAgent: 0,
ipBlocklist: 0,
userBlocked: 0,
},
rateLimited: 0,
},
});

Expand All @@ -170,6 +210,14 @@ t.test("it keeps track of amount of calls", async () => {
total: 0,
blocked: 0,
},
blocked: {
total: 0,
allowedIpsRoute: 0,
userAgent: 0,
ipBlocklist: 0,
userBlocked: 0,
},
rateLimited: 0,
},
});

Expand Down Expand Up @@ -202,6 +250,14 @@ t.test("it keeps track of amount of calls", async () => {
total: 0,
blocked: 0,
},
blocked: {
total: 0,
allowedIpsRoute: 0,
userAgent: 0,
ipBlocklist: 0,
userBlocked: 0,
},
rateLimited: 0,
},
});

Expand Down Expand Up @@ -234,6 +290,14 @@ t.test("it keeps track of amount of calls", async () => {
total: 0,
blocked: 0,
},
blocked: {
total: 0,
allowedIpsRoute: 0,
userAgent: 0,
ipBlocklist: 0,
userBlocked: 0,
},
rateLimited: 0,
},
});

Expand Down Expand Up @@ -285,6 +349,14 @@ t.test("it keeps track of amount of calls", async () => {
total: 0,
blocked: 0,
},
blocked: {
total: 0,
allowedIpsRoute: 0,
userAgent: 0,
ipBlocklist: 0,
userBlocked: 0,
},
rateLimited: 0,
},
});

Expand Down Expand Up @@ -332,6 +404,14 @@ t.test("it keeps track of requests", async () => {
total: 0,
blocked: 0,
},
blocked: {
total: 0,
allowedIpsRoute: 0,
userAgent: 0,
ipBlocklist: 0,
userBlocked: 0,
},
rateLimited: 0,
},
});

Expand All @@ -347,6 +427,14 @@ t.test("it keeps track of requests", async () => {
total: 0,
blocked: 0,
},
blocked: {
total: 0,
allowedIpsRoute: 0,
userAgent: 0,
ipBlocklist: 0,
userBlocked: 0,
},
rateLimited: 0,
},
});

Expand All @@ -363,6 +451,14 @@ t.test("it keeps track of requests", async () => {
total: 1,
blocked: 0,
},
blocked: {
total: 0,
allowedIpsRoute: 0,
userAgent: 0,
ipBlocklist: 0,
userBlocked: 0,
},
rateLimited: 0,
},
});

Expand All @@ -379,6 +475,14 @@ t.test("it keeps track of requests", async () => {
total: 2,
blocked: 1,
},
blocked: {
total: 0,
allowedIpsRoute: 0,
userAgent: 0,
ipBlocklist: 0,
userBlocked: 0,
},
rateLimited: 0,
},
});

Expand All @@ -396,6 +500,14 @@ t.test("it keeps track of requests", async () => {
total: 0,
blocked: 0,
},
blocked: {
total: 0,
allowedIpsRoute: 0,
userAgent: 0,
ipBlocklist: 0,
userBlocked: 0,
},
rateLimited: 0,
},
});

Expand All @@ -420,6 +532,14 @@ t.test("it force compresses stats", async () => {
total: 0,
blocked: 0,
},
blocked: {
total: 0,
allowedIpsRoute: 0,
userAgent: 0,
ipBlocklist: 0,
userBlocked: 0,
},
rateLimited: 0,
},
});

Expand Down Expand Up @@ -462,6 +582,87 @@ t.test("it keeps track of aborted requests", async () => {
total: 0,
blocked: 0,
},
blocked: {
total: 0,
allowedIpsRoute: 0,
userAgent: 0,
ipBlocklist: 0,
userBlocked: 0,
},
rateLimited: 0,
},
});

clock.uninstall();
});

t.test("it keeps track of blocked requests", async () => {
const clock = FakeTimers.install();

const stats = new InspectionStatistics({
maxPerfSamplesInMemory: 50,
maxCompressedStatsInMemory: 5,
});

stats.onBlockedRequest({ reason: "ipBlocklist" });
stats.onBlockedRequest({ reason: "userAgent" });
stats.onBlockedRequest({ reason: "allowedIpsRoute" });
stats.onBlockedRequest({ reason: "userBlock" });

t.same(stats.getStats(), {
sinks: {},
startedAt: 0,
requests: {
total: 0,
aborted: 0,
attacksDetected: {
total: 0,
blocked: 0,
},
blocked: {
total: 4,
allowedIpsRoute: 1,
userAgent: 1,
ipBlocklist: 1,
userBlocked: 1,
},
rateLimited: 0,
},
});

clock.uninstall();
});

t.test("it keeps track of rate limited requests", async () => {
const clock = FakeTimers.install();

const stats = new InspectionStatistics({
maxPerfSamplesInMemory: 50,
maxCompressedStatsInMemory: 5,
});

stats.onRateLimitedRequest();

t.same(stats.getStats(), {
sinks: {},
startedAt: 0,
requests: {
total: 0,
aborted: 0,
attacksDetected: {
total: 0,
blocked: 0,
},
blocked: {
total: 0,
allowedIpsRoute: 0,
userAgent: 0,
ipBlocklist: 0,
userBlocked: 0,
},
rateLimited: 1,
},
});

clock.uninstall();
});
Loading
Loading