11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst http = require('http'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst testCases = [ 71cb0ef41Sopenharmony_ci { 81cb0ef41Sopenharmony_ci username: 'test@test"', 91cb0ef41Sopenharmony_ci password: '123456^', 101cb0ef41Sopenharmony_ci expected: 'dGVzdEB0ZXN0IjoxMjM0NTZe' 111cb0ef41Sopenharmony_ci }, 121cb0ef41Sopenharmony_ci { 131cb0ef41Sopenharmony_ci username: 'test%40test', 141cb0ef41Sopenharmony_ci password: '123456', 151cb0ef41Sopenharmony_ci expected: 'dGVzdEB0ZXN0OjEyMzQ1Ng==' 161cb0ef41Sopenharmony_ci }, 171cb0ef41Sopenharmony_ci { 181cb0ef41Sopenharmony_ci username: 'not%3Agood', 191cb0ef41Sopenharmony_ci password: 'god', 201cb0ef41Sopenharmony_ci expected: 'bm90Omdvb2Q6Z29k' 211cb0ef41Sopenharmony_ci }, 221cb0ef41Sopenharmony_ci { 231cb0ef41Sopenharmony_ci username: 'not%22good', 241cb0ef41Sopenharmony_ci password: 'g%5Eod', 251cb0ef41Sopenharmony_ci expected: 'bm90Imdvb2Q6Z15vZA==' 261cb0ef41Sopenharmony_ci }, 271cb0ef41Sopenharmony_ci { 281cb0ef41Sopenharmony_ci username: 'test1234::::', 291cb0ef41Sopenharmony_ci password: 'mypass', 301cb0ef41Sopenharmony_ci expected: 'dGVzdDEyMzQ6Ojo6Om15cGFzcw==' 311cb0ef41Sopenharmony_ci }, 321cb0ef41Sopenharmony_ci]; 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_cifor (const testCase of testCases) { 351cb0ef41Sopenharmony_ci const server = http.createServer(function(request, response) { 361cb0ef41Sopenharmony_ci // The correct authorization header is be passed 371cb0ef41Sopenharmony_ci assert.strictEqual(request.headers.authorization, `Basic ${testCase.expected}`); 381cb0ef41Sopenharmony_ci response.writeHead(200, {}); 391cb0ef41Sopenharmony_ci response.end('ok'); 401cb0ef41Sopenharmony_ci server.close(); 411cb0ef41Sopenharmony_ci }); 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci server.listen(0, function() { 441cb0ef41Sopenharmony_ci // make the request 451cb0ef41Sopenharmony_ci const url = new URL(`http://${testCase.username}:${testCase.password}@localhost:${this.address().port}`); 461cb0ef41Sopenharmony_ci http.request(url).end(); 471cb0ef41Sopenharmony_ci }); 481cb0ef41Sopenharmony_ci} 49