• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2require('../common');
3const assert = require('assert');
4const http = require('http');
5
6const testCases = [
7  {
8    username: 'test@test"',
9    password: '123456^',
10    expected: 'dGVzdEB0ZXN0IjoxMjM0NTZe'
11  },
12  {
13    username: 'test%40test',
14    password: '123456',
15    expected: 'dGVzdEB0ZXN0OjEyMzQ1Ng=='
16  },
17  {
18    username: 'not%3Agood',
19    password: 'god',
20    expected: 'bm90Omdvb2Q6Z29k'
21  },
22  {
23    username: 'not%22good',
24    password: 'g%5Eod',
25    expected: 'bm90Imdvb2Q6Z15vZA=='
26  },
27  {
28    username: 'test1234::::',
29    password: 'mypass',
30    expected: 'dGVzdDEyMzQ6Ojo6Om15cGFzcw=='
31  },
32];
33
34for (const testCase of testCases) {
35  const server = http.createServer(function(request, response) {
36    // The correct authorization header is be passed
37    assert.strictEqual(request.headers.authorization, `Basic ${testCase.expected}`);
38    response.writeHead(200, {});
39    response.end('ok');
40    server.close();
41  });
42
43  server.listen(0, function() {
44    // make the request
45    const url = new URL(`http://${testCase.username}:${testCase.password}@localhost:${this.address().port}`);
46    http.request(url).end();
47  });
48}
49