Skip to content

Commit 77fe7b0

Browse files
committed
Improve allowed ip addresses test
1 parent 4cbbb15 commit 77fe7b0

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

library/sources/Hono.onlyAllowIPAddresses.test.ts renamed to library/sources/Hono.allowedIPAddresses.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const agent = createTestAgent({
6161
blockedUserIds: ["567"],
6262
configUpdatedAt: 0,
6363
heartbeatIntervalInMS: 10 * 60 * 1000,
64-
allowedIPAddresses: ["4.3.2.1"],
64+
allowedIPAddresses: ["5.6.7.8"],
6565
}),
6666
});
6767
agent.start([new HonoInternal(), new HTTPServer()]);
@@ -124,5 +124,26 @@ t.test("test access only allowed for some IP addresses", opts, async (t) => {
124124
});
125125
t.equal(response4.statusCode, 200);
126126

127+
const response5 = await fetch.fetch({
128+
url: new URL("http://127.0.0.1:8768/"),
129+
headers: {
130+
"X-Forwarded-For": "11.9.8.7",
131+
},
132+
});
133+
t.equal(response5.statusCode, 403);
134+
t.equal(
135+
response5.body,
136+
"Your IP address is not allowed to access this resource. (Your IP: 11.9.8.7)"
137+
);
138+
139+
// Allow bypased IP addresses
140+
const response6 = await fetch.fetch({
141+
url: new URL("http://127.0.0.1:8768/"),
142+
headers: {
143+
"X-Forwarded-For": "5.6.7.8",
144+
},
145+
});
146+
t.equal(response6.statusCode, 200);
147+
127148
server.close();
128149
});

0 commit comments

Comments
 (0)