Skip to content

Commit 6b59acd

Browse files
committed
Working DMZ and EIM NAT tests
1 parent 237d097 commit 6b59acd

File tree

3 files changed

+44
-227
lines changed

3 files changed

+44
-227
lines changed

tests/nat/endpointIndependentNAT.test.ts

Lines changed: 4 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import os from 'os';
22
import path from 'path';
33
import fs from 'fs';
4-
import readline from 'readline';
54
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
65
import * as testNatUtils from './utils';
7-
import { generateRandomNodeId } from '../utils';
8-
import { encodeNodeId } from '@/nodes/utils';
96

107
describe('endpoint independent NAT traversal', () => {
11-
const logger = new Logger('EIM NAT test', LogLevel.DEBUG, [
8+
const logger = new Logger('EIM NAT test', LogLevel.WARN, [
129
new StreamHandler(),
1310
]);
1411
let dataDir: string;
@@ -139,7 +136,7 @@ describe('endpoint independent NAT traversal', () => {
139136
},
140137
global.defaultTimeout * 2,
141138
);
142-
test.only(
139+
test(
143140
'Node1 behind EIM NAT connects to Node2 behind EIM NAT',
144141
async () => {
145142
const {
@@ -151,109 +148,13 @@ describe('endpoint independent NAT traversal', () => {
151148
agent1NodePath,
152149
agent2NodePath,
153150
agent1NodeId,
154-
agent1Host,
155-
agent1ProxyPort,
156151
agent2NodeId,
157-
agent2Host,
158-
agent2ProxyPort,
159152
tearDownNAT,
160153
} = await testNatUtils.setupNATWithSeedNode('eim', 'eim', logger);
161-
// Add information of other node to both nodes
162-
const out1 = await testNatUtils.pkExecNs(
163-
userPid,
164-
agent2Pid,
165-
['nodes', 'add', agent1NodeId, agent1Host, agent1ProxyPort],
166-
{
167-
PK_NODE_PATH: agent2NodePath,
168-
PK_PASSWORD: password,
169-
},
170-
dataDir,
171-
);
172-
console.log(out1);
173-
const out2 = await testNatUtils.pkExecNs(
174-
userPid,
175-
agent1Pid,
176-
['nodes', 'add', agent2NodeId, agent2Host, agent2ProxyPort],
177-
{
178-
PK_NODE_PATH: agent1NodePath,
179-
PK_PASSWORD: password,
180-
},
181-
dataDir,
182-
);
183-
console.log(out2);
184-
const randomNode = encodeNodeId(generateRandomNodeId());
185-
await testNatUtils.pkExecNs(
186-
userPid,
187-
agent1Pid,
188-
['nodes', 'add', randomNode, '198.168.0.3', '55555'],
189-
{
190-
PK_NODE_PATH: agent1NodePath,
191-
PK_PASSWORD: password,
192-
},
193-
dataDir,
194-
);
195154
// Since node2 is behind a NAT we need it to attempt to contact us first
196155
// This won't be successfull, but will allow to get past its router with
197156
// our own ping
198-
const rl = readline.createInterface({
199-
input: process.stdin,
200-
output: process.stdout
201-
});
202-
const pauser = () => {
203-
return new Promise((resolve: (value: void) => void) => {
204-
rl.question('Ready to continue? ', () => {
205-
console.log('Continuing');
206-
resolve();
207-
});
208-
});
209-
}
210-
await pauser();
211-
rl.close();
212-
// const test = await testNatUtils.pkExecNs(
213-
// userPid,
214-
// agent1Pid,
215-
// ['nodes', 'ping', agent2NodeId, '--format', 'json', '-vv'],
216-
// {
217-
// PK_NODE_PATH: agent1NodePath,
218-
// PK_PASSWORD: password,
219-
// },
220-
// dataDir,
221-
// );
222-
// console.log(test);
223-
const out3 = await testNatUtils.pkExecNs(
224-
userPid,
225-
agent2Pid,
226-
['nodes', 'ping', agent1NodeId, '--format', 'json', '-vv'],
227-
{
228-
PK_NODE_PATH: agent2NodePath,
229-
PK_PASSWORD: password,
230-
},
231-
dataDir,
232-
);
233-
console.log(out3);
234-
const { exitCode, stdout, stderr } = await testNatUtils.pkExecNs(
235-
userPid,
236-
agent1Pid,
237-
['nodes', 'ping', agent2NodeId, '--format', 'json', '-vv'],
238-
{
239-
PK_NODE_PATH: agent1NodePath,
240-
PK_PASSWORD: password,
241-
},
242-
dataDir,
243-
);
244-
console.log(stderr);
245-
const out4 = await testNatUtils.pkExecNs(
246-
userPid,
247-
agent1Pid,
248-
['nodes', 'ping', agent2NodeId, '--format', 'json', '-vv'],
249-
{
250-
PK_NODE_PATH: agent1NodePath,
251-
PK_PASSWORD: password,
252-
},
253-
dataDir,
254-
);
255-
console.log(out4);
256-
const out5 = await testNatUtils.pkExecNs(
157+
await testNatUtils.pkExecNs(
257158
userPid,
258159
agent2Pid,
259160
['nodes', 'ping', agent1NodeId, '--format', 'json', '-vv'],
@@ -263,8 +164,7 @@ describe('endpoint independent NAT traversal', () => {
263164
},
264165
dataDir,
265166
);
266-
console.log(out5);
267-
const out6 = await testNatUtils.pkExecNs(
167+
const { exitCode, stdout } = await testNatUtils.pkExecNs(
268168
userPid,
269169
agent1Pid,
270170
['nodes', 'ping', agent2NodeId, '--format', 'json', '-vv'],
@@ -274,7 +174,6 @@ describe('endpoint independent NAT traversal', () => {
274174
},
275175
dataDir,
276176
);
277-
console.log(out6);
278177
expect(exitCode).toBe(0);
279178
expect(JSON.parse(stdout)).toEqual({
280179
success: true,
@@ -284,39 +183,6 @@ describe('endpoint independent NAT traversal', () => {
284183
},
285184
global.defaultTimeout * 20,
286185
);
287-
test.skip(
288-
'Node1 behind EIM NAT connects to Node2 behind EIM NAT via seed node',
289-
async () => {
290-
const {
291-
userPid,
292-
agent1Pid,
293-
password,
294-
dataDir,
295-
agent1NodePath,
296-
agent2NodeId,
297-
tearDownNAT,
298-
} = await testNatUtils.setupNATWithSeedNode('eim', 'eim', logger);
299-
// Since we have a seed node we should be able to ping the other node
300-
// straight away
301-
const { exitCode, stdout } = await testNatUtils.pkExecNs(
302-
userPid,
303-
agent1Pid,
304-
['nodes', 'ping', agent2NodeId, '--format', 'json'],
305-
{
306-
PK_NODE_PATH: agent1NodePath,
307-
PK_PASSWORD: password,
308-
},
309-
dataDir,
310-
);
311-
expect(exitCode).toBe(0);
312-
expect(JSON.parse(stdout)).toEqual({
313-
success: true,
314-
message: 'Node is Active.',
315-
});
316-
await tearDownNAT();
317-
},
318-
global.defaultTimeout * 4,
319-
);
320186
test.skip(
321187
'Node1 behind EIM NAT cannot connect to Node2 behind EDM NAT',
322188
async () => {

tests/nat/noNAT.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as testNatUtils from './utils';
99
import * as testBinUtils from '../bin/utils';
1010

1111
describe('no NAT', () => {
12-
const logger = new Logger('no NAT test', LogLevel.DEBUG, [
12+
const logger = new Logger('no NAT test', LogLevel.WARN, [
1313
new StreamHandler(),
1414
]);
1515
let dataDir: string;
@@ -184,7 +184,7 @@ describe('no NAT', () => {
184184
},
185185
global.defaultTimeout * 2,
186186
);
187-
test.only(
187+
test(
188188
'agents in different namespaces can ping each other via seed node',
189189
async () => {
190190
const {
@@ -201,8 +201,8 @@ describe('no NAT', () => {
201201
} = await testNatUtils.setupNATWithSeedNode('dmz', 'dmz', logger);
202202
// Should be able to ping straight away using the details from the
203203
// seed node
204-
let exitCode, stdout, stderr;
205-
({ exitCode, stdout, stderr } = await testNatUtils.pkExecNs(
204+
let exitCode, stdout;
205+
({ exitCode, stdout } = await testNatUtils.pkExecNs(
206206
userPid,
207207
agent1Pid,
208208
['nodes', 'ping', agent2NodeId, '--format', 'json', '--verbose'],
@@ -212,7 +212,6 @@ describe('no NAT', () => {
212212
},
213213
dataDir,
214214
));
215-
console.log(stderr);
216215
expect(exitCode).toBe(0);
217216
expect(JSON.parse(stdout)).toEqual({
218217
success: true,
@@ -235,6 +234,6 @@ describe('no NAT', () => {
235234
});
236235
await tearDownNAT();
237236
},
238-
global.defaultTimeout * 20,
237+
global.defaultTimeout * 2,
239238
);
240239
});

0 commit comments

Comments
 (0)