consider ipv6 in chat user tests (#2415)
Co-authored-by: meisam <meisam@noreply.codeberg.org>
This commit is contained in:
@@ -154,17 +154,13 @@ test('ban an ip address', async (done) => {
|
|||||||
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) => {
|
test('verify IP address is blocked from the ban', async (done) => {
|
||||||
const response = await request
|
const response = await request
|
||||||
.get(`/api/admin/chat/users/ipbans`)
|
.get(`/api/admin/chat/users/ipbans`)
|
||||||
.auth('admin', 'abc123')
|
.auth('admin', 'abc123')
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect(response.body).toHaveLength(1);
|
expect(onlyLocalIPAddress(response.body)).toBe(true);
|
||||||
expect(response.body[0].ipAddress).toBe(localIPAddress);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -196,3 +192,14 @@ test('verify access is again allowed', async (done) => {
|
|||||||
await request.get(`/api/chat?accessToken=${accessToken}`).expect(200);
|
await request.get(`/api/chat?accessToken=${accessToken}`).expect(200);
|
||||||
done();
|
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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user