Skip to content

Commit

Permalink
Working DMZ and EIM NAT tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emmacasolin committed Apr 8, 2022
1 parent 237d097 commit 6b59acd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 227 deletions.
142 changes: 4 additions & 138 deletions tests/nat/endpointIndependentNAT.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import os from 'os';
import path from 'path';
import fs from 'fs';
import readline from 'readline';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import * as testNatUtils from './utils';
import { generateRandomNodeId } from '../utils';
import { encodeNodeId } from '@/nodes/utils';

describe('endpoint independent NAT traversal', () => {
const logger = new Logger('EIM NAT test', LogLevel.DEBUG, [
const logger = new Logger('EIM NAT test', LogLevel.WARN, [
new StreamHandler(),
]);
let dataDir: string;
Expand Down Expand Up @@ -139,7 +136,7 @@ describe('endpoint independent NAT traversal', () => {
},
global.defaultTimeout * 2,
);
test.only(
test(
'Node1 behind EIM NAT connects to Node2 behind EIM NAT',
async () => {
const {
Expand All @@ -151,109 +148,13 @@ describe('endpoint independent NAT traversal', () => {
agent1NodePath,
agent2NodePath,
agent1NodeId,
agent1Host,
agent1ProxyPort,
agent2NodeId,
agent2Host,
agent2ProxyPort,
tearDownNAT,
} = await testNatUtils.setupNATWithSeedNode('eim', 'eim', logger);
// Add information of other node to both nodes
const out1 = await testNatUtils.pkExecNs(
userPid,
agent2Pid,
['nodes', 'add', agent1NodeId, agent1Host, agent1ProxyPort],
{
PK_NODE_PATH: agent2NodePath,
PK_PASSWORD: password,
},
dataDir,
);
console.log(out1);
const out2 = await testNatUtils.pkExecNs(
userPid,
agent1Pid,
['nodes', 'add', agent2NodeId, agent2Host, agent2ProxyPort],
{
PK_NODE_PATH: agent1NodePath,
PK_PASSWORD: password,
},
dataDir,
);
console.log(out2);
const randomNode = encodeNodeId(generateRandomNodeId());
await testNatUtils.pkExecNs(
userPid,
agent1Pid,
['nodes', 'add', randomNode, '198.168.0.3', '55555'],
{
PK_NODE_PATH: agent1NodePath,
PK_PASSWORD: password,
},
dataDir,
);
// Since node2 is behind a NAT we need it to attempt to contact us first
// This won't be successfull, but will allow to get past its router with
// our own ping
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const pauser = () => {
return new Promise((resolve: (value: void) => void) => {
rl.question('Ready to continue? ', () => {
console.log('Continuing');
resolve();
});
});
}
await pauser();
rl.close();
// const test = await testNatUtils.pkExecNs(
// userPid,
// agent1Pid,
// ['nodes', 'ping', agent2NodeId, '--format', 'json', '-vv'],
// {
// PK_NODE_PATH: agent1NodePath,
// PK_PASSWORD: password,
// },
// dataDir,
// );
// console.log(test);
const out3 = await testNatUtils.pkExecNs(
userPid,
agent2Pid,
['nodes', 'ping', agent1NodeId, '--format', 'json', '-vv'],
{
PK_NODE_PATH: agent2NodePath,
PK_PASSWORD: password,
},
dataDir,
);
console.log(out3);
const { exitCode, stdout, stderr } = await testNatUtils.pkExecNs(
userPid,
agent1Pid,
['nodes', 'ping', agent2NodeId, '--format', 'json', '-vv'],
{
PK_NODE_PATH: agent1NodePath,
PK_PASSWORD: password,
},
dataDir,
);
console.log(stderr);
const out4 = await testNatUtils.pkExecNs(
userPid,
agent1Pid,
['nodes', 'ping', agent2NodeId, '--format', 'json', '-vv'],
{
PK_NODE_PATH: agent1NodePath,
PK_PASSWORD: password,
},
dataDir,
);
console.log(out4);
const out5 = await testNatUtils.pkExecNs(
await testNatUtils.pkExecNs(
userPid,
agent2Pid,
['nodes', 'ping', agent1NodeId, '--format', 'json', '-vv'],
Expand All @@ -263,8 +164,7 @@ describe('endpoint independent NAT traversal', () => {
},
dataDir,
);
console.log(out5);
const out6 = await testNatUtils.pkExecNs(
const { exitCode, stdout } = await testNatUtils.pkExecNs(
userPid,
agent1Pid,
['nodes', 'ping', agent2NodeId, '--format', 'json', '-vv'],
Expand All @@ -274,7 +174,6 @@ describe('endpoint independent NAT traversal', () => {
},
dataDir,
);
console.log(out6);
expect(exitCode).toBe(0);
expect(JSON.parse(stdout)).toEqual({
success: true,
Expand All @@ -284,39 +183,6 @@ describe('endpoint independent NAT traversal', () => {
},
global.defaultTimeout * 20,
);
test.skip(
'Node1 behind EIM NAT connects to Node2 behind EIM NAT via seed node',
async () => {
const {
userPid,
agent1Pid,
password,
dataDir,
agent1NodePath,
agent2NodeId,
tearDownNAT,
} = await testNatUtils.setupNATWithSeedNode('eim', 'eim', logger);
// Since we have a seed node we should be able to ping the other node
// straight away
const { exitCode, stdout } = await testNatUtils.pkExecNs(
userPid,
agent1Pid,
['nodes', 'ping', agent2NodeId, '--format', 'json'],
{
PK_NODE_PATH: agent1NodePath,
PK_PASSWORD: password,
},
dataDir,
);
expect(exitCode).toBe(0);
expect(JSON.parse(stdout)).toEqual({
success: true,
message: 'Node is Active.',
});
await tearDownNAT();
},
global.defaultTimeout * 4,
);
test.skip(
'Node1 behind EIM NAT cannot connect to Node2 behind EDM NAT',
async () => {
Expand Down
11 changes: 5 additions & 6 deletions tests/nat/noNAT.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as testNatUtils from './utils';
import * as testBinUtils from '../bin/utils';

describe('no NAT', () => {
const logger = new Logger('no NAT test', LogLevel.DEBUG, [
const logger = new Logger('no NAT test', LogLevel.WARN, [
new StreamHandler(),
]);
let dataDir: string;
Expand Down Expand Up @@ -184,7 +184,7 @@ describe('no NAT', () => {
},
global.defaultTimeout * 2,
);
test.only(
test(
'agents in different namespaces can ping each other via seed node',
async () => {
const {
Expand All @@ -201,8 +201,8 @@ describe('no NAT', () => {
} = await testNatUtils.setupNATWithSeedNode('dmz', 'dmz', logger);
// Should be able to ping straight away using the details from the
// seed node
let exitCode, stdout, stderr;
({ exitCode, stdout, stderr } = await testNatUtils.pkExecNs(
let exitCode, stdout;
({ exitCode, stdout } = await testNatUtils.pkExecNs(
userPid,
agent1Pid,
['nodes', 'ping', agent2NodeId, '--format', 'json', '--verbose'],
Expand All @@ -212,7 +212,6 @@ describe('no NAT', () => {
},
dataDir,
));
console.log(stderr);
expect(exitCode).toBe(0);
expect(JSON.parse(stdout)).toEqual({
success: true,
Expand All @@ -235,6 +234,6 @@ describe('no NAT', () => {
});
await tearDownNAT();
},
global.defaultTimeout * 20,
global.defaultTimeout * 2,
);
});
Loading

0 comments on commit 6b59acd

Please sign in to comment.