File size: 813 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// @flow
import normalizeUrl from '../normalize-url';

type Input = string;
type Output = string;

// If only Input is provided it tests for input === output
type TestCase = [Input, Output];

type TestCases = {
  [testName: string]: TestCase,
};

const testCases: TestCases = {
  'should do nothing to https URLs': [
    'https://github.com',
    'https://github.com',
  ],
  'should do nothing to http URLs': ['http://github.com', 'http://github.com'],
  'should add https:// in front of URLs without protocol': [
    'github.com',
    'https://github.com',
  ],
  'should block malicious links': [
    'javascript:alert(document.cookie)',
    'about:blank',
  ],
};

Object.keys(testCases).forEach(name => {
  it(name, () => {
    expect(normalizeUrl(testCases[name][0])).toEqual(testCases[name][1]);
  });
});