Skip to content

Commit b9557b1

Browse files
committed
Add tests
1 parent 7d656b8 commit b9557b1

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

library/sources/HTTPServer.stats.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,13 @@ wrap(fetchBlockedLists, "fetchBlockedLists", function fetchBlockedLists() {
4949
key: "google_extended",
5050
pattern: "Google-Extended",
5151
},
52+
{
53+
key: "chatgpt_agent",
54+
pattern: "chatgpt.com",
55+
},
5256
],
5357
blockedSignatureAgents: "",
54-
monitoredSignatureAgents: "",
58+
monitoredSignatureAgents: "chatgpt.com",
5559
} satisfies Response;
5660
};
5761
});
@@ -97,17 +101,28 @@ t.test("it tracks monitored user agents", async () => {
97101
},
98102
timeoutInMS: 500,
99103
}),
100-
]).then(([response1, response2, response3]) => {
104+
fetch({
105+
url: new URL("http://localhost:3327/test"),
106+
method: "GET",
107+
headers: {
108+
"Signature-Agent": "chatgpt.com",
109+
},
110+
timeoutInMS: 500,
111+
}),
112+
]).then(([response1, response2, response3, response4]) => {
101113
t.equal(response1.statusCode, 200);
102114
t.equal(response2.statusCode, 200);
103115
t.equal(response3.statusCode, 200);
116+
t.equal(response4.statusCode, 200);
104117
const stats = agent.getInspectionStatistics().getStats();
105118
t.same(stats.userAgents, {
106119
breakdown: {
107120
// eslint-disable-next-line camelcase
108121
ai_data_scrapers: 1,
109122
// eslint-disable-next-line camelcase
110123
google_extended: 1,
124+
// eslint-disable-next-line camelcase
125+
chatgpt_agent: 1,
111126
},
112127
});
113128
t.same(stats.ipAddresses, {

library/sources/Hono.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,16 @@ t.test("bypass list works", opts, async (t) => {
614614
});
615615
t.equal(response6.statusCode, 403);
616616

617+
// Not blocked signature agent
618+
const response7 = await fetch.fetch({
619+
url: new URL("http://127.0.0.1:8769/"),
620+
headers: {
621+
"X-Forwarded-For": "2.3.4.5",
622+
"Signature-Agent": "some-other-agent",
623+
},
624+
});
625+
t.equal(response7.statusCode, 200);
626+
617627
// Cleanup server
618628
server.close();
619629
});

0 commit comments

Comments
 (0)