From 9bb77f9d9866b8b68e27aada18a14a6637b9695a Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Sun, 25 Aug 2024 09:23:55 +0200 Subject: [PATCH] Add more tests for ipBlockList function. --- tests/utils/ipBlockList.test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/utils/ipBlockList.test.js b/tests/utils/ipBlockList.test.js index 111310b..92c5f8b 100644 --- a/tests/utils/ipBlockList.test.js +++ b/tests/utils/ipBlockList.test.js @@ -78,4 +78,28 @@ describe("IP block list functionality", () => { false, ); }); + + test("should handle edge cases for IPv4 addresses", () => { + blockList.add("192.168.1.0/30"); + expect(blockList.check("192.168.1.1")).toBe(true); + expect(blockList.check("192.168.1.2")).toBe(true); + expect(blockList.check("192.168.1.3")).toBe(true); + expect(blockList.check("192.168.1.4")).toBe(false); + }); + + test("should handle edge cases for IPv6 addresses", () => { + blockList.add("2001:0db8:85a3::/64"); + expect(blockList.check("2001:0db8:85a2:ffff:ffff:ffff:ffff:ffff")).toBe( + false, + ); + expect(blockList.check("2001:0db8:85a3:0000:0000:0000:0000:0000")).toBe( + true, + ); + expect(blockList.check("2001:0db8:85a3:0000:ffff:ffff:ffff:ffff")).toBe( + true, + ); + expect(blockList.check("2001:0db8:85a3:0001:0000:0000:0000:0000")).toBe( + false, + ); + }); });