(
askpassDir: string,
promptText: string,
requestId: string,
cleanupResponseFiles = true
)
| 7 | describe("sshAskpass", () => { |
| 8 | describe("createAskpassSession", () => { |
| 9 | async function simulateAskpassInvocation( |
| 10 | askpassDir: string, |
| 11 | promptText: string, |
| 12 | requestId: string, |
| 13 | cleanupResponseFiles = true |
| 14 | ): Promise<string> { |
| 15 | const promptFile = path.join(askpassDir, `prompt.${requestId}.txt`); |
| 16 | const responseFile = path.join(askpassDir, `response.${requestId}.txt`); |
| 17 | |
| 18 | // Simulate askpass writing prompt content for this invocation. |
| 19 | await fs.promises.writeFile(promptFile, promptText, "utf-8"); |
| 20 | |
| 21 | // Poll for the response file written by createAskpassSession(). |
| 22 | for (let i = 0; i < 100; i += 1) { |
| 23 | try { |
| 24 | const response = await fs.promises.readFile(responseFile, "utf-8"); |
| 25 | |
| 26 | if (cleanupResponseFiles) { |
| 27 | // Simulate askpass script cleanup. |
| 28 | await fs.promises.unlink(promptFile).catch(() => undefined); |
| 29 | await fs.promises.unlink(responseFile).catch(() => undefined); |
| 30 | } |
| 31 | |
| 32 | return response.trim(); |
| 33 | } catch { |
| 34 | await new Promise((resolve) => setTimeout(resolve, 50)); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | throw new Error(`Timeout waiting for response for request '${requestId}'`); |
| 39 | } |
| 40 | |
| 41 | async function listAskpassTempDirs(): Promise<string[]> { |
| 42 | return (await fs.promises.readdir(os.tmpdir())) |
no test coverage detected