| 197 | } |
| 198 | |
| 199 | const requestNextKey = (): void => { |
| 200 | authHandler([], false, (auth: string | AnyAuthMethod | false) => { |
| 201 | expect(auth).not.toBe(false); |
| 202 | expect(typeof auth).toBe('object'); |
| 203 | if (auth === false || typeof auth !== 'object') { |
| 204 | client.emit('error', new Error('authHandler returned no auth method')); |
| 205 | return; |
| 206 | } |
| 207 | if (auth.type !== 'publickey') { |
| 208 | client.emit('error', new Error(`unexpected auth type: ${auth.type}`)); |
| 209 | return; |
| 210 | } |
| 211 | const key = |
| 212 | typeof auth.key === 'string' |
| 213 | ? auth.key |
| 214 | : Buffer.isBuffer(auth.key) |
| 215 | ? auth.key.toString('utf-8') |
| 216 | : JSON.stringify(auth.key); |
| 217 | harnessState.attemptedKeys.push(key); |
| 218 | if (key === 'first-key') { |
| 219 | requestNextKey(); |
| 220 | return; |
| 221 | } |
| 222 | queueMicrotask(() => { |
| 223 | client.emit('ready'); |
| 224 | }); |
| 225 | }); |
| 226 | }; |
| 227 | |
| 228 | requestNextKey(); |
| 229 | }, |