(request, response)
| 188 | } |
| 189 | |
| 190 | function sendBasicAuth(request, response) { |
| 191 | const denyAccess = function () { |
| 192 | response.writeHead(401, { 'WWW-Authenticate': 'Basic realm="test"' }) |
| 193 | response.end('Access denied') |
| 194 | } |
| 195 | |
| 196 | const basicAuthRegExp = /^\s*basic\s+([a-z0-9\-._~+/]+)=*\s*$/i |
| 197 | const auth = request.headers.authorization |
| 198 | const match = basicAuthRegExp.exec(auth || '') |
| 199 | if (!match) { |
| 200 | denyAccess() |
| 201 | return |
| 202 | } |
| 203 | |
| 204 | const userNameAndPass = Buffer.from(match[1], 'base64').toString() |
| 205 | const parts = userNameAndPass.split(':', 2) |
| 206 | if (parts[0] !== 'genie' || parts[1] !== 'bottle') { |
| 207 | denyAccess() |
| 208 | return |
| 209 | } |
| 210 | |
| 211 | response.writeHead(200, { 'content-type': 'text/plain' }) |
| 212 | response.end('Access granted!') |
| 213 | } |
| 214 | |
| 215 | function sendDelayedResponse(request, response) { |
| 216 | var duration = 0 |
nothing calls this directly
no test coverage detected