(mode, token)
| 11 | const { writeSettings } = require('../src/proxy/server/settings'); |
| 12 | |
| 13 | function startStatusServer(mode, token) { |
| 14 | const child = spawn(process.execPath, ['-e', ` |
| 15 | const http = require('http'); |
| 16 | const mode = process.env.TEST_PROXY_MODE; |
| 17 | const token = process.env.TEST_PROXY_TOKEN; |
| 18 | const server = http.createServer((req, res) => { |
| 19 | if (mode === 'auth') { |
| 20 | if (req.headers.authorization !== 'Bearer ' + token) { |
| 21 | res.writeHead(401, { 'content-type': 'application/json' }); |
| 22 | res.end(JSON.stringify({ error: 'unauthorized' })); |
| 23 | return; |
| 24 | } |
| 25 | res.writeHead(200, { 'content-type': 'application/json' }); |
| 26 | res.end(JSON.stringify({ |
| 27 | status: 'running', |
| 28 | proxy_protocol_version: '1.0.0', |
| 29 | schema_version: '1.0.0', |
| 30 | })); |
| 31 | return; |
| 32 | } |
| 33 | res.writeHead(200, { 'content-type': 'application/json' }); |
| 34 | res.end(JSON.stringify({ ok: true })); |
| 35 | }); |
| 36 | server.listen(0, '127.0.0.1', () => { |
| 37 | process.stdout.write('http://127.0.0.1:' + server.address().port + '\\n'); |
| 38 | }); |
| 39 | process.on('SIGTERM', () => server.close(() => process.exit(0))); |
| 40 | `], { |
| 41 | env: { PATH: process.env.PATH, TEST_PROXY_MODE: mode, TEST_PROXY_TOKEN: token || '' }, |
| 42 | stdio: ['ignore', 'pipe', 'inherit'], |
| 43 | }); |
| 44 | return new Promise((resolve, reject) => { |
| 45 | let settled = false; |
| 46 | child.once('error', reject); |
| 47 | child.stdout.once('data', (chunk) => { |
| 48 | settled = true; |
| 49 | resolve({ child, url: String(chunk).trim() }); |
| 50 | }); |
| 51 | child.once('exit', (code) => { |
| 52 | if (!settled) reject(new Error(`status server exited early: ${code}`)); |
| 53 | }); |
| 54 | }); |
| 55 | } |
| 56 | |
| 57 | function close(child) { |
| 58 | return new Promise((resolve) => { |
no outgoing calls
no test coverage detected