(authHandler)
| 91 | } |
| 92 | |
| 93 | async function startServer (authHandler) { |
| 94 | const clients = new Set() |
| 95 | const server = new Server({ |
| 96 | hostKeys: [HOST_KEY.private] |
| 97 | }, (client) => { |
| 98 | clients.add(client) |
| 99 | const cleanup = () => clients.delete(client) |
| 100 | |
| 101 | client.on('close', cleanup) |
| 102 | client.on('end', cleanup) |
| 103 | client.on('authentication', (ctx) => { |
| 104 | authHandler(ctx) |
| 105 | }) |
| 106 | client.on('ready', () => { |
| 107 | client.on('session', (accept) => { |
| 108 | const sshSession = accept() |
| 109 | sshSession.on('env', (accept) => accept()) |
| 110 | sshSession.on('pty', (accept) => accept()) |
| 111 | sshSession.on('shell', (accept) => { |
| 112 | const stream = accept() |
| 113 | stream.write('electerm ready\n') |
| 114 | }) |
| 115 | }) |
| 116 | }) |
| 117 | }) |
| 118 | |
| 119 | server.listen(0, '127.0.0.1') |
| 120 | await once(server, 'listening') |
| 121 | |
| 122 | return { |
| 123 | port: server.address().port, |
| 124 | async close () { |
| 125 | for (const client of clients) { |
| 126 | client.end() |
| 127 | } |
| 128 | await new Promise((resolve, reject) => { |
| 129 | server.close((err) => { |
| 130 | if (err) { |
| 131 | reject(err) |
| 132 | } else { |
| 133 | resolve() |
| 134 | } |
| 135 | }) |
| 136 | }) |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | function createPromptWs (promptResponder, options = {}) { |
| 142 | const { |
no test coverage detected