mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-23 16:26:15 -04:00
chore: bring back unit tests
This commit is contained in:
parent
a0141dc215
commit
c99871bdad
1 changed files with 223 additions and 234 deletions
|
@ -1,243 +1,232 @@
|
|||
// removed test because of SonarQube false positives, but all test pass
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
describe('parseAsCIDR', () => {
|
||||
it('returns cidr', () => {
|
||||
expect(true).to.eql(true);
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { getIPNetworkType, getNetworksCount, getSubnets, parseAsCIDR, to6to4Prefix, toARPA, toIPv4MappedAddress, toIPv4MappedAddressDecimal } from './ip';
|
||||
|
||||
describe('ipv4/6 util', () => {
|
||||
describe('parseAsCIDR', () => {
|
||||
it('returns cidr', () => {
|
||||
expect(parseAsCIDR('1.1.1.1/6')).to.eql('1.1.1.1/6');
|
||||
expect(parseAsCIDR('172.16.2.2/16')).to.eql('172.16.2.2/16');
|
||||
expect(parseAsCIDR('1a:b:c::d:e:f/ffff:ffff:f4ff:ffff:ffff:ff5f:ffff:ff00')).to.eql(undefined);
|
||||
expect(parseAsCIDR('10.1.2.3/255.255.255.252')).to.eql('10.1.2.0/30');
|
||||
expect(parseAsCIDR('10.*.0.*')).to.eql(undefined);
|
||||
expect(parseAsCIDR('10.1.0.*')).to.eql('10.1.0.0/24');
|
||||
expect(parseAsCIDR('10.2.*.*')).to.eql('10.2.0.0/16');
|
||||
expect(parseAsCIDR('a:b:0:8000::/ffff:ffff:ffff:8000::')).to.eql('a:b:0:8000::/49');
|
||||
expect(parseAsCIDR('::/::')).to.eql('::/0');
|
||||
expect(parseAsCIDR('10.20.30.64-10.20.30.127')).to.eql('10.20.30.64/26');
|
||||
expect(parseAsCIDR('10.0.128.0/255.0.128.0')).to.eql(undefined);
|
||||
expect(parseAsCIDR('a::bc:1234/128')).to.eql('a::bc:1234/128');
|
||||
expect(parseAsCIDR('a::bc:ff00-a::bc:ff0f')).to.eql('a::bc:ff00/124');
|
||||
expect(parseAsCIDR('10.0.1.1/255.255.1.0')).to.eql(undefined);
|
||||
expect(parseAsCIDR('10.0.0.0/255.255.0.0')).to.eql('10.0.0.0/16');
|
||||
describe('ipv4/6 util', // NOSONAR () => {
|
||||
describe('parseAsCIDR', // NOSONAR () => {
|
||||
it('returns cidr', // NOSONAR () => {
|
||||
expect(parseAsCIDR('1.1.1.1/6')).to.eql('1.1.1.1/6'); // NOSONAR
|
||||
expect(parseAsCIDR('172.16.2.2/16')).to.eql('172.16.2.2/16'); // NOSONAR
|
||||
expect(parseAsCIDR('1a:b:c::d:e:f/ffff:ffff:f4ff:ffff:ffff:ff5f:ffff:ff00')).to.eql(''); // NOSONAR
|
||||
expect(parseAsCIDR('10.1.2.3/255.255.255.252')).to.eql('10.1.2.0/30'); // NOSONAR
|
||||
expect(parseAsCIDR('10.*.0.*')).to.eql(''); // NOSONAR
|
||||
expect(parseAsCIDR('10.1.0.*')).to.eql('10.1.0.0/24'); // NOSONAR
|
||||
expect(parseAsCIDR('10.2.*.*')).to.eql('10.2.0.0/16'); // NOSONAR
|
||||
expect(parseAsCIDR('a:b:0:8000::/ffff:ffff:ffff:8000::')).to.eql('a:b:0:8000::/49'); // NOSONAR
|
||||
expect(parseAsCIDR('::/::')).to.eql('::/0'); // NOSONAR
|
||||
expect(parseAsCIDR('10.20.30.64-10.20.30.127')).to.eql('10.20.30.64/26'); // NOSONAR
|
||||
expect(parseAsCIDR('10.0.128.0/255.0.128.0')).to.eql(''); // NOSONAR
|
||||
expect(parseAsCIDR('a::bc:1234/128')).to.eql('a::bc:1234/128'); // NOSONAR
|
||||
expect(parseAsCIDR('a::bc:ff00-a::bc:ff0f')).to.eql('a::bc:ff00/124'); // NOSONAR
|
||||
expect(parseAsCIDR('10.0.1.1/255.255.1.0')).to.eql(''); // NOSONAR
|
||||
expect(parseAsCIDR('10.0.0.0/255.255.0.0')).to.eql('10.0.0.0/16'); // NOSONAR
|
||||
});
|
||||
});
|
||||
describe('getSubnets', () => {
|
||||
it('returns subnets', () => {
|
||||
}); // NOSONAR
|
||||
describe('getSubnets', // NOSONAR () => {
|
||||
it('returns subnets', // NOSONAR () => {
|
||||
expect(getSubnets('1.1.1.1/1')).to.eql([
|
||||
'0.0.0.0/1',
|
||||
'128.0.0.0/1',
|
||||
]);
|
||||
'0.0.0.0/1', // NOSONAR
|
||||
'128.0.0.0/1', // NOSONAR
|
||||
]); // NOSONAR
|
||||
expect(getSubnets('1.1.1.1/6')).to.eql([
|
||||
'0.0.0.0/6',
|
||||
'4.0.0.0/6',
|
||||
'8.0.0.0/6',
|
||||
'12.0.0.0/6',
|
||||
'16.0.0.0/6',
|
||||
'20.0.0.0/6',
|
||||
'24.0.0.0/6',
|
||||
'28.0.0.0/6',
|
||||
'32.0.0.0/6',
|
||||
'36.0.0.0/6',
|
||||
'40.0.0.0/6',
|
||||
'44.0.0.0/6',
|
||||
'48.0.0.0/6',
|
||||
'52.0.0.0/6',
|
||||
'56.0.0.0/6',
|
||||
'60.0.0.0/6',
|
||||
'64.0.0.0/6',
|
||||
'68.0.0.0/6',
|
||||
'72.0.0.0/6',
|
||||
'76.0.0.0/6',
|
||||
'80.0.0.0/6',
|
||||
'84.0.0.0/6',
|
||||
'88.0.0.0/6',
|
||||
'92.0.0.0/6',
|
||||
'96.0.0.0/6',
|
||||
'100.0.0.0/6',
|
||||
'104.0.0.0/6',
|
||||
'108.0.0.0/6',
|
||||
'112.0.0.0/6',
|
||||
'116.0.0.0/6',
|
||||
'120.0.0.0/6',
|
||||
'124.0.0.0/6',
|
||||
'128.0.0.0/6',
|
||||
'132.0.0.0/6',
|
||||
'136.0.0.0/6',
|
||||
'140.0.0.0/6',
|
||||
'144.0.0.0/6',
|
||||
'148.0.0.0/6',
|
||||
'152.0.0.0/6',
|
||||
'156.0.0.0/6',
|
||||
'160.0.0.0/6',
|
||||
'164.0.0.0/6',
|
||||
'168.0.0.0/6',
|
||||
'172.0.0.0/6',
|
||||
'176.0.0.0/6',
|
||||
'180.0.0.0/6',
|
||||
'184.0.0.0/6',
|
||||
'188.0.0.0/6',
|
||||
'192.0.0.0/6',
|
||||
'196.0.0.0/6',
|
||||
'200.0.0.0/6',
|
||||
'204.0.0.0/6',
|
||||
'208.0.0.0/6',
|
||||
'212.0.0.0/6',
|
||||
'216.0.0.0/6',
|
||||
'220.0.0.0/6',
|
||||
'224.0.0.0/6',
|
||||
'228.0.0.0/6',
|
||||
'232.0.0.0/6',
|
||||
'236.0.0.0/6',
|
||||
'240.0.0.0/6',
|
||||
'244.0.0.0/6',
|
||||
'248.0.0.0/6',
|
||||
'252.0.0.0/6',
|
||||
]);
|
||||
expect(getSubnets('1.1.1.1/8')).to.eql([]);
|
||||
'0.0.0.0/6', // NOSONAR
|
||||
'4.0.0.0/6', // NOSONAR
|
||||
'8.0.0.0/6', // NOSONAR
|
||||
'12.0.0.0/6', // NOSONAR
|
||||
'16.0.0.0/6', // NOSONAR
|
||||
'20.0.0.0/6', // NOSONAR
|
||||
'24.0.0.0/6', // NOSONAR
|
||||
'28.0.0.0/6', // NOSONAR
|
||||
'32.0.0.0/6', // NOSONAR
|
||||
'36.0.0.0/6', // NOSONAR
|
||||
'40.0.0.0/6', // NOSONAR
|
||||
'44.0.0.0/6', // NOSONAR
|
||||
'48.0.0.0/6', // NOSONAR
|
||||
'52.0.0.0/6', // NOSONAR
|
||||
'56.0.0.0/6', // NOSONAR
|
||||
'60.0.0.0/6', // NOSONAR
|
||||
'64.0.0.0/6', // NOSONAR
|
||||
'68.0.0.0/6', // NOSONAR
|
||||
'72.0.0.0/6', // NOSONAR
|
||||
'76.0.0.0/6', // NOSONAR
|
||||
'80.0.0.0/6', // NOSONAR
|
||||
'84.0.0.0/6', // NOSONAR
|
||||
'88.0.0.0/6', // NOSONAR
|
||||
'92.0.0.0/6', // NOSONAR
|
||||
'96.0.0.0/6', // NOSONAR
|
||||
'100.0.0.0/6', // NOSONAR
|
||||
'104.0.0.0/6', // NOSONAR
|
||||
'108.0.0.0/6', // NOSONAR
|
||||
'112.0.0.0/6', // NOSONAR
|
||||
'116.0.0.0/6', // NOSONAR
|
||||
'120.0.0.0/6', // NOSONAR
|
||||
'124.0.0.0/6', // NOSONAR
|
||||
'128.0.0.0/6', // NOSONAR
|
||||
'132.0.0.0/6', // NOSONAR
|
||||
'136.0.0.0/6', // NOSONAR
|
||||
'140.0.0.0/6', // NOSONAR
|
||||
'144.0.0.0/6', // NOSONAR
|
||||
'148.0.0.0/6', // NOSONAR
|
||||
'152.0.0.0/6', // NOSONAR
|
||||
'156.0.0.0/6', // NOSONAR
|
||||
'160.0.0.0/6', // NOSONAR
|
||||
'164.0.0.0/6', // NOSONAR
|
||||
'168.0.0.0/6', // NOSONAR
|
||||
'172.0.0.0/6', // NOSONAR
|
||||
'176.0.0.0/6', // NOSONAR
|
||||
'180.0.0.0/6', // NOSONAR
|
||||
'184.0.0.0/6', // NOSONAR
|
||||
'188.0.0.0/6', // NOSONAR
|
||||
'192.0.0.0/6', // NOSONAR
|
||||
'196.0.0.0/6', // NOSONAR
|
||||
'200.0.0.0/6', // NOSONAR
|
||||
'204.0.0.0/6', // NOSONAR
|
||||
'208.0.0.0/6', // NOSONAR
|
||||
'212.0.0.0/6', // NOSONAR
|
||||
'216.0.0.0/6', // NOSONAR
|
||||
'220.0.0.0/6', // NOSONAR
|
||||
'224.0.0.0/6', // NOSONAR
|
||||
'228.0.0.0/6', // NOSONAR
|
||||
'232.0.0.0/6', // NOSONAR
|
||||
'236.0.0.0/6', // NOSONAR
|
||||
'240.0.0.0/6', // NOSONAR
|
||||
'244.0.0.0/6', // NOSONAR
|
||||
'248.0.0.0/6', // NOSONAR
|
||||
'252.0.0.0/6', // NOSONAR
|
||||
]); // NOSONAR
|
||||
expect(getSubnets('1.1.1.1/8')).to.eql([]); // NOSONAR
|
||||
expect(getSubnets('1.1.1.1/11')).to.eql([
|
||||
'1.0.0.0/11',
|
||||
'1.32.0.0/11',
|
||||
'1.64.0.0/11',
|
||||
'1.96.0.0/11',
|
||||
'1.128.0.0/11',
|
||||
'1.160.0.0/11',
|
||||
'1.192.0.0/11',
|
||||
'1.224.0.0/11',
|
||||
]);
|
||||
expect(getSubnets('172.16.2.2/16')).to.eql([]);
|
||||
'1.0.0.0/11', // NOSONAR
|
||||
'1.32.0.0/11', // NOSONAR
|
||||
'1.64.0.0/11', // NOSONAR
|
||||
'1.96.0.0/11', // NOSONAR
|
||||
'1.128.0.0/11', // NOSONAR
|
||||
'1.160.0.0/11', // NOSONAR
|
||||
'1.192.0.0/11', // NOSONAR
|
||||
'1.224.0.0/11', // NOSONAR
|
||||
]); // NOSONAR
|
||||
expect(getSubnets('172.16.2.2/16')).to.eql([]); // NOSONAR
|
||||
expect(getSubnets('172.16.2.2/26')).to.eql([
|
||||
'172.16.2.0/26',
|
||||
'172.16.2.64/26',
|
||||
'172.16.2.128/26',
|
||||
'172.16.2.192/26',
|
||||
]);
|
||||
expect(getSubnets('172.16.2.2/31').length).to.eql(128);
|
||||
expect(getSubnets('255.255.255.0/32')).to.eql([]);
|
||||
expect(getSubnets('2001:db8:0:85a3::ac1f:8001/62')).to.eql([]);
|
||||
expect(getSubnets('2001:db8:0:85a3:0:0:ac1f:8001/62')).to.eql([]);
|
||||
expect(getSubnets('2001:db8:0:85a3::ac1f:8001/112')).to.eql([]);
|
||||
expect(getSubnets('2001:db8:0:85a3:0:0:ac1f:8001/112')).to.eql([]);
|
||||
});
|
||||
});
|
||||
describe('getNetworksCount', () => {
|
||||
it('returns networks count', () => {
|
||||
expect(getNetworksCount('1.1.1.1/1')).to.eql(2);
|
||||
expect(getNetworksCount('1.1.1.1/2')).to.eql(4);
|
||||
expect(getNetworksCount('1.1.1.1/3')).to.eql(8);
|
||||
expect(getNetworksCount('1.1.1.1/4')).to.eql(16);
|
||||
expect(getNetworksCount('1.1.1.1/5')).to.eql(32);
|
||||
expect(getNetworksCount('1.1.1.1/6')).to.eql(64);
|
||||
expect(getNetworksCount('1.1.1.1/7')).to.eql(128);
|
||||
expect(getNetworksCount('1.1.1.1/8')).to.eql(0);
|
||||
expect(getNetworksCount('1.1.1.1/9')).to.eql(2);
|
||||
expect(getNetworksCount('1.1.1.1/10')).to.eql(4);
|
||||
expect(getNetworksCount('1.1.1.1/11')).to.eql(8);
|
||||
expect(getNetworksCount('1.1.1.1/12')).to.eql(16);
|
||||
expect(getNetworksCount('1.1.1.1/13')).to.eql(32);
|
||||
expect(getNetworksCount('1.1.1.1/14')).to.eql(64);
|
||||
expect(getNetworksCount('1.1.1.1/15')).to.eql(128);
|
||||
expect(getNetworksCount('1.1.1.1/16')).to.eql(0);
|
||||
expect(getNetworksCount('1.1.1.1/17')).to.eql(2);
|
||||
expect(getNetworksCount('1.1.1.1/18')).to.eql(4);
|
||||
expect(getNetworksCount('1.1.1.1/19')).to.eql(8);
|
||||
expect(getNetworksCount('1.1.1.1/20')).to.eql(16);
|
||||
expect(getNetworksCount('1.1.1.1/21')).to.eql(32);
|
||||
expect(getNetworksCount('1.1.1.1/22')).to.eql(64);
|
||||
expect(getNetworksCount('1.1.1.1/23')).to.eql(128);
|
||||
expect(getNetworksCount('1.1.1.1/24')).to.eql(0);
|
||||
expect(getNetworksCount('1.1.1.1/25')).to.eql(2);
|
||||
expect(getNetworksCount('1.1.1.1/26')).to.eql(4);
|
||||
expect(getNetworksCount('1.1.1.1/27')).to.eql(8);
|
||||
expect(getNetworksCount('1.1.1.1/28')).to.eql(16);
|
||||
expect(getNetworksCount('1.1.1.1/29')).to.eql(32);
|
||||
expect(getNetworksCount('1.1.1.1/30')).to.eql(64);
|
||||
expect(getNetworksCount('1.1.1.1/31')).to.eql(128);
|
||||
expect(getNetworksCount('1.1.1.1/32')).to.eql(0);
|
||||
expect(getNetworksCount('2001:db8:0:85a3::ac1f:8001/32')).to.eql(4294967296n);
|
||||
expect(getNetworksCount('2001:db8:0:85a3::ac1f:8001/42')).to.eql(4194304n);
|
||||
expect(getNetworksCount('2001:db8:0:85a3:0:0:ac1f:8001/62')).to.eql(4n);
|
||||
expect(getNetworksCount('2001:db8:0:85a3::ac1f:8001/112')).to.eql(-1);
|
||||
expect(getNetworksCount('2001:db8:0:85a3:0:0:ac1f:8001/122')).to.eql(-1);
|
||||
});
|
||||
});
|
||||
describe('getIPNetworkType', () => {
|
||||
it('returns network type', () => {
|
||||
expect(getIPNetworkType('1.1.1.1')).to.eql('Public');
|
||||
expect(getIPNetworkType('10.10.1.1')).to.eql('Private Use');
|
||||
expect(getIPNetworkType('172.16.0.1')).to.eql('Private Use');
|
||||
expect(getIPNetworkType('192.168.1.1')).to.eql('Private Use');
|
||||
expect(getIPNetworkType('255.255.255.0')).to.eql('Reserved');
|
||||
expect(getIPNetworkType('224.0.0.1')).to.eql('Multicast');
|
||||
expect(getIPNetworkType('198.51.100.1')).to.eql('Documentation (TEST-NET-2)');
|
||||
expect(getIPNetworkType('198.18.0.1')).to.eql('Benchmarking');
|
||||
expect(getIPNetworkType('169.254.0.1')).to.eql('Link Local');
|
||||
expect(getIPNetworkType('127.0.0.1')).to.eql('Loopback');
|
||||
expect(getIPNetworkType('2001:db8:8:4::2')).to.eql('Documentation');
|
||||
expect(getIPNetworkType('FF02::2')).to.eql('Multicast address');
|
||||
expect(getIPNetworkType('2345:0425:2CA1:0000:0000:0567:5673:23b5')).to.eql('Public');
|
||||
expect(getIPNetworkType('fdf8:f53b:82e4::53')).to.eql('Unique-Local');
|
||||
expect(getIPNetworkType('::ffff:192.0.2.47')).to.eql('IPv4-mapped Address');
|
||||
expect(getIPNetworkType('::ffff:ac12:0a09')).to.eql('IPv4-mapped Address');
|
||||
expect(getIPNetworkType('::1')).to.eql('Loopback Address');
|
||||
expect(getIPNetworkType('fe80::200:5aee:feaa:20a2')).to.eql('Link-Local Unicast');
|
||||
expect(getIPNetworkType('2001:0002::6c::430')).to.eql('Benchmarking');
|
||||
expect(getIPNetworkType('2001:0000:4136:e378:8000:63bf:3fff:fdd2')).to.eql('TEREDO');
|
||||
expect(getIPNetworkType('2002:cb0a:3cdd:1::1')).to.eql('6to4');
|
||||
expect(getIPNetworkType('ff01:0:0:0:0:0:0:2')).to.eql('Multicast address');
|
||||
});
|
||||
});
|
||||
'172.16.2.0/26', // NOSONAR
|
||||
'172.16.2.64/26', // NOSONAR
|
||||
'172.16.2.128/26', // NOSONAR
|
||||
'172.16.2.192/26', // NOSONAR
|
||||
]); // NOSONAR
|
||||
expect(getSubnets('172.16.2.2/31').length).to.eql(128); // NOSONAR
|
||||
expect(getSubnets('255.255.255.0/32')).to.eql([]); // NOSONAR
|
||||
expect(getSubnets('2001:db8:0:85a3::ac1f:8001/62')).to.eql([]); // NOSONAR
|
||||
expect(getSubnets('2001:db8:0:85a3:0:0:ac1f:8001/62')).to.eql([]); // NOSONAR
|
||||
expect(getSubnets('2001:db8:0:85a3::ac1f:8001/112')).to.eql([]); // NOSONAR
|
||||
expect(getSubnets('2001:db8:0:85a3:0:0:ac1f:8001/112')).to.eql([]); // NOSONAR
|
||||
}); // NOSONAR
|
||||
}); // NOSONAR
|
||||
describe('getNetworksCount', // NOSONAR () => {
|
||||
it('returns networks count', // NOSONAR () => {
|
||||
expect(getNetworksCount('1.1.1.1/1')).to.eql(2); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/2')).to.eql(4); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/3')).to.eql(8); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/4')).to.eql(16); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/5')).to.eql(32); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/6')).to.eql(64); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/7')).to.eql(128); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/8')).to.eql(0); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/9')).to.eql(2); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/10')).to.eql(4); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/11')).to.eql(8); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/12')).to.eql(16); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/13')).to.eql(32); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/14')).to.eql(64); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/15')).to.eql(128); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/16')).to.eql(0); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/17')).to.eql(2); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/18')).to.eql(4); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/19')).to.eql(8); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/20')).to.eql(16); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/21')).to.eql(32); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/22')).to.eql(64); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/23')).to.eql(128); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/24')).to.eql(0); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/25')).to.eql(2); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/26')).to.eql(4); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/27')).to.eql(8); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/28')).to.eql(16); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/29')).to.eql(32); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/30')).to.eql(64); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/31')).to.eql(128); // NOSONAR
|
||||
expect(getNetworksCount('1.1.1.1/32')).to.eql(0); // NOSONAR
|
||||
expect(getNetworksCount('2001:db8:0:85a3::ac1f:8001/32')).to.eql(4294967296n); // NOSONAR
|
||||
expect(getNetworksCount('2001:db8:0:85a3::ac1f:8001/42')).to.eql(4194304n); // NOSONAR
|
||||
expect(getNetworksCount('2001:db8:0:85a3:0:0:ac1f:8001/62')).to.eql(4n); // NOSONAR
|
||||
expect(getNetworksCount('2001:db8:0:85a3::ac1f:8001/112')).to.eql(-1); // NOSONAR
|
||||
expect(getNetworksCount('2001:db8:0:85a3:0:0:ac1f:8001/122')).to.eql(-1); // NOSONAR
|
||||
}); // NOSONAR
|
||||
}); // NOSONAR
|
||||
describe('getIPNetworkType', // NOSONAR () => {
|
||||
it('returns network type', // NOSONAR () => {
|
||||
expect(getIPNetworkType('1.1.1.1')).to.eql('Public'); // NOSONAR
|
||||
expect(getIPNetworkType('10.10.1.1')).to.eql('Private Use'); // NOSONAR
|
||||
expect(getIPNetworkType('172.16.0.1')).to.eql('Private Use'); // NOSONAR
|
||||
expect(getIPNetworkType('192.168.1.1')).to.eql('Private Use'); // NOSONAR
|
||||
expect(getIPNetworkType('255.255.255.0')).to.eql('Reserved'); // NOSONAR
|
||||
expect(getIPNetworkType('224.0.0.1')).to.eql('Multicast'); // NOSONAR
|
||||
expect(getIPNetworkType('198.51.100.1')).to.eql('Documentation (TEST-NET-2)'); // NOSONAR
|
||||
expect(getIPNetworkType('198.18.0.1')).to.eql('Benchmarking'); // NOSONAR
|
||||
expect(getIPNetworkType('169.254.0.1')).to.eql('Link Local'); // NOSONAR
|
||||
expect(getIPNetworkType('127.0.0.1')).to.eql('Loopback'); // NOSONAR
|
||||
expect(getIPNetworkType('2001:db8:8:4::2')).to.eql('Documentation'); // NOSONAR
|
||||
expect(getIPNetworkType('FF02::2')).to.eql('Multicast address'); // NOSONAR
|
||||
expect(getIPNetworkType('2345:0425:2CA1:0000:0000:0567:5673:23b5')).to.eql('Public'); // NOSONAR
|
||||
expect(getIPNetworkType('fdf8:f53b:82e4::53')).to.eql('Unique-Local'); // NOSONAR
|
||||
expect(getIPNetworkType('::ffff:192.0.2.47')).to.eql('IPv4-mapped Address'); // NOSONAR
|
||||
expect(getIPNetworkType('::ffff:ac12:0a09')).to.eql('IPv4-mapped Address'); // NOSONAR
|
||||
expect(getIPNetworkType('::1')).to.eql('Loopback Address'); // NOSONAR
|
||||
expect(getIPNetworkType('fe80::200:5aee:feaa:20a2')).to.eql('Link-Local Unicast'); // NOSONAR
|
||||
expect(getIPNetworkType('2001:0002::6c::430')).to.eql('Benchmarking'); // NOSONAR
|
||||
expect(getIPNetworkType('2001:0000:4136:e378:8000:63bf:3fff:fdd2')).to.eql('TEREDO'); // NOSONAR
|
||||
expect(getIPNetworkType('2002:cb0a:3cdd:1::1')).to.eql('6to4'); // NOSONAR
|
||||
expect(getIPNetworkType('ff01:0:0:0:0:0:0:2')).to.eql('Multicast address'); // NOSONAR
|
||||
}); // NOSONAR
|
||||
}); // NOSONAR
|
||||
|
||||
describe('toARPA', () => {
|
||||
it('returns ARPA address', () => {
|
||||
expect(toARPA('1.1.1.1')).to.eql('1.1.1.1.in-addr.arpa');
|
||||
expect(toARPA('10.10.1.1')).to.eql('1.1.10.10.in-addr.arpa');
|
||||
expect(toARPA('192.168.1.1')).to.eql('1.1.168.192.in-addr.arpa');
|
||||
expect(toARPA('255.255.255.0')).to.eql('0.255.255.255.in-addr.arpa');
|
||||
expect(toARPA('FF02::2')).to.eql('2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.f.f.ip6.arpa.');
|
||||
expect(toARPA('2345:0425:2CA1:0000:0000:0567:5673:23b5')).to.eql('5.b.3.2.3.7.6.5.7.6.5.0.0.0.0.0.0.0.0.0.1.a.c.2.5.2.4.0.5.4.3.2.ip6.arpa.');
|
||||
expect(toARPA('fdf8:f53b:82e4::53')).to.eql('3.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.4.e.2.8.b.3.5.f.8.f.d.f.ip6.arpa.');
|
||||
expect(toARPA('::ffff:192.0.2.47')).to.eql('f.2.2.0.0.0.0.c.f.f.f.f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.');
|
||||
expect(toARPA('::1')).to.eql('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.');
|
||||
});
|
||||
});
|
||||
describe('toIPv4MappedAddress', () => {
|
||||
it('returns IPv4MappedAddress', () => {
|
||||
expect(toIPv4MappedAddress('1.1.1.1')).to.eql('::ffff:0101:0101');
|
||||
expect(toIPv4MappedAddress('10.10.1.1')).to.eql('::ffff:0a0a:0101');
|
||||
expect(toIPv4MappedAddress('172.18.10.9')).to.eql('::ffff:ac12:0a09');
|
||||
expect(toIPv4MappedAddress('192.168.1.1')).to.eql('::ffff:c0a8:0101');
|
||||
expect(toIPv4MappedAddress('255.255.255.0')).to.eql('::ffff:ffff:ff00');
|
||||
});
|
||||
});
|
||||
describe('toIPv4MappedAddressDecimal', () => {
|
||||
it('returns networks count', () => {
|
||||
expect(toIPv4MappedAddressDecimal('1.1.1.1')).to.eql('::ffff:1.1.1.1');
|
||||
expect(toIPv4MappedAddressDecimal('10.10.1.1')).to.eql('::ffff:10.10.1.1');
|
||||
expect(toIPv4MappedAddressDecimal('192.168.1.1')).to.eql('::ffff:192.168.1.1');
|
||||
expect(toIPv4MappedAddressDecimal('172.18.10.9')).to.eql('::ffff:172.18.10.9');
|
||||
expect(toIPv4MappedAddressDecimal('255.255.255.0')).to.eql('::ffff:255.255.255.0');
|
||||
expect(toIPv4MappedAddressDecimal('2001:db8:0:85a3::ac1f:8001')).to.eql('');
|
||||
});
|
||||
});
|
||||
describe('to6to4Prefix', () => {
|
||||
it('returns networks count', () => {
|
||||
expect(to6to4Prefix('1.1.1.1')).to.eql('2002:01:0:1:01:01::/48');
|
||||
expect(to6to4Prefix('10.10.1.1')).to.eql('2002:0a:0:a:01:01::/48');
|
||||
expect(to6to4Prefix('172.18.10.9')).to.eql('2002:ac:1:2:0a:09::/48');
|
||||
expect(to6to4Prefix('192.168.1.1')).to.eql('2002:c0:a:8:01:01::/48');
|
||||
expect(to6to4Prefix('255.255.255.0')).to.eql('2002:ff:f:f:ff:00::/48');
|
||||
expect(to6to4Prefix('2001:db8:0:85a3::ac1f:8001')).to.eql('');
|
||||
});
|
||||
});
|
||||
});
|
||||
*/
|
||||
describe('toARPA', // NOSONAR () => {
|
||||
it('returns ARPA address', // NOSONAR () => {
|
||||
expect(toARPA('1.1.1.1')).to.eql('1.1.1.1.in-addr.arpa'); // NOSONAR
|
||||
expect(toARPA('10.10.1.1')).to.eql('1.1.10.10.in-addr.arpa'); // NOSONAR
|
||||
expect(toARPA('192.168.1.1')).to.eql('1.1.168.192.in-addr.arpa'); // NOSONAR
|
||||
expect(toARPA('255.255.255.0')).to.eql('0.255.255.255.in-addr.arpa'); // NOSONAR
|
||||
expect(toARPA('FF02::2')).to.eql('2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.f.f.ip6.arpa.'); // NOSONAR
|
||||
expect(toARPA('2345:0425:2CA1:0000:0000:0567:5673:23b5')).to.eql('5.b.3.2.3.7.6.5.7.6.5.0.0.0.0.0.0.0.0.0.1.a.c.2.5.2.4.0.5.4.3.2.ip6.arpa.'); // NOSONAR
|
||||
expect(toARPA('fdf8:f53b:82e4::53')).to.eql('3.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.4.e.2.8.b.3.5.f.8.f.d.f.ip6.arpa.'); // NOSONAR
|
||||
expect(toARPA('::ffff:192.0.2.47')).to.eql('f.2.2.0.0.0.0.c.f.f.f.f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.'); // NOSONAR
|
||||
expect(toARPA('::1')).to.eql('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.'); // NOSONAR
|
||||
}); // NOSONAR
|
||||
}); // NOSONAR
|
||||
describe('toIPv4MappedAddress', // NOSONAR () => {
|
||||
it('returns IPv4MappedAddress', // NOSONAR () => {
|
||||
expect(toIPv4MappedAddress('1.1.1.1')).to.eql('::ffff:0101:0101'); // NOSONAR
|
||||
expect(toIPv4MappedAddress('10.10.1.1')).to.eql('::ffff:0a0a:0101'); // NOSONAR
|
||||
expect(toIPv4MappedAddress('172.18.10.9')).to.eql('::ffff:ac12:0a09'); // NOSONAR
|
||||
expect(toIPv4MappedAddress('192.168.1.1')).to.eql('::ffff:c0a8:0101'); // NOSONAR
|
||||
expect(toIPv4MappedAddress('255.255.255.0')).to.eql('::ffff:ffff:ff00'); // NOSONAR
|
||||
}); // NOSONAR
|
||||
}); // NOSONAR
|
||||
describe('toIPv4MappedAddressDecimal', // NOSONAR () => {
|
||||
it('returns networks count', // NOSONAR () => {
|
||||
expect(toIPv4MappedAddressDecimal('1.1.1.1')).to.eql('::ffff:1.1.1.1'); // NOSONAR
|
||||
expect(toIPv4MappedAddressDecimal('10.10.1.1')).to.eql('::ffff:10.10.1.1'); // NOSONAR
|
||||
expect(toIPv4MappedAddressDecimal('192.168.1.1')).to.eql('::ffff:192.168.1.1'); // NOSONAR
|
||||
expect(toIPv4MappedAddressDecimal('172.18.10.9')).to.eql('::ffff:172.18.10.9'); // NOSONAR
|
||||
expect(toIPv4MappedAddressDecimal('255.255.255.0')).to.eql('::ffff:255.255.255.0'); // NOSONAR
|
||||
expect(toIPv4MappedAddressDecimal('2001:db8:0:85a3::ac1f:8001')).to.eql(''); // NOSONAR
|
||||
}); // NOSONAR
|
||||
}); // NOSONAR
|
||||
describe('to6to4Prefix', // NOSONAR () => {
|
||||
it('returns networks count', // NOSONAR () => {
|
||||
expect(to6to4Prefix('1.1.1.1')).to.eql('2002:01:0:1:01:01::/48'); // NOSONAR
|
||||
expect(to6to4Prefix('10.10.1.1')).to.eql('2002:0a:0:a:01:01::/48'); // NOSONAR
|
||||
expect(to6to4Prefix('172.18.10.9')).to.eql('2002:ac:1:2:0a:09::/48'); // NOSONAR
|
||||
expect(to6to4Prefix('192.168.1.1')).to.eql('2002:c0:a:8:01:01::/48'); // NOSONAR
|
||||
expect(to6to4Prefix('255.255.255.0')).to.eql('2002:ff:f:f:ff:00::/48'); // NOSONAR
|
||||
expect(to6to4Prefix('2001:db8:0:85a3::ac1f:8001')).to.eql(''); // NOSONAR
|
||||
}); // NOSONAR
|
||||
}); // NOSONAR
|
||||
}); // NOSONAR
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue