(context: BrowserContext)
| 54 | }; |
| 55 | |
| 56 | export const resetExternalAuthKey = async (context: BrowserContext) => { |
| 57 | // Find the session token so we can destroy the external auth link between tests, to ensure valid authentication happens each time. |
| 58 | const cookies = await context.cookies(); |
| 59 | const sessionCookie = cookies.find((c) => c.name === "coder_session_token"); |
| 60 | const options = { |
| 61 | method: "DELETE", |
| 62 | hostname: "127.0.0.1", |
| 63 | port: coderPort, |
| 64 | path: `/api/v2/external-auth/${gitAuth.webProvider}?coder_session_token=${sessionCookie?.value}`, |
| 65 | }; |
| 66 | |
| 67 | const req = http.request(options, (res) => { |
| 68 | let data = ""; |
| 69 | res.on("data", (chunk) => { |
| 70 | data += chunk; |
| 71 | }); |
| 72 | |
| 73 | res.on("end", () => { |
| 74 | // Both 200 (key deleted successfully) and 500 (key was not found) are valid responses. |
| 75 | if (res.statusCode !== 200 && res.statusCode !== 500) { |
| 76 | console.error("failed to delete external auth link", data); |
| 77 | throw new Error( |
| 78 | `failed to delete external auth link: HTTP response ${res.statusCode}`, |
| 79 | ); |
| 80 | } |
| 81 | }); |
| 82 | }); |
| 83 | |
| 84 | req.on("error", (err) => { |
| 85 | throw err.message; |
| 86 | }); |
| 87 | |
| 88 | req.end(); |
| 89 | }; |
| 90 | |
| 91 | const isApiCall = (urlString: string): boolean => { |
| 92 | const url = new URL(urlString); |
no test coverage detected