Skip to content
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
1 change: 0 additions & 1 deletion end2end/server/src/zen/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ function generateConfig(app) {
endpoints: [],
blockedUserIds: [],
allowedIPAddresses: [],
receivedAnyStats: false,
};
}

Expand Down
2 changes: 0 additions & 2 deletions library/agent/Agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ t.test(
blockedUserIds: [],
allowedIPAddresses: [],
block: true,
receivedAnyStats: false,
});
const agent = createTestAgent({
api,
Expand Down Expand Up @@ -490,7 +489,6 @@ t.test(
blockedUserIds: [],
allowedIPAddresses: [],
block: true,
receivedAnyStats: false,
});
const agent = createTestAgent({
api,
Expand Down
15 changes: 2 additions & 13 deletions library/agent/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,7 @@ export class Agent {
private timeoutInMS = 30 * 1000;
private hostnames = new Hostnames(200);
private users = new Users(1000);
private serviceConfig = new ServiceConfig(
[],
Date.now(),
[],
[],
true,
[],
[]
);
private serviceConfig = new ServiceConfig([], Date.now(), [], [], [], []);
private routes: Routes = new Routes(200);
private rateLimiter: RateLimiter = new RateLimiter(5000, 120 * 60 * 1000);
private statistics = new InspectionStatistics({
Expand Down Expand Up @@ -310,10 +302,7 @@ export class Agent {
response.allowedIPAddresses &&
Array.isArray(response.allowedIPAddresses)
? response.allowedIPAddresses
: [],
typeof response.receivedAnyStats === "boolean"
? response.receivedAnyStats
: true
: []
);
}

Expand Down
1 change: 0 additions & 1 deletion library/agent/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ export type Config = {
blockedUserIds: string[];
allowedIPAddresses: string[];
block?: boolean;
receivedAnyStats?: boolean;
};
34 changes: 11 additions & 23 deletions library/agent/ServiceConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as t from "tap";
import { ServiceConfig } from "./ServiceConfig";

t.test("it returns false if empty rules", async () => {
const config = new ServiceConfig([], 0, [], [], false, [], []);
const config = new ServiceConfig([], 0, [], [], [], []);
t.same(config.getLastUpdatedAt(), 0);
t.same(config.isUserBlocked("id"), false);
t.same(config.isBypassedIP("1.2.3.4"), false);
Expand Down Expand Up @@ -53,7 +53,6 @@ t.test("it works", async () => {
0,
["123"],
[],
false,
[],
[]
);
Expand Down Expand Up @@ -83,7 +82,7 @@ t.test("it works", async () => {
});

t.test("it checks if IP is bypassed", async () => {
const config = new ServiceConfig([], 0, [], ["1.2.3.4"], false, [], []);
const config = new ServiceConfig([], 0, [], ["1.2.3.4"], [], []);
t.same(config.isBypassedIP("1.2.3.4"), true);
t.same(config.isBypassedIP("1.2.3.5"), false);
});
Expand All @@ -94,7 +93,6 @@ t.test("ip blocking works", async () => {
0,
[],
[],
false,
[
{
key: "geoip/Belgium;BE",
Expand Down Expand Up @@ -143,7 +141,7 @@ t.test("ip blocking works", async () => {
});

t.test("it blocks bots", async () => {
const config = new ServiceConfig([], 0, [], [], true, [], []);
const config = new ServiceConfig([], 0, [], [], [], []);
config.updateBlockedUserAgents("googlebot|bingbot");

t.same(config.isUserAgentBlocked("googlebot"), { blocked: true });
Expand All @@ -161,7 +159,6 @@ t.test("restricting access to some ips", async () => {
0,
[],
[],
true,
[],
[
{
Expand Down Expand Up @@ -189,7 +186,6 @@ t.test("only allow some ips: empty list", async () => {
0,
[],
[],
true,
[],
[
{
Expand All @@ -211,7 +207,6 @@ t.test("bypassed ips support cidr", async () => {
0,
[],
["192.168.2.0/24", "::1"],
false,
[],
[]
);
Expand All @@ -221,13 +216,7 @@ t.test("bypassed ips support cidr", async () => {
t.same(config.isBypassedIP("::2"), false);
t.same(config.isBypassedIP("10.0.0.1"), false);

config.updateConfig(
[],
0,
[],
["invalid", "2002::1/124", "127.0.0.1"],
false
);
config.updateConfig([], 0, [], ["invalid", "2002::1/124", "127.0.0.1"]);

t.same(config.isBypassedIP("2002::6"), true);
t.same(config.isBypassedIP("2002::f"), true);
Expand All @@ -240,8 +229,7 @@ t.test("bypassed ips support cidr", async () => {
[],
0,
[],
["0", "123.123.123.1/32", "234.0.0.0/8", "999.999.999.999", "::1/128"],
false
["0", "123.123.123.1/32", "234.0.0.0/8", "999.999.999.999", "::1/128"]
);

t.same(config.isBypassedIP("123.123.123.1"), true);
Expand All @@ -253,14 +241,14 @@ t.test("bypassed ips support cidr", async () => {
t.same(config.isBypassedIP("::1"), true);
t.same(config.isBypassedIP("::2"), false);

config.updateConfig([], 0, [], [], false);
config.updateConfig([], 0, [], []);

t.same(config.isBypassedIP("123.123.123.1"), false);
t.same(config.isBypassedIP("999.999.999.999"), false);
});

t.test("it sets and updates monitored IP lists", async (t) => {
const config = new ServiceConfig([], 0, [], [], false, [], []);
const config = new ServiceConfig([], 0, [], [], [], []);

t.same(config.getMatchingMonitoredIPListKeys("9.9.9.9"), []);
t.same(config.getMatchingMonitoredIPListKeys("1.2.3.4"), []);
Expand All @@ -284,7 +272,7 @@ t.test("it sets and updates monitored IP lists", async (t) => {
});

t.test("it returns matching IP lists keys", async (t) => {
const config = new ServiceConfig([], 0, [], [], false, [], []);
const config = new ServiceConfig([], 0, [], [], [], []);

config.updateMonitoredIPAddresses([
{
Expand Down Expand Up @@ -340,7 +328,7 @@ t.test("it returns matching IP lists keys", async (t) => {
});

t.test("should return all matching user agent patterns", async (t) => {
const config = new ServiceConfig([], 0, [], [], false, [], []);
const config = new ServiceConfig([], 0, [], [], [], []);
config.updateUserAgentDetails([
{
key: "list1",
Expand All @@ -359,7 +347,7 @@ t.test("should return all matching user agent patterns", async (t) => {
});

t.test("it clears RegExp when updating with empty pattern", async (t) => {
const config = new ServiceConfig([], 0, [], [], false, [], []);
const config = new ServiceConfig([], 0, [], [], [], []);
config.updateBlockedUserAgents("googlebot");
config.updateMonitoredUserAgents("googlebot");
config.updateUserAgentDetails([
Expand All @@ -381,7 +369,7 @@ t.test("it clears RegExp when updating with empty pattern", async (t) => {
t.test(
"it does not throw error when updating user agent lists with invalid patterns",
async (t) => {
const config = new ServiceConfig([], 0, [], [], false, [], []);
const config = new ServiceConfig([], 0, [], [], [], []);

config.updateBlockedUserAgents("googlebot");
config.updateMonitoredUserAgents("googlebot");
Expand Down
9 changes: 1 addition & 8 deletions library/agent/ServiceConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export class ServiceConfig {
private lastUpdatedAt: number,
blockedUserIds: string[],
bypassedIPAddresses: string[],
private receivedAnyStats: boolean,
blockedIPAddresses: IPList[],
allowedIPAddresses: IPList[]
) {
Expand Down Expand Up @@ -261,21 +260,15 @@ export class ServiceConfig {
endpoints: EndpointConfig[],
lastUpdatedAt: number,
blockedUserIds: string[],
bypassedIPAddresses: string[],
hasReceivedAnyStats: boolean
bypassedIPAddresses: string[]
) {
this.setEndpoints(endpoints);
this.setBlockedUserIds(blockedUserIds);
this.setBypassedIPAddresses(bypassedIPAddresses);
this.lastUpdatedAt = lastUpdatedAt;
this.receivedAnyStats = hasReceivedAnyStats;
}

getLastUpdatedAt() {
return this.lastUpdatedAt;
}

hasReceivedAnyStats() {
return this.receivedAnyStats;
}
}
11 changes: 1 addition & 10 deletions library/ratelimiting/getRateLimitedEndpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ const context: Context = {

t.test("it returns undefined if no endpoints", async () => {
t.same(
getRateLimitedEndpoint(
context,
new ServiceConfig([], 0, [], [], true, [], [])
),
getRateLimitedEndpoint(context, new ServiceConfig([], 0, [], [], [], [])),
undefined
);
});
Expand All @@ -47,7 +44,6 @@ t.test("it returns undefined if no matching endpoints", async () => {
0,
[],
[],
false,
[],
[]
)
Expand Down Expand Up @@ -77,7 +73,6 @@ t.test("it returns undefined if matching but not enabled", async () => {
0,
[],
[],
false,
[],
[]
)
Expand Down Expand Up @@ -107,7 +102,6 @@ t.test("it returns endpoint if matching and enabled", async () => {
0,
[],
[],
false,
[],
[]
)
Expand Down Expand Up @@ -158,7 +152,6 @@ t.test("it returns endpoint with lowest max requests", async () => {
0,
[],
[],
false,
[],
[]
)
Expand Down Expand Up @@ -209,7 +202,6 @@ t.test("it returns endpoint with smallest window size", async () => {
0,
[],
[],
false,
[],
[]
)
Expand Down Expand Up @@ -260,7 +252,6 @@ t.test("it always returns exact matches first", async () => {
0,
[],
[],
false,
[],
[]
)
Expand Down
1 change: 0 additions & 1 deletion library/sinks/Undici.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export async function createUndiciTests(undiciPkgName: string, port: number) {
blockedUserIds: [],
allowedIPAddresses: ["1.2.3.4"],
block: true,
receivedAnyStats: false,
});
const agent = startTestAgent({
api,
Expand Down
1 change: 0 additions & 1 deletion library/sinks/Undici2.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export async function createUndiciTests(undiciPkgName: string, port: number) {
blockedUserIds: [],
allowedIPAddresses: ["1.2.3.4"],
block: true,
receivedAnyStats: false,
});
const agent = startTestAgent({
api,
Expand Down