Skip to content

Commit

Permalink
Merge pull request #1 from texh/improvement/ip6
Browse files Browse the repository at this point in the history
Check if ip6:XXX is actually an IPv6 address
  • Loading branch information
c0bra committed Sep 10, 2018
2 parents d2836c6 + 981d906 commit 8b3f2aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mechanisms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
11 changes: 11 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8b3f2aa

Please sign in to comment.