Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dependency_linker_util_spec.js « utils « plugins « source_viewer « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e4ce07ec668eed61d40248b8df21a9880927b773 (plain)
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
import {
  createLink,
  generateHLJSOpenTag,
} from '~/vue_shared/components/source_viewer/plugins/utils/dependency_linker_util';

describe('createLink', () => {
  it('generates a link with the correct attributes', () => {
    const href = 'http://test.com';
    const innerText = 'testing';
    const result = `<a href="${href}" rel="nofollow noreferrer noopener">${innerText}</a>`;

    expect(createLink(href, innerText)).toBe(result);
  });

  it('escapes the user-controlled content', () => {
    const unescapedXSS = '<script>XSS</script>';
    const escapedPackageName = '&lt;script&gt;XSS&lt;/script&gt;';
    const escapedHref = '&lt;script&gt;XSS&lt;/script&gt;';
    const href = `http://test.com/${unescapedXSS}`;
    const innerText = `testing${unescapedXSS}`;
    const result = `<a href="http://test.com/${escapedHref}" rel="nofollow noreferrer noopener">testing${escapedPackageName}</a>`;

    expect(createLink(href, innerText)).toBe(result);
  });
});

describe('generateHLJSOpenTag', () => {
  it('generates an open tag with the correct selector', () => {
    const type = 'string';
    const result = `<span class="hljs-${type}">&quot;`;

    expect(generateHLJSOpenTag(type)).toBe(result);
  });
});