diff options
Diffstat (limited to 'spec/frontend/lib/utils/url_utility_spec.js')
-rw-r--r-- | spec/frontend/lib/utils/url_utility_spec.js | 53 |
1 files changed, 11 insertions, 42 deletions
diff --git a/spec/frontend/lib/utils/url_utility_spec.js b/spec/frontend/lib/utils/url_utility_spec.js index 7608cff4c9e..81cf4bd293b 100644 --- a/spec/frontend/lib/utils/url_utility_spec.js +++ b/spec/frontend/lib/utils/url_utility_spec.js @@ -1,6 +1,7 @@ import setWindowLocation from 'helpers/set_window_location_helper'; import { TEST_HOST } from 'helpers/test_constants'; import * as urlUtils from '~/lib/utils/url_utility'; +import { safeUrls, unsafeUrls } from './mock_data'; const shas = { valid: [ @@ -575,48 +576,6 @@ describe('URL utility', () => { }); describe('isSafeUrl', () => { - const absoluteUrls = [ - 'http://example.org', - 'http://example.org:8080', - 'https://example.org', - 'https://example.org:8080', - 'https://192.168.1.1', - ]; - - const rootRelativeUrls = ['/relative/link']; - - const relativeUrls = ['./relative/link', '../relative/link']; - - const urlsWithoutHost = ['http://', 'https://', 'https:https:https:']; - - /* eslint-disable no-script-url */ - const nonHttpUrls = [ - 'javascript:', - 'javascript:alert("XSS")', - 'jav\tascript:alert("XSS");', - '  javascript:alert("XSS");', - 'ftp://192.168.1.1', - 'file:///', - 'file:///etc/hosts', - ]; - /* eslint-enable no-script-url */ - - // javascript:alert('XSS') - const encodedJavaScriptUrls = [ - 'javascript:alert('XSS')', - 'javascript:alert('XSS')', - 'javascript:alert('XSS')', - '\\u006A\\u0061\\u0076\\u0061\\u0073\\u0063\\u0072\\u0069\\u0070\\u0074\\u003A\\u0061\\u006C\\u0065\\u0072\\u0074\\u0028\\u0027\\u0058\\u0053\\u0053\\u0027\\u0029', - ]; - - const safeUrls = [...absoluteUrls, ...rootRelativeUrls]; - const unsafeUrls = [ - ...relativeUrls, - ...urlsWithoutHost, - ...nonHttpUrls, - ...encodedJavaScriptUrls, - ]; - describe('with URL constructor support', () => { it.each(safeUrls)('returns true for %s', (url) => { expect(urlUtils.isSafeURL(url)).toBe(true); @@ -628,6 +587,16 @@ describe('URL utility', () => { }); }); + describe('sanitizeUrl', () => { + it.each(safeUrls)('returns the url for %s', (url) => { + expect(urlUtils.sanitizeUrl(url)).toBe(url); + }); + + it.each(unsafeUrls)('returns `about:blank` for %s', (url) => { + expect(urlUtils.sanitizeUrl(url)).toBe('about:blank'); + }); + }); + describe('getNormalizedURL', () => { it.each` url | base | result |