From 981d906df2b31ca2dffe649dcd6e1b28052670f3 Mon Sep 17 00:00:00 2001 From: Jarrod Linahan Date: Mon, 10 Sep 2018 07:33:00 +1000 Subject: [PATCH] Check if ip6: is **actually** an IPv6 address --- mechanisms.js | 2 +- test/test.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/mechanisms.js b/mechanisms.js index da17062..f2aeb70 100644 --- a/mechanisms.js +++ b/mechanisms.js @@ -123,7 +123,7 @@ module.exports = { throw new MechanismError(`Missing or blank mandatory network specification for the 'ip6' mechanism.`, 'error'); } - if (!ipaddr.isValid(ip)) { + if (!ipaddr.IPv6.isValid(ip)) { throw new MechanismError(`Invalid IPv6 address: '${ip}'`, 'error'); } diff --git a/test/test.js b/test/test.js index c1a526f..1d2d7cd 100644 --- a/test/test.js +++ b/test/test.js @@ -148,6 +148,17 @@ test('Invalid ip6 fails', t => { ]); }); +test('IPv4 is not an IPv6', t => { + const m = []; + s.parseTerm('ip6:127.0.0.1', m); + t.deepEqual(m, [ + { + message: `Invalid IPv6 address: '127.0.0.1'`, + type: 'error' + } + ]); +}); + test('Invalid ip6 CIDR fails', t => { const m = []; s.parseTerm('ip6:::1/720', m);