|
| 1 | +/* global describe, it */ |
| 2 | +'use strict' |
| 3 | + |
| 4 | +const expect = require('chai').expect |
| 5 | +const { buildURL } = require('./../lib/utils') |
| 6 | + |
| 7 | +describe('buildURL', () => { |
| 8 | + it('should produce invalid URL - //10.0.0.10/', function () { |
| 9 | + const url = new URL('//10.0.0.10/', 'http://localhost') |
| 10 | + expect(url.origin).to.equal('http://10.0.0.10') |
| 11 | + expect(url.pathname).to.equal('/') |
| 12 | + expect(url.href).to.equal('http://10.0.0.10/') |
| 13 | + }) |
| 14 | + |
| 15 | + it('should produce invalid URL - //httpbin.org/hi', function () { |
| 16 | + const url = new URL('//httpbin.org/hi', 'http://localhost') |
| 17 | + expect(url.origin).to.equal('http://httpbin.org') |
| 18 | + expect(url.pathname).to.equal('/hi') |
| 19 | + expect(url.href).to.equal('http://httpbin.org/hi') |
| 20 | + }) |
| 21 | + |
| 22 | + it('should produce valid URL (2 params)', function () { |
| 23 | + const url = buildURL('/hi', 'http://localhost') |
| 24 | + |
| 25 | + expect(url.origin).to.equal('http://localhost') |
| 26 | + expect(url.pathname).to.equal('/hi') |
| 27 | + expect(url.href).to.equal('http://localhost/hi') |
| 28 | + }) |
| 29 | + |
| 30 | + it('should produce valid URL (1 param)', function () { |
| 31 | + const url = buildURL('http://localhost/hi') |
| 32 | + |
| 33 | + expect(url.origin).to.equal('http://localhost') |
| 34 | + expect(url.pathname).to.equal('/hi') |
| 35 | + expect(url.href).to.equal('http://localhost/hi') |
| 36 | + }) |
| 37 | + |
| 38 | + it('should sanitize invalid source (2 params) - //10.0.0.10/hi', function () { |
| 39 | + const url = buildURL('//10.0.0.10/hi', 'http://localhost') |
| 40 | + |
| 41 | + expect(url.origin).to.equal('http://localhost') |
| 42 | + expect(url.pathname).to.equal('/10.0.0.10/hi') |
| 43 | + expect(url.href).to.equal('http://localhost/10.0.0.10/hi') |
| 44 | + }) |
| 45 | + |
| 46 | + it('should sanitize invalid source (2 params) - //httpbin.org/hi', function () { |
| 47 | + const url = buildURL('//httpbin.org/hi', 'http://localhost') |
| 48 | + |
| 49 | + expect(url.origin).to.equal('http://localhost') |
| 50 | + expect(url.pathname).to.equal('/httpbin.org/hi') |
| 51 | + expect(url.href).to.equal('http://localhost/httpbin.org/hi') |
| 52 | + }) |
| 53 | +}) |
0 commit comments