2019-09-12 15:26:21 +00:00
|
|
|
import * as os from 'os';
|
2024-02-29 22:00:39 +00:00
|
|
|
import type { SinonStub } from 'sinon';
|
2022-10-18 19:44:19 +00:00
|
|
|
import { stub } from 'sinon';
|
2017-11-01 06:47:48 +00:00
|
|
|
|
2021-04-26 19:54:04 +00:00
|
|
|
import { expect } from 'chai';
|
2022-08-17 23:35:08 +00:00
|
|
|
import * as network from '~/src/network';
|
2019-09-12 15:26:21 +00:00
|
|
|
|
|
|
|
describe('network', () => {
|
|
|
|
describe('getIPAddresses', () => {
|
|
|
|
before(() =>
|
2017-11-01 06:47:48 +00:00
|
|
|
stub(os, 'networkInterfaces').returns({
|
2019-09-12 15:26:21 +00:00
|
|
|
lo: [
|
|
|
|
{
|
2017-11-01 06:47:48 +00:00
|
|
|
address: '127.0.0.1',
|
|
|
|
netmask: '255.0.0.0',
|
|
|
|
family: 'IPv4',
|
|
|
|
mac: '00:00:00:00:00:00',
|
2019-09-12 15:26:21 +00:00
|
|
|
internal: true,
|
2017-11-01 06:47:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
address: '::1',
|
|
|
|
netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
|
|
|
|
family: 'IPv6',
|
|
|
|
mac: '00:00:00:00:00:00',
|
|
|
|
scopeid: 0,
|
2019-09-12 15:26:21 +00:00
|
|
|
internal: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
docker0: [
|
|
|
|
{
|
2017-11-01 06:47:48 +00:00
|
|
|
address: '172.17.0.1',
|
|
|
|
netmask: '255.255.0.0',
|
|
|
|
family: 'IPv4',
|
|
|
|
mac: '02:42:0f:33:06:ad',
|
2019-09-12 15:26:21 +00:00
|
|
|
internal: false,
|
2017-11-01 06:47:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
address: 'fe80::42:fff:fe33:6ad',
|
|
|
|
netmask: 'ffff:ffff:ffff:ffff::',
|
|
|
|
family: 'IPv6',
|
|
|
|
mac: '02:42:0f:33:06:ad',
|
|
|
|
scopeid: 3,
|
2019-09-12 15:26:21 +00:00
|
|
|
internal: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
wlan0: [
|
|
|
|
{
|
2017-11-01 06:47:48 +00:00
|
|
|
address: '192.168.1.137',
|
|
|
|
netmask: '255.255.255.0',
|
|
|
|
family: 'IPv4',
|
|
|
|
mac: '60:6d:c7:c6:44:3d',
|
2019-09-12 15:26:21 +00:00
|
|
|
internal: false,
|
2017-11-01 06:47:48 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
address: '2605:9080:1103:3011:2dbe:35e3:1b5a:b99',
|
|
|
|
netmask: 'ffff:ffff:ffff:ffff::',
|
|
|
|
family: 'IPv6',
|
|
|
|
mac: '60:6d:c7:c6:44:3d',
|
|
|
|
scopeid: 0,
|
2019-09-12 15:26:21 +00:00
|
|
|
internal: false,
|
|
|
|
},
|
|
|
|
],
|
2022-02-08 21:36:29 +00:00
|
|
|
eth0: [
|
|
|
|
{
|
|
|
|
address: 'fe80::9992:76e3:c2e1:8a02',
|
|
|
|
netmask: 'ffff:ffff:ffff:ffff::',
|
|
|
|
family: 'IPv6',
|
|
|
|
mac: '58:6d:c7:c6:44:3d',
|
|
|
|
scopeid: 9,
|
|
|
|
internal: false,
|
|
|
|
},
|
|
|
|
],
|
2019-09-12 15:26:21 +00:00
|
|
|
'resin-vpn': [
|
|
|
|
{
|
2017-11-01 06:47:48 +00:00
|
|
|
address: '10.10.2.14',
|
|
|
|
netmask: '255.255.0.0',
|
|
|
|
family: 'IPv4',
|
|
|
|
mac: '01:43:1f:32:05:bd',
|
2019-09-12 15:26:21 +00:00
|
|
|
internal: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
} as any),
|
|
|
|
);
|
|
|
|
|
2024-02-29 22:00:39 +00:00
|
|
|
after(() => (os.networkInterfaces as SinonStub).restore());
|
2019-09-12 15:26:21 +00:00
|
|
|
|
|
|
|
it('returns only the relevant IP addresses', () =>
|
2022-02-08 21:36:29 +00:00
|
|
|
expect(network.getIPAddresses()).to.deep.equal([
|
|
|
|
'192.168.1.137',
|
|
|
|
'2605:9080:1103:3011:2dbe:35e3:1b5a:b99',
|
|
|
|
]));
|
2019-09-12 15:26:21 +00:00
|
|
|
});
|
|
|
|
});
|