@@ -30,8 +30,21 @@ describe('endpoint dependent NAT traversal', () => {
3030 dataDir,
3131 agent1NodePath,
3232 agent2NodeId,
33+ agent2Host,
34+ agent2ProxyPort,
3335 tearDownNAT,
3436 } = await testNatUtils . setupNAT ( 'edm' , 'dmz' , logger ) ;
37+ // Since node2 is not behind a NAT can directly add its details
38+ await testNatUtils . pkExecNs (
39+ userPid ,
40+ agent1Pid ,
41+ [ 'nodes' , 'add' , agent2NodeId , agent2Host , agent2ProxyPort ] ,
42+ {
43+ PK_NODE_PATH : agent1NodePath ,
44+ PK_PASSWORD : password ,
45+ } ,
46+ dataDir ,
47+ ) ;
3548 const { exitCode, stdout } = await testNatUtils . pkExecNs (
3649 userPid ,
3750 agent1Pid ,
@@ -57,22 +70,83 @@ describe('endpoint dependent NAT traversal', () => {
5770 const {
5871 userPid,
5972 agent1Pid,
73+ agent2Pid,
6074 password,
6175 dataDir,
6276 agent1NodePath,
77+ agent2NodePath,
78+ agent1NodeId,
79+ agent1Host,
80+ agent1ProxyPort,
6381 agent2NodeId,
82+ agent2Host,
83+ agent2ProxyPort,
6484 tearDownNAT,
65- } = await testNatUtils . setupNAT ( 'dmz' , 'edm' , logger ) ;
66- const { exitCode, stdout } = await testNatUtils . pkExecNs (
85+ } = await testNatUtils . setupNAT ( 'dmz' , 'edmSimple' , logger ) ;
86+ await testNatUtils . pkExecNs (
87+ userPid ,
88+ agent2Pid ,
89+ [ 'nodes' , 'add' , agent1NodeId , agent1Host , agent1ProxyPort ] ,
90+ {
91+ PK_NODE_PATH : agent2NodePath ,
92+ PK_PASSWORD : password ,
93+ } ,
94+ dataDir ,
95+ ) ;
96+ await testNatUtils . pkExecNs (
6797 userPid ,
6898 agent1Pid ,
69- [ 'nodes' , 'ping ' , agent2NodeId , '--format' , 'json' ] ,
99+ [ 'nodes' , 'add ' , agent2NodeId , agent2Host , agent2ProxyPort ] ,
70100 {
71101 PK_NODE_PATH : agent1NodePath ,
72102 PK_PASSWORD : password ,
73103 } ,
74104 dataDir ,
75105 ) ;
106+ // If we try to ping Agent 2 it will fail
107+ let exitCode , stdout ;
108+ ( { exitCode, stdout } = await testNatUtils . pkExecNs (
109+ userPid ,
110+ agent1Pid ,
111+ [ 'nodes' , 'ping' , agent2NodeId , '--format' , 'json' ] ,
112+ {
113+ PK_NODE_PATH : agent1NodePath ,
114+ PK_PASSWORD : password ,
115+ } ,
116+ dataDir ,
117+ ) ) ;
118+ expect ( exitCode ) . toBe ( 1 ) ;
119+ expect ( JSON . parse ( stdout ) ) . toEqual ( {
120+ success : false ,
121+ message : 'No response received' ,
122+ } ) ;
123+ // But Agent 2 can ping Agent 1 because Agent 1 is not behind a NAT
124+ ( { exitCode, stdout } = await testNatUtils . pkExecNs (
125+ userPid ,
126+ agent2Pid ,
127+ [ 'nodes' , 'ping' , agent1NodeId , '--format' , 'json' ] ,
128+ {
129+ PK_NODE_PATH : agent2NodePath ,
130+ PK_PASSWORD : password ,
131+ } ,
132+ dataDir ,
133+ ) ) ;
134+ expect ( exitCode ) . toBe ( 0 ) ;
135+ expect ( JSON . parse ( stdout ) ) . toEqual ( {
136+ success : true ,
137+ message : 'Node is Active.' ,
138+ } ) ;
139+ // Can now ping Agent 2 (it will be expecting a response)
140+ ( { exitCode, stdout } = await testNatUtils . pkExecNs (
141+ userPid ,
142+ agent1Pid ,
143+ [ 'nodes' , 'ping' , agent2NodeId , '--format' , 'json' ] ,
144+ {
145+ PK_NODE_PATH : agent1NodePath ,
146+ PK_PASSWORD : password ,
147+ } ,
148+ dataDir ,
149+ ) ) ;
76150 expect ( exitCode ) . toBe ( 0 ) ;
77151 expect ( JSON . parse ( stdout ) ) . toEqual ( {
78152 success : true ,
@@ -88,13 +162,40 @@ describe('endpoint dependent NAT traversal', () => {
88162 const {
89163 userPid,
90164 agent1Pid,
165+ agent2Pid,
91166 password,
92167 dataDir,
93168 agent1NodePath,
169+ agent2NodePath,
170+ agent1NodeId,
94171 agent2NodeId,
95172 tearDownNAT,
96- } = await testNatUtils . setupNAT ( 'edm' , 'edm' , logger ) ;
97- const { exitCode, stdout } = await testNatUtils . pkExecNs (
173+ } = await testNatUtils . setupNATWithSeedNode (
174+ 'edmSimple' ,
175+ 'edmSimple' ,
176+ logger ,
177+ ) ;
178+ // Contact details are retrieved from the seed node, but cannot be used
179+ // since port mapping changes between targets in EDM mapping
180+ // Node 2 -> Node 1 ping should fail (Node 1 behind NAT)
181+ let exitCode , stdout ;
182+ ( { exitCode, stdout } = await testNatUtils . pkExecNs (
183+ userPid ,
184+ agent2Pid ,
185+ [ 'nodes' , 'ping' , agent1NodeId , '--format' , 'json' ] ,
186+ {
187+ PK_NODE_PATH : agent2NodePath ,
188+ PK_PASSWORD : password ,
189+ } ,
190+ dataDir ,
191+ ) ) ;
192+ expect ( exitCode ) . toBe ( 1 ) ;
193+ expect ( JSON . parse ( stdout ) ) . toEqual ( {
194+ success : false ,
195+ message : 'No response received' ,
196+ } ) ;
197+ // Node 1 -> Node 2 ping should also fail
198+ ( { exitCode, stdout } = await testNatUtils . pkExecNs (
98199 userPid ,
99200 agent1Pid ,
100201 [ 'nodes' , 'ping' , agent2NodeId , '--format' , 'json' ] ,
@@ -103,11 +204,11 @@ describe('endpoint dependent NAT traversal', () => {
103204 PK_PASSWORD : password ,
104205 } ,
105206 dataDir ,
106- ) ;
107- expect ( exitCode ) . not . toBe ( 0 ) ;
207+ ) ) ;
208+ expect ( exitCode ) . toBe ( 1 ) ;
108209 expect ( JSON . parse ( stdout ) ) . toEqual ( {
109210 success : false ,
110- message : ` No response received` ,
211+ message : ' No response received' ,
111212 } ) ;
112213 await tearDownNAT ( ) ;
113214 } ,
@@ -119,26 +220,46 @@ describe('endpoint dependent NAT traversal', () => {
119220 const {
120221 userPid,
121222 agent1Pid,
223+ agent2Pid,
122224 password,
123225 dataDir,
124226 agent1NodePath,
227+ agent2NodePath,
228+ agent1NodeId,
125229 agent2NodeId,
126230 tearDownNAT,
127- } = await testNatUtils . setupNAT ( 'edm' , 'eim' , logger ) ;
128- const { exitCode, stdout } = await testNatUtils . pkExecNs (
231+ } = await testNatUtils . setupNATWithSeedNode ( 'edmSimple' , 'eim' , logger ) ;
232+ // Since one of the nodes uses EDM NAT we cannot punch through
233+ let exitCode , stdout ;
234+ ( { exitCode, stdout } = await testNatUtils . pkExecNs (
235+ userPid ,
236+ agent2Pid ,
237+ [ 'nodes' , 'ping' , agent1NodeId , '--format' , 'json' , '-vv' ] ,
238+ {
239+ PK_NODE_PATH : agent2NodePath ,
240+ PK_PASSWORD : password ,
241+ } ,
242+ dataDir ,
243+ ) ) ;
244+ expect ( exitCode ) . toBe ( 1 ) ;
245+ expect ( JSON . parse ( stdout ) ) . toEqual ( {
246+ success : false ,
247+ message : 'No response received' ,
248+ } ) ;
249+ ( { exitCode, stdout } = await testNatUtils . pkExecNs (
129250 userPid ,
130251 agent1Pid ,
131- [ 'nodes' , 'ping' , agent2NodeId , '--format' , 'json' ] ,
252+ [ 'nodes' , 'ping' , agent2NodeId , '--format' , 'json' , '-vv' ] ,
132253 {
133254 PK_NODE_PATH : agent1NodePath ,
134255 PK_PASSWORD : password ,
135256 } ,
136257 dataDir ,
137- ) ;
138- expect ( exitCode ) . not . toBe ( 0 ) ;
258+ ) ) ;
259+ expect ( exitCode ) . toBe ( 1 ) ;
139260 expect ( JSON . parse ( stdout ) ) . toEqual ( {
140261 success : false ,
141- message : ` No response received` ,
262+ message : ' No response received' ,
142263 } ) ;
143264 await tearDownNAT ( ) ;
144265 } ,
0 commit comments