Skip to content

Commit fecff75

Browse files
joshuakarpemmacasolin
authored andcommitted
NAT Traversal testing utils and test WIPs
1 parent 3fe4b39 commit fecff75

6 files changed

Lines changed: 1634 additions & 2 deletions

File tree

scripts/test-pipelines.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ test $test_dir:
5959
interruptible: true
6060
script:
6161
- >
62-
nix-shell -I nixpkgs=./pkgs.nix --packages nodejs --run '
62+
nix-shell -I nixpkgs=./pkgs.nix --packages nodejs iproute2 utillinux nftables iptables --run '
6363
npm ci;
6464
npm test -- ${test_files[@]};
6565
'
@@ -76,7 +76,7 @@ test index:
7676
interruptible: true
7777
script:
7878
- >
79-
nix-shell -I nixpkgs=./pkgs.nix --packages nodejs --run '
79+
nix-shell -I nixpkgs=./pkgs.nix --packages nodejs iptables-legacy --run '
8080
npm ci;
8181
npm test -- ${test_files[@]};
8282
'

shell.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ in
1111
grpc-tools
1212
grpcurl
1313
utils.pkg
14+
utillinux
1415
];
1516
PKG_CACHE_PATH = utils.pkgCachePath;
1617
PKG_IGNORE_TAG = 1;
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import os from 'os';
2+
import path from 'path';
3+
import fs from 'fs';
4+
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
5+
import * as testNatUtils from './utils';
6+
7+
describe('endpoint dependent NAT traversal', () => {
8+
const logger = new Logger('EDM NAT test', LogLevel.WARN, [
9+
new StreamHandler(),
10+
]);
11+
let dataDir: string;
12+
beforeEach(async () => {
13+
dataDir = await fs.promises.mkdtemp(
14+
path.join(os.tmpdir(), 'polykey-test-'),
15+
);
16+
});
17+
afterEach(async () => {
18+
await fs.promises.rm(dataDir, {
19+
force: true,
20+
recursive: true,
21+
});
22+
});
23+
test(
24+
'Node1 behind EDM NAT connects to Node2',
25+
async () => {
26+
const {
27+
userPid,
28+
agent1Pid,
29+
password,
30+
dataDir,
31+
agent1NodePath,
32+
agent2NodeId,
33+
tearDownNAT,
34+
} = await testNatUtils.setupNAT('edm', 'dmz', logger);
35+
const { exitCode, stdout } = await testNatUtils.pkExecNs(
36+
userPid,
37+
agent1Pid,
38+
['nodes', 'ping', agent2NodeId, '--format', 'json'],
39+
{
40+
PK_NODE_PATH: agent1NodePath,
41+
PK_PASSWORD: password,
42+
},
43+
dataDir,
44+
);
45+
expect(exitCode).toBe(0);
46+
expect(JSON.parse(stdout)).toEqual({
47+
success: true,
48+
message: 'Node is Active.',
49+
});
50+
await tearDownNAT();
51+
},
52+
global.defaultTimeout * 2,
53+
);
54+
test(
55+
'Node1 connects to Node2 behind EDM NAT',
56+
async () => {
57+
const {
58+
userPid,
59+
agent1Pid,
60+
password,
61+
dataDir,
62+
agent1NodePath,
63+
agent2NodeId,
64+
tearDownNAT,
65+
} = await testNatUtils.setupNAT('dmz', 'edm', logger);
66+
const { exitCode, stdout } = await testNatUtils.pkExecNs(
67+
userPid,
68+
agent1Pid,
69+
['nodes', 'ping', agent2NodeId, '--format', 'json'],
70+
{
71+
PK_NODE_PATH: agent1NodePath,
72+
PK_PASSWORD: password,
73+
},
74+
dataDir,
75+
);
76+
expect(exitCode).toBe(0);
77+
expect(JSON.parse(stdout)).toEqual({
78+
success: true,
79+
message: 'Node is Active.',
80+
});
81+
await tearDownNAT();
82+
},
83+
global.defaultTimeout * 2,
84+
);
85+
test(
86+
'Node1 behind EDM NAT cannot connect to Node2 behind EDM NAT',
87+
async () => {
88+
const {
89+
userPid,
90+
agent1Pid,
91+
password,
92+
dataDir,
93+
agent1NodePath,
94+
agent2NodeId,
95+
tearDownNAT,
96+
} = await testNatUtils.setupNAT('edm', 'edm', logger);
97+
const { exitCode, stdout } = await testNatUtils.pkExecNs(
98+
userPid,
99+
agent1Pid,
100+
['nodes', 'ping', agent2NodeId, '--format', 'json'],
101+
{
102+
PK_NODE_PATH: agent1NodePath,
103+
PK_PASSWORD: password,
104+
},
105+
dataDir,
106+
);
107+
expect(exitCode).not.toBe(0);
108+
expect(JSON.parse(stdout)).toEqual({
109+
success: false,
110+
message: `No response received`,
111+
});
112+
await tearDownNAT();
113+
},
114+
global.defaultTimeout * 2,
115+
);
116+
test(
117+
'Node1 behind EDM NAT cannot connect to Node2 behind EIM NAT',
118+
async () => {
119+
const {
120+
userPid,
121+
agent1Pid,
122+
password,
123+
dataDir,
124+
agent1NodePath,
125+
agent2NodeId,
126+
tearDownNAT,
127+
} = await testNatUtils.setupNAT('edm', 'eim', logger);
128+
const { exitCode, stdout } = await testNatUtils.pkExecNs(
129+
userPid,
130+
agent1Pid,
131+
['nodes', 'ping', agent2NodeId, '--format', 'json'],
132+
{
133+
PK_NODE_PATH: agent1NodePath,
134+
PK_PASSWORD: password,
135+
},
136+
dataDir,
137+
);
138+
expect(exitCode).not.toBe(0);
139+
expect(JSON.parse(stdout)).toEqual({
140+
success: false,
141+
message: `No response received`,
142+
});
143+
await tearDownNAT();
144+
},
145+
global.defaultTimeout * 2,
146+
);
147+
});

0 commit comments

Comments
 (0)