Skip to content

Commit

Permalink
Working tests using manual seed node
Browse files Browse the repository at this point in the history
  • Loading branch information
emmacasolin committed Apr 11, 2022
1 parent fecff75 commit bb1d042
Show file tree
Hide file tree
Showing 3 changed files with 634 additions and 222 deletions.
149 changes: 135 additions & 14 deletions tests/nat/endpointDependentNAT.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,21 @@ describe('endpoint dependent NAT traversal', () => {
dataDir,
agent1NodePath,
agent2NodeId,
agent2Host,
agent2ProxyPort,
tearDownNAT,
} = await testNatUtils.setupNAT('edm', 'dmz', logger);
// Since node2 is not behind a NAT can directly add its details
await testNatUtils.pkExecNs(
userPid,
agent1Pid,
['nodes', 'add', agent2NodeId, agent2Host, agent2ProxyPort],
{
PK_NODE_PATH: agent1NodePath,
PK_PASSWORD: password,
},
dataDir,
);
const { exitCode, stdout } = await testNatUtils.pkExecNs(
userPid,
agent1Pid,
Expand All @@ -57,22 +70,83 @@ describe('endpoint dependent NAT traversal', () => {
const {
userPid,
agent1Pid,
agent2Pid,
password,
dataDir,
agent1NodePath,
agent2NodePath,
agent1NodeId,
agent1Host,
agent1ProxyPort,
agent2NodeId,
agent2Host,
agent2ProxyPort,
tearDownNAT,
} = await testNatUtils.setupNAT('dmz', 'edm', logger);
const { exitCode, stdout } = await testNatUtils.pkExecNs(
} = await testNatUtils.setupNAT('dmz', 'edmSimple', logger);
await testNatUtils.pkExecNs(
userPid,
agent2Pid,
['nodes', 'add', agent1NodeId, agent1Host, agent1ProxyPort],
{
PK_NODE_PATH: agent2NodePath,
PK_PASSWORD: password,
},
dataDir,
);
await testNatUtils.pkExecNs(
userPid,
agent1Pid,
['nodes', 'ping', agent2NodeId, '--format', 'json'],
['nodes', 'add', agent2NodeId, agent2Host, agent2ProxyPort],
{
PK_NODE_PATH: agent1NodePath,
PK_PASSWORD: password,
},
dataDir,
);
// If we try to ping Agent 2 it will fail
let exitCode, stdout;
({ exitCode, stdout } = await testNatUtils.pkExecNs(
userPid,
agent1Pid,
['nodes', 'ping', agent2NodeId, '--format', 'json'],
{
PK_NODE_PATH: agent1NodePath,
PK_PASSWORD: password,
},
dataDir,
));
expect(exitCode).toBe(1);
expect(JSON.parse(stdout)).toEqual({
success: false,
message: 'No response received',
});
// But Agent 2 can ping Agent 1 because Agent 1 is not behind a NAT
({ exitCode, stdout } = await testNatUtils.pkExecNs(
userPid,
agent2Pid,
['nodes', 'ping', agent1NodeId, '--format', 'json'],
{
PK_NODE_PATH: agent2NodePath,
PK_PASSWORD: password,
},
dataDir,
));
expect(exitCode).toBe(0);
expect(JSON.parse(stdout)).toEqual({
success: true,
message: 'Node is Active.',
});
// Can now ping Agent 2 (it will be expecting a response)
({ 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,
Expand All @@ -88,13 +162,40 @@ describe('endpoint dependent NAT traversal', () => {
const {
userPid,
agent1Pid,
agent2Pid,
password,
dataDir,
agent1NodePath,
agent2NodePath,
agent1NodeId,
agent2NodeId,
tearDownNAT,
} = await testNatUtils.setupNAT('edm', 'edm', logger);
const { exitCode, stdout } = await testNatUtils.pkExecNs(
} = await testNatUtils.setupNATWithSeedNode(
'edmSimple',
'edmSimple',
logger,
);
// Contact details are retrieved from the seed node, but cannot be used
// since port mapping changes between targets in EDM mapping
// Node 2 -> Node 1 ping should fail (Node 1 behind NAT)
let exitCode, stdout;
({ exitCode, stdout } = await testNatUtils.pkExecNs(
userPid,
agent2Pid,
['nodes', 'ping', agent1NodeId, '--format', 'json'],
{
PK_NODE_PATH: agent2NodePath,
PK_PASSWORD: password,
},
dataDir,
));
expect(exitCode).toBe(1);
expect(JSON.parse(stdout)).toEqual({
success: false,
message: 'No response received',
});
// Node 1 -> Node 2 ping should also fail
({ exitCode, stdout } = await testNatUtils.pkExecNs(
userPid,
agent1Pid,
['nodes', 'ping', agent2NodeId, '--format', 'json'],
Expand All @@ -103,11 +204,11 @@ describe('endpoint dependent NAT traversal', () => {
PK_PASSWORD: password,
},
dataDir,
);
expect(exitCode).not.toBe(0);
));
expect(exitCode).toBe(1);
expect(JSON.parse(stdout)).toEqual({
success: false,
message: `No response received`,
message: 'No response received',
});
await tearDownNAT();
},
Expand All @@ -119,26 +220,46 @@ describe('endpoint dependent NAT traversal', () => {
const {
userPid,
agent1Pid,
agent2Pid,
password,
dataDir,
agent1NodePath,
agent2NodePath,
agent1NodeId,
agent2NodeId,
tearDownNAT,
} = await testNatUtils.setupNAT('edm', 'eim', logger);
const { exitCode, stdout } = await testNatUtils.pkExecNs(
} = await testNatUtils.setupNATWithSeedNode('edmSimple', 'eim', logger);
// Since one of the nodes uses EDM NAT we cannot punch through
let exitCode, stdout;
({ exitCode, stdout } = await testNatUtils.pkExecNs(
userPid,
agent2Pid,
['nodes', 'ping', agent1NodeId, '--format', 'json', '-vv'],
{
PK_NODE_PATH: agent2NodePath,
PK_PASSWORD: password,
},
dataDir,
));
expect(exitCode).toBe(1);
expect(JSON.parse(stdout)).toEqual({
success: false,
message: 'No response received',
});
({ exitCode, stdout } = await testNatUtils.pkExecNs(
userPid,
agent1Pid,
['nodes', 'ping', agent2NodeId, '--format', 'json'],
['nodes', 'ping', agent2NodeId, '--format', 'json', '-vv'],
{
PK_NODE_PATH: agent1NodePath,
PK_PASSWORD: password,
},
dataDir,
);
expect(exitCode).not.toBe(0);
));
expect(exitCode).toBe(1);
expect(JSON.parse(stdout)).toEqual({
success: false,
message: `No response received`,
message: 'No response received',
});
await tearDownNAT();
},
Expand Down
Loading

0 comments on commit bb1d042

Please sign in to comment.