@andy.ian/dsh-homing 2.0.3 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/bin/restart-daemon.mjs +3 -0
  2. package/bin/restart.mjs +3 -0
  3. package/index.js +714 -21
  4. package/lib/devices.mjs +0 -1
  5. package/lib/files-page.mjs +0 -18
  6. package/lib/files.mjs +39 -27
  7. package/package.json +8 -9
  8. package/restart/client.mjs +184 -0
  9. package/restart/config.mjs +187 -0
  10. package/restart/engine.mjs +93 -0
  11. package/restart/face.mjs +62 -0
  12. package/restart/runner.mjs +184 -0
  13. package/restart/service.mjs +91 -0
  14. package/restart-daemon/README.md +66 -0
  15. package/restart-daemon/cli.mjs +321 -0
  16. package/restart-daemon/lib/detach.mjs +126 -0
  17. package/restart-daemon/lib/process-tree.mjs +69 -0
  18. package/restart-daemon/lib/restart-flow.mjs +111 -0
  19. package/restart-daemon/lib/update-state.mjs +72 -0
  20. package/restart-daemon/main.mjs +691 -0
  21. package/bin/supervisor.mjs +0 -488
  22. package/bin/watchdog.mjs +0 -144
  23. package/lib/vendor/node_modules/ssh2/examples/server-chat.js +0 -238
  24. package/lib/vendor/node_modules/ssh2/examples/sftp-server-download-only.js +0 -134
  25. package/lib/vendor/node_modules/ssh2/test/common.js +0 -316
  26. package/lib/vendor/node_modules/ssh2/test/fixtures/bad_rsa_private_key +0 -26
  27. package/lib/vendor/node_modules/ssh2/test/fixtures/https_cert.pem +0 -33
  28. package/lib/vendor/node_modules/ssh2/test/fixtures/https_key.pem +0 -52
  29. package/lib/vendor/node_modules/ssh2/test/fixtures/id_dsa +0 -12
  30. package/lib/vendor/node_modules/ssh2/test/fixtures/id_ecdsa +0 -5
  31. package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa +0 -15
  32. package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa.ppk +0 -26
  33. package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa_enc +0 -30
  34. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa +0 -21
  35. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub +0 -1
  36. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub.result +0 -7
  37. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.result +0 -7
  38. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc +0 -22
  39. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub +0 -1
  40. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub.result +0 -7
  41. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.result +0 -7
  42. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm +0 -23
  43. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub +0 -1
  44. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub.result +0 -7
  45. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.result +0 -7
  46. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa +0 -9
  47. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub +0 -1
  48. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub.result +0 -7
  49. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.result +0 -7
  50. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc +0 -10
  51. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub +0 -1
  52. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub.result +0 -8
  53. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.result +0 -7
  54. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm +0 -10
  55. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub +0 -1
  56. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub.result +0 -8
  57. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.result +0 -7
  58. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519 +0 -7
  59. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub +0 -1
  60. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub.result +0 -7
  61. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.result +0 -7
  62. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa +0 -27
  63. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub +0 -1
  64. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub.result +0 -7
  65. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.result +0 -7
  66. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc +0 -28
  67. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub +0 -1
  68. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub.result +0 -8
  69. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.result +0 -7
  70. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm +0 -29
  71. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub +0 -1
  72. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub.result +0 -8
  73. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.result +0 -7
  74. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa +0 -12
  75. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub +0 -1
  76. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub.result +0 -7
  77. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.result +0 -7
  78. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc +0 -15
  79. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub +0 -1
  80. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub.result +0 -8
  81. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.result +0 -7
  82. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa +0 -5
  83. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub +0 -1
  84. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub.result +0 -7
  85. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.result +0 -7
  86. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc +0 -8
  87. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub +0 -1
  88. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub.result +0 -8
  89. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.result +0 -7
  90. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa +0 -27
  91. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub +0 -1
  92. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub.result +0 -7
  93. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.result +0 -7
  94. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc +0 -30
  95. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub +0 -1
  96. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub.result +0 -8
  97. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.result +0 -7
  98. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256 +0 -54
  99. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub +0 -1
  100. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub.result +0 -6
  101. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.result +0 -6
  102. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc +0 -17
  103. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc.result +0 -7
  104. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa +0 -26
  105. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa.result +0 -7
  106. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc +0 -18
  107. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc.result +0 -7
  108. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub +0 -9
  109. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub.result +0 -7
  110. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub +0 -10
  111. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub.result +0 -7
  112. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub +0 -11
  113. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub.result +0 -7
  114. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub +0 -11
  115. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub.result +0 -7
  116. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub +0 -8
  117. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub.result +0 -7
  118. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub +0 -13
  119. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub.result +0 -7
  120. package/lib/vendor/node_modules/ssh2/test/fixtures/openssh_new_rsa +0 -27
  121. package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_dsa_key +0 -12
  122. package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_ecdsa_key +0 -5
  123. package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_rsa_key +0 -15
  124. package/lib/vendor/node_modules/ssh2/test/test-exec.js +0 -578
  125. package/lib/vendor/node_modules/ssh2/test/test-integration-openssh.js +0 -486
  126. package/lib/vendor/node_modules/ssh2/test/test-keygen.js +0 -60
  127. package/lib/vendor/node_modules/ssh2/test/test-misc-client-server.js +0 -1460
  128. package/lib/vendor/node_modules/ssh2/test/test-openssh.js +0 -261
  129. package/lib/vendor/node_modules/ssh2/test/test-protocol-crypto.js +0 -631
  130. package/lib/vendor/node_modules/ssh2/test/test-protocol-keyparser.js +0 -177
  131. package/lib/vendor/node_modules/ssh2/test/test-server-hostkeys.js +0 -138
  132. package/lib/vendor/node_modules/ssh2/test/test-sftp.js +0 -842
  133. package/lib/vendor/node_modules/ssh2/test/test-shell.js +0 -109
  134. package/lib/vendor/node_modules/ssh2/test/test-userauth-agent-openssh.js +0 -110
  135. package/lib/vendor/node_modules/ssh2/test/test-userauth-agent.js +0 -171
  136. package/lib/vendor/node_modules/ssh2/test/test-userauth.js +0 -611
  137. package/lib/vendor/node_modules/ssh2/test/test-worker-imports.js +0 -25
  138. package/lib/vendor/node_modules/ssh2/test/test.js +0 -20
@@ -1,578 +0,0 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const { inspect } = require('util');
5
-
6
- const {
7
- mustCall,
8
- mustCallAtLeast,
9
- setupSimple,
10
- } = require('./common.js');
11
-
12
- const DEBUG = false;
13
-
14
- const setup = setupSimple.bind(undefined, DEBUG);
15
-
16
- {
17
- const { client, server } = setup('Simple exec()');
18
-
19
- const COMMAND = 'foo --bar';
20
- const STDOUT_DATA = 'stdout data!\n';
21
- const STDERR_DATA = 'stderr data!\n';
22
-
23
- server.on('connection', mustCall((conn) => {
24
- conn.on('ready', mustCall(() => {
25
- conn.on('session', mustCall((accept, reject) => {
26
- accept().on('exec', mustCall((accept, reject, info) => {
27
- assert(info.command === COMMAND,
28
- `Wrong exec command: ${info.command}`);
29
- const stream = accept();
30
- stream.stderr.write(STDERR_DATA);
31
- stream.write(STDOUT_DATA);
32
- stream.exit(100);
33
- stream.end();
34
- conn.end();
35
- }));
36
- }));
37
- }));
38
- }));
39
-
40
- client.on('ready', mustCall(() => {
41
- let out = '';
42
- let outErr = '';
43
- const events = [];
44
- const EXPECTED_EVENTS = [ 'exit', 'close' ];
45
- const EXPECTED_EXIT_CLOSE_ARGS = [ 100 ];
46
- client.on('close', mustCall(() => {
47
- assert(out === STDOUT_DATA, `Wrong stdout data: ${inspect(out)}`);
48
- assert(outErr === STDERR_DATA, `Wrong stderr data: ${inspect(outErr)}`);
49
- assert.deepStrictEqual(
50
- events,
51
- EXPECTED_EVENTS,
52
- `Wrong command event order: ${events}`
53
- );
54
- })).exec(COMMAND, mustCall((err, stream) => {
55
- assert(!err, `Unexpected exec error: ${err}`);
56
- stream.on('data', mustCallAtLeast((d) => {
57
- out += d;
58
- })).on('exit', mustCall((...args) => {
59
- assert.deepStrictEqual(args,
60
- EXPECTED_EXIT_CLOSE_ARGS,
61
- `Wrong exit args: ${inspect(args)}`);
62
- events.push('exit');
63
- })).on('close', mustCall((...args) => {
64
- assert.deepStrictEqual(args,
65
- EXPECTED_EXIT_CLOSE_ARGS,
66
- `Wrong close args: ${inspect(args)}`);
67
- events.push('close');
68
- })).stderr.on('data', mustCallAtLeast((d) => {
69
- outErr += d;
70
- }));
71
- }));
72
- }));
73
- }
74
-
75
- {
76
- const { client, server } = setup('Simple exec() (exit signal)');
77
-
78
- const COMMAND = 'foo --bar';
79
- const STDOUT_DATA = 'stdout data!\n';
80
- const STDERR_DATA = 'stderr data!\n';
81
-
82
- server.on('connection', mustCall((conn) => {
83
- conn.on('ready', mustCall(() => {
84
- conn.on('session', mustCall((accept, reject) => {
85
- accept().on('exec', mustCall((accept, reject, info) => {
86
- assert(info.command === COMMAND,
87
- `Wrong exec command: ${info.command}`);
88
- const stream = accept();
89
- stream.stderr.write(STDERR_DATA);
90
- stream.write(STDOUT_DATA);
91
- assert.throws(() => stream.exit('SIGFAKE'));
92
- stream.exit('SIGKILL');
93
- stream.end();
94
- conn.end();
95
- }));
96
- }));
97
- }));
98
- }));
99
-
100
- client.on('ready', mustCall(() => {
101
- let out = '';
102
- let outErr = '';
103
- const events = [];
104
- const EXPECTED_EVENTS = [ 'exit', 'close' ];
105
- const EXPECTED_EXIT_CLOSE_ARGS = [ null, 'SIGKILL', false, '' ];
106
- client.on('close', mustCall(() => {
107
- assert(out === STDOUT_DATA, `Wrong stdout data: ${inspect(out)}`);
108
- assert(outErr === STDERR_DATA, `Wrong stderr data: ${inspect(outErr)}`);
109
- assert.deepStrictEqual(
110
- events,
111
- EXPECTED_EVENTS,
112
- `Wrong command event order: ${events}`
113
- );
114
- })).exec(COMMAND, mustCall((err, stream) => {
115
- assert(!err, `Unexpected exec error: ${err}`);
116
- stream.on('data', mustCallAtLeast((d) => {
117
- out += d;
118
- })).on('exit', mustCall((...args) => {
119
- assert.deepStrictEqual(args,
120
- EXPECTED_EXIT_CLOSE_ARGS,
121
- `Wrong exit args: ${inspect(args)}`);
122
- events.push('exit');
123
- })).on('close', mustCall((...args) => {
124
- assert.deepStrictEqual(args,
125
- EXPECTED_EXIT_CLOSE_ARGS,
126
- `Wrong close args: ${inspect(args)}`);
127
- events.push('close');
128
- })).stderr.on('data', mustCallAtLeast((d) => {
129
- outErr += d;
130
- }));
131
- }));
132
- }));
133
- }
134
-
135
- {
136
- const { client, server } = setup('Simple exec() (exit signal -- no "SIG")');
137
-
138
- const COMMAND = 'foo --bar';
139
- const STDOUT_DATA = 'stdout data!\n';
140
- const STDERR_DATA = 'stderr data!\n';
141
-
142
- server.on('connection', mustCall((conn) => {
143
- conn.on('ready', mustCall(() => {
144
- conn.on('session', mustCall((accept, reject) => {
145
- accept().on('exec', mustCall((accept, reject, info) => {
146
- assert(info.command === COMMAND,
147
- `Wrong exec command: ${info.command}`);
148
- const stream = accept();
149
- stream.stderr.write(STDERR_DATA);
150
- stream.write(STDOUT_DATA);
151
- assert.throws(() => stream.exit('FAKE'));
152
- stream.exit('KILL');
153
- stream.end();
154
- conn.end();
155
- }));
156
- }));
157
- }));
158
- }));
159
-
160
- client.on('ready', mustCall(() => {
161
- let out = '';
162
- let outErr = '';
163
- const events = [];
164
- const EXPECTED_EVENTS = [ 'exit', 'close' ];
165
- const EXPECTED_EXIT_CLOSE_ARGS = [ null, 'SIGKILL', false, '' ];
166
- client.on('close', mustCall(() => {
167
- assert(out === STDOUT_DATA, `Wrong stdout data: ${inspect(out)}`);
168
- assert(outErr === STDERR_DATA, `Wrong stderr data: ${inspect(outErr)}`);
169
- assert.deepStrictEqual(
170
- events,
171
- EXPECTED_EVENTS,
172
- `Wrong command event order: ${events}`
173
- );
174
- })).exec(COMMAND, mustCall((err, stream) => {
175
- assert(!err, `Unexpected exec error: ${err}`);
176
- stream.on('data', mustCallAtLeast((d) => {
177
- out += d;
178
- })).on('exit', mustCall((...args) => {
179
- assert.deepStrictEqual(args,
180
- EXPECTED_EXIT_CLOSE_ARGS,
181
- `Wrong exit args: ${inspect(args)}`);
182
- events.push('exit');
183
- })).on('close', mustCall((...args) => {
184
- assert.deepStrictEqual(args,
185
- EXPECTED_EXIT_CLOSE_ARGS,
186
- `Wrong close args: ${inspect(args)}`);
187
- events.push('close');
188
- })).stderr.on('data', mustCallAtLeast((d) => {
189
- outErr += d;
190
- }));
191
- }));
192
- }));
193
- }
194
-
195
- {
196
- const { client, server } = setup('Exec with signal()');
197
-
198
- const COMMAND = 'foo --bar';
199
- const STDOUT_DATA = 'stdout data!\n';
200
- const STDERR_DATA = 'stderr data!\n';
201
-
202
- server.on('connection', mustCall((conn) => {
203
- conn.on('ready', mustCall(() => {
204
- conn.on('session', mustCall((accept, reject) => {
205
- let stream;
206
- accept().on('exec', mustCall((accept, reject, info) => {
207
- assert(info.command === COMMAND,
208
- `Wrong exec command: ${info.command}`);
209
- stream = accept();
210
- stream.stderr.write(STDERR_DATA);
211
- stream.write(STDOUT_DATA);
212
- })).on('signal', mustCall((accept, reject, info) => {
213
- assert(info.name === 'INT', `Wrong client signal name: ${info.name}`);
214
- stream.exit(100);
215
- stream.end();
216
- conn.end();
217
- }));
218
- }));
219
- }));
220
- }));
221
-
222
- client.on('ready', mustCall(() => {
223
- let out = '';
224
- let outErr = '';
225
- const events = [];
226
- const EXPECTED_EVENTS = [ 'exit', 'close' ];
227
- const EXPECTED_EXIT_CLOSE_ARGS = [ 100 ];
228
- client.on('close', mustCall(() => {
229
- assert(out === STDOUT_DATA, `Wrong stdout data: ${inspect(out)}`);
230
- assert(outErr === STDERR_DATA, `Wrong stderr data: ${inspect(outErr)}`);
231
- assert.deepStrictEqual(
232
- events,
233
- EXPECTED_EVENTS,
234
- `Wrong command event order: ${events}`
235
- );
236
- })).exec(COMMAND, mustCall((err, stream) => {
237
- assert(!err, `Unexpected exec error: ${err}`);
238
- const sendSignal = (() => {
239
- let sent = false;
240
- return () => {
241
- if (sent)
242
- return;
243
- sent = true;
244
- assert.throws(() => stream.signal('FAKE'));
245
- assert.throws(() => stream.signal('SIGFAKE'));
246
- stream.signal('SIGINT');
247
- };
248
- })();
249
- stream.on('data', mustCallAtLeast((d) => {
250
- out += d;
251
- sendSignal();
252
- })).on('exit', mustCall((...args) => {
253
- assert.deepStrictEqual(args,
254
- EXPECTED_EXIT_CLOSE_ARGS,
255
- `Wrong exit args: ${inspect(args)}`);
256
- events.push('exit');
257
- })).on('close', mustCall((...args) => {
258
- assert.deepStrictEqual(args,
259
- EXPECTED_EXIT_CLOSE_ARGS,
260
- `Wrong close args: ${inspect(args)}`);
261
- events.push('close');
262
- })).stderr.on('data', mustCallAtLeast((d) => {
263
- outErr += d;
264
- }));
265
- }));
266
- }));
267
- }
268
-
269
- {
270
- const { client, server } = setup('Exec with signal() -- no "SIG"');
271
-
272
- const COMMAND = 'foo --bar';
273
- const STDOUT_DATA = 'stdout data!\n';
274
- const STDERR_DATA = 'stderr data!\n';
275
-
276
- server.on('connection', mustCall((conn) => {
277
- conn.on('ready', mustCall(() => {
278
- conn.on('session', mustCall((accept, reject) => {
279
- let stream;
280
- accept().on('exec', mustCall((accept, reject, info) => {
281
- assert(info.command === COMMAND,
282
- `Wrong exec command: ${info.command}`);
283
- stream = accept();
284
- stream.stderr.write(STDERR_DATA);
285
- stream.write(STDOUT_DATA);
286
- })).on('signal', mustCall((accept, reject, info) => {
287
- assert(info.name === 'INT', `Wrong client signal name: ${info.name}`);
288
- stream.exit(100);
289
- stream.end();
290
- conn.end();
291
- }));
292
- }));
293
- }));
294
- }));
295
-
296
- client.on('ready', mustCall(() => {
297
- let out = '';
298
- let outErr = '';
299
- const events = [];
300
- const EXPECTED_EVENTS = [ 'exit', 'close' ];
301
- const EXPECTED_EXIT_CLOSE_ARGS = [ 100 ];
302
- client.on('close', mustCall(() => {
303
- assert(out === STDOUT_DATA, `Wrong stdout data: ${inspect(out)}`);
304
- assert(outErr === STDERR_DATA, `Wrong stderr data: ${inspect(outErr)}`);
305
- assert.deepStrictEqual(
306
- events,
307
- EXPECTED_EVENTS,
308
- `Wrong command event order: ${events}`
309
- );
310
- })).exec(COMMAND, mustCall((err, stream) => {
311
- assert(!err, `Unexpected exec error: ${err}`);
312
- const sendSignal = (() => {
313
- let sent = false;
314
- return () => {
315
- if (sent)
316
- return;
317
- sent = true;
318
- stream.signal('INT');
319
- };
320
- })();
321
- stream.on('data', mustCallAtLeast((d) => {
322
- out += d;
323
- sendSignal();
324
- })).on('exit', mustCall((...args) => {
325
- assert.deepStrictEqual(args,
326
- EXPECTED_EXIT_CLOSE_ARGS,
327
- `Wrong exit args: ${inspect(args)}`);
328
- events.push('exit');
329
- })).on('close', mustCall((...args) => {
330
- assert.deepStrictEqual(args,
331
- EXPECTED_EXIT_CLOSE_ARGS,
332
- `Wrong close args: ${inspect(args)}`);
333
- events.push('close');
334
- })).stderr.on('data', mustCallAtLeast((d) => {
335
- outErr += d;
336
- }));
337
- }));
338
- }));
339
- }
340
-
341
- {
342
- const { client, server } = setup('Exec with environment set');
343
-
344
- const env = { SSH2NODETEST: 'foo' };
345
-
346
- server.on('connection', mustCall((conn) => {
347
- conn.on('ready', mustCall(() => {
348
- conn.on('session', mustCall((accept, reject) => {
349
- accept().on('env', mustCall((accept, reject, info) => {
350
- accept && accept();
351
- assert(info.key === Object.keys(env)[0],
352
- 'Wrong env key');
353
- assert(info.val === Object.values(env)[0],
354
- 'Wrong env value');
355
- })).on('exec', mustCall((accept, reject, info) => {
356
- assert(info.command === 'foo --bar',
357
- `Wrong exec command: ${info.command}`);
358
- const stream = accept();
359
- stream.exit(100);
360
- stream.end();
361
- conn.end();
362
- }));
363
- }));
364
- }));
365
- }));
366
-
367
- client.on('ready', mustCall(() => {
368
- client.exec('foo --bar', { env }, mustCall((err, stream) => {
369
- assert(!err, `Unexpected exec error: ${err}`);
370
- stream.resume();
371
- }));
372
- }));
373
- }
374
-
375
- {
376
- const { client, server } = setup('Exec with setWindow()');
377
-
378
- const dimensions = {
379
- rows: 60,
380
- cols: 115,
381
- height: 480,
382
- width: 640,
383
- };
384
-
385
- server.on('connection', mustCall((conn) => {
386
- conn.on('ready', mustCall(() => {
387
- conn.on('session', mustCall((accept, reject) => {
388
- accept().on('window-change', mustCall((accept, reject, info) => {
389
- accept && accept();
390
- assert.deepStrictEqual(info, dimensions, 'Wrong dimensions');
391
- })).on('exec', mustCall((accept, reject, info) => {
392
- assert(info.command === 'foo --bar',
393
- `Wrong exec command: ${info.command}`);
394
- const stream = accept();
395
- stream.exit(100);
396
- stream.end();
397
- conn.end();
398
- }));
399
- }));
400
- }));
401
- }));
402
-
403
- client.on('ready', mustCall(() => {
404
- client.exec('foo --bar', mustCall((err, stream) => {
405
- assert(!err, `Unexpected exec error: ${err}`);
406
- stream.setWindow(...Object.values(dimensions));
407
- stream.resume();
408
- }));
409
- }));
410
- }
411
-
412
- {
413
- const { client, server } = setup('Exec with pty set');
414
-
415
- const pty = {
416
- rows: 2,
417
- cols: 4,
418
- width: 0,
419
- height: 0,
420
- term: 'vt220',
421
- modes: {},
422
- };
423
-
424
- server.on('connection', mustCall((conn) => {
425
- conn.on('ready', mustCall(() => {
426
- conn.on('session', mustCall((accept, reject) => {
427
- let sawPty = false;
428
- accept().on('pty', mustCall((accept, reject, info) => {
429
- assert.deepStrictEqual(info, pty, 'Wrong pty info');
430
- sawPty = true;
431
- accept && accept();
432
- })).on('exec', mustCall((accept, reject, info) => {
433
- assert(sawPty, 'Expected pty to be set up');
434
- assert(info.command === 'foo --bar',
435
- `Wrong exec command: ${info.command}`);
436
- const stream = accept();
437
- stream.exit(100);
438
- stream.end();
439
- conn.end();
440
- }));
441
- }));
442
- }));
443
- }));
444
-
445
- client.on('ready', mustCall(() => {
446
- client.exec('foo --bar', { pty }, mustCall((err, stream) => {
447
- assert(!err, `Unexpected exec error: ${err}`);
448
- stream.resume();
449
- }));
450
- }));
451
- }
452
-
453
- {
454
- const { client, server } = setup('Exec with X11 forwarding');
455
-
456
- server.on('connection', mustCall((conn) => {
457
- conn.on('ready', mustCall(() => {
458
- conn.on('session', mustCall((accept, reject) => {
459
- let sawX11 = false;
460
- accept().on('x11', mustCall((accept, reject, info) => {
461
- assert.strictEqual(info.single,
462
- false,
463
- `Wrong x11 single: ${info.single}`);
464
- assert.strictEqual(info.screen,
465
- 0,
466
- `Wrong x11 screen: ${info.screen}`);
467
- assert.strictEqual(info.protocol,
468
- 'MIT-MAGIC-COOKIE-1',
469
- `Wrong x11 protocol: ${info.protocol}`);
470
- assert(Buffer.isBuffer(info.cookie), 'Expected cookie Buffer');
471
- assert.strictEqual(
472
- info.cookie.length,
473
- 32,
474
- `Invalid x11 cookie length: ${info.cookie.length}`
475
- );
476
- sawX11 = true;
477
- accept && accept();
478
- })).on('exec', mustCall((accept, reject, info) => {
479
- assert(sawX11, 'Expected x11 before exec');
480
- assert(info.command === 'foo --bar',
481
- `Wrong exec command: ${info.command}`);
482
- const stream = accept();
483
- conn.x11('127.0.0.1', 4321, mustCall((err, xstream) => {
484
- assert(!err, `Unexpected x11() error: ${err}`);
485
- xstream.resume();
486
- xstream.on('end', mustCall(() => {
487
- stream.exit(100);
488
- stream.end();
489
- conn.end();
490
- })).end();
491
- }));
492
- }));
493
- }));
494
- }));
495
- }));
496
-
497
- client.on('ready', mustCall(() => {
498
- client.on('x11', mustCall((info, accept, reject) => {
499
- assert.strictEqual(info.srcIP,
500
- '127.0.0.1',
501
- `Invalid x11 srcIP: ${info.srcIP}`);
502
- assert.strictEqual(info.srcPort,
503
- 4321,
504
- `Invalid x11 srcPort: ${info.srcPort}`);
505
- accept();
506
- })).exec('foo --bar', { x11: true }, mustCall((err, stream) => {
507
- assert(!err, `Unexpected exec error: ${err}`);
508
- stream.resume();
509
- }));
510
- }));
511
- }
512
-
513
- {
514
- const { client, server } = setup(
515
- 'Exec with X11 forwarding (custom X11 settings)'
516
- );
517
-
518
- const x11 = {
519
- single: true,
520
- screen: 1234,
521
- protocol: 'YUMMY-MAGIC-COOKIE-1',
522
- cookie: '00112233445566778899001122334455',
523
- };
524
-
525
- server.on('connection', mustCall((conn) => {
526
- conn.on('ready', mustCall(() => {
527
- conn.on('session', mustCall((accept, reject) => {
528
- let sawX11 = false;
529
- accept().on('x11', mustCall((accept, reject, info) => {
530
- assert.strictEqual(info.single,
531
- x11.single,
532
- `Wrong x11 single: ${info.single}`);
533
- assert.strictEqual(info.screen,
534
- x11.screen,
535
- `Wrong x11 screen: ${info.screen}`);
536
- assert.strictEqual(info.protocol,
537
- x11.protocol,
538
- `Wrong x11 protocol: ${info.protocol}`);
539
- assert(Buffer.isBuffer(info.cookie), 'Expected cookie Buffer');
540
- assert.strictEqual(info.cookie.toString(),
541
- x11.cookie,
542
- `Wrong x11 cookie: ${info.cookie}`);
543
- sawX11 = true;
544
- accept && accept();
545
- })).on('exec', mustCall((accept, reject, info) => {
546
- assert(sawX11, 'Expected x11 before exec');
547
- assert(info.command === 'foo --bar',
548
- `Wrong exec command: ${info.command}`);
549
- const stream = accept();
550
- conn.x11('127.0.0.1', 4321, mustCall((err, xstream) => {
551
- assert(!err, `Unexpected x11() error: ${err}`);
552
- xstream.resume();
553
- xstream.on('end', mustCall(() => {
554
- stream.exit(100);
555
- stream.end();
556
- conn.end();
557
- })).end();
558
- }));
559
- }));
560
- }));
561
- }));
562
- }));
563
-
564
- client.on('ready', mustCall(() => {
565
- client.on('x11', mustCall((info, accept, reject) => {
566
- assert.strictEqual(info.srcIP,
567
- '127.0.0.1',
568
- `Invalid x11 srcIP: ${info.srcIP}`);
569
- assert.strictEqual(info.srcPort,
570
- 4321,
571
- `Invalid x11 srcPort: ${info.srcPort}`);
572
- accept();
573
- })).exec('foo --bar', { x11 }, mustCall((err, stream) => {
574
- assert(!err, `Unexpected exec error: ${err}`);
575
- stream.resume();
576
- }));
577
- }));
578
- }