(url: string, opts?: ConnectOptions)
| 180 | } |
| 181 | |
| 182 | function expectRejected(url: string, opts?: ConnectOptions): Promise<void> { |
| 183 | return new Promise((resolve, reject) => { |
| 184 | const ws = new WebSocket(url, opts?.protocols, { headers: opts?.headers }); |
| 185 | const done = (err?: Error): void => { |
| 186 | clearTimeout(t); |
| 187 | ws.removeAllListeners(); |
| 188 | try { |
| 189 | ws.terminate(); |
| 190 | } catch { |
| 191 | // ignore |
| 192 | } |
| 193 | if (err !== undefined) reject(err); |
| 194 | else resolve(); |
| 195 | }; |
| 196 | const t = setTimeout( |
| 197 | () => done(new Error('connection was not rejected within timeout')), |
| 198 | 1500, |
| 199 | ); |
| 200 | ws.once('open', () => done(new Error('connection unexpectedly opened'))); |
| 201 | ws.once('error', () => done()); |
| 202 | ws.once('close', () => done()); |
| 203 | }); |
| 204 | } |
| 205 | |
| 206 | describe('HTTP Host check (start.ts)', () => { |
| 207 | it('rejects Host: evil.com with 403 before the route handler', async () => { |
no test coverage detected