Skip to content

Commit 32ac11a

Browse files
fix ipaddr.js failing tests
Failing tests with the same error message: `Error: ipaddr: the address has neither IPv6 nor IPv4 CIDR format` List of ip failing: - `123` - ` ` (empty string) - `192.168.1.1` - `2001:0db8:85a3:0000:0000:8a2e:0370:7334` - `2001:0db8:85a3:0000:XYZZ:8a2e:0370:7334` - `2001::85a3::8a2e`
1 parent 6b4e21e commit 32ac11a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/api/apiUtils/authorization/permissionChecks.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { evaluators, actionMaps, RequestContext, requestUtils } = require('arsenal').policies;
22
const { errorInstances } = require('arsenal');
3-
const { parseCIDR } = require('ipaddr.js');
3+
const { parseCIDR, isValid } = require('ipaddr.js');
44
const constants = require('../../../../constants');
55
const { config } = require('../../../Config');
66

@@ -554,8 +554,10 @@ function checkIp(value) {
554554
parseCIDR(values[i]);
555555
} catch (err) {
556556
// eslint-disable-next-line no-console
557-
console.log('=== INVALID IP ===', values[i], err);
558-
return errString;
557+
if (!isValid(values[i])) {
558+
console.log('=== INVALID IP ===', values[i], err);
559+
return errString;
560+
}
559561
}
560562

561563
if (validateIpRegex(values[i]) !== true) {

0 commit comments

Comments
 (0)