From a0933da8d1398a6f4494e62b95d2444812054c68 Mon Sep 17 00:00:00 2001 From: Meisam <39205857+MFTabriz@users.noreply.github.com> Date: Tue, 6 Dec 2022 23:29:05 +0100 Subject: [PATCH] consider ipv6 in chat user tests (#2415) Co-authored-by: meisam --- test/automated/api/chatusers.test.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/test/automated/api/chatusers.test.js b/test/automated/api/chatusers.test.js index 468f4b11a..d37f78f62 100644 --- a/test/automated/api/chatusers.test.js +++ b/test/automated/api/chatusers.test.js @@ -154,17 +154,13 @@ test('ban an ip address', async (done) => { done(); }); -// Note: This test expects the local address to be 127.0.0.1. -// If it's running on an ipv6-only network, for example, things will -// probably fail. test('verify IP address is blocked from the ban', async (done) => { const response = await request .get(`/api/admin/chat/users/ipbans`) .auth('admin', 'abc123') .expect(200); - expect(response.body).toHaveLength(1); - expect(response.body[0].ipAddress).toBe(localIPAddress); + expect(onlyLocalIPAddress(response.body)).toBe(true); done(); }); @@ -196,3 +192,14 @@ test('verify access is again allowed', async (done) => { await request.get(`/api/chat?accessToken=${accessToken}`).expect(200); done(); }); + + +// This function expects the local address to be 127.0.0.1 & ::1 +function onlyLocalIPAddress(banInfo) { + for (let i = 0; i < banInfo.length; i++) { + if ((banInfo[i].ipAddress != "127.0.0.1") && (banInfo[i].ipAddress != "::1")) { + return false + } + } + return true +} \ No newline at end of file