Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
2993a8b0
Commit
2993a8b0
authored
Feb 20, 2019
by
Winnie Hellmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use table-based tests for is_safe_url_spec.js
parent
81559676
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
106 deletions
+45
-106
ee/spec/frontend/vue_shared/components/is_safe_url_spec.js
ee/spec/frontend/vue_shared/components/is_safe_url_spec.js
+45
-106
No files found.
ee/spec/frontend/vue_shared/components/is_safe_url_spec.js
View file @
2993a8b0
...
...
@@ -2,62 +2,46 @@
import
isSafeURL
from
'
ee/vue_shared/components/is_safe_url
'
;
describe
(
'
isSafeUrl
'
,
()
=>
{
describe
(
'
with URL constructor support
'
,
()
=>
{
it
(
'
returns true for absolute http(s) urls
'
,
()
=>
{
expect
(
isSafeURL
(
'
http://example.org
'
)).
toBe
(
true
);
expect
(
isSafeURL
(
'
http://example.org:8080
'
)).
toBe
(
true
);
expect
(
isSafeURL
(
'
https://example.org
'
)).
toBe
(
true
);
expect
(
isSafeURL
(
'
https://example.org:8080
'
)).
toBe
(
true
);
expect
(
isSafeURL
(
'
https://192.168.1.1
'
)).
toBe
(
true
);
});
it
(
'
returns false for relative urls
'
,
()
=>
{
expect
(
isSafeURL
(
'
./relative/link
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
/relative/link
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
../relative/link
'
)).
toBe
(
false
);
});
it
(
'
returns false for http(s) urls without host
'
,
()
=>
{
expect
(
isSafeURL
(
'
http://
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
https://
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
https:https:https:
'
)).
toBe
(
false
);
});
const
absoluteUrls
=
[
'
http://example.org
'
,
'
http://example.org:8080
'
,
'
https://example.org
'
,
'
https://example.org:8080
'
,
'
https://192.168.1.1
'
,
];
const
relativeUrls
=
[
'
./relative/link
'
,
'
/relative/link
'
,
'
../relative/link
'
];
const
urlsWithoutHost
=
[
'
http://
'
,
'
https://
'
,
'
https:https:https:
'
];
const
nonHttpUrls
=
[
'
javascript:
'
,
'
javascript:alert("XSS")
'
,
'
jav
\t
ascript:alert("XSS");
'
,
'
 javascript:alert("XSS");
'
,
'
ftp://192.168.1.1
'
,
'
file:///
'
,
'
file:///etc/hosts
'
,
];
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
'
,
];
it
(
'
returns false for non http(s) links
'
,
()
=>
{
expect
(
isSafeURL
(
'
javascript:
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
javascript:alert("XSS")
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
jav
\t
ascript:alert("XSS");
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
 javascript:alert("XSS");
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
ftp://192.168.1.1
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
file:///
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
file:///etc/hosts
'
)).
toBe
(
false
);
describe
(
'
with URL constructor support
'
,
()
=>
{
it
.
each
(
absoluteUrls
)(
'
returns true for %s
'
,
url
=>
{
expect
(
isSafeURL
(
url
)).
toBe
(
true
);
});
it
(
'
returns false for encoded javascript links
'
,
()
=>
{
expect
(
isSafeURL
(
'
javascript:alert('XSS')
'
,
),
).
toBe
(
false
);
expect
(
isSafeURL
(
'
javascript:alert('XSS')
'
,
),
).
toBe
(
false
);
expect
(
isSafeURL
(
'
javascript:alert('XSS')
'
,
),
).
toBe
(
false
);
expect
(
isSafeURL
(
'
\\
u006A
\\
u0061
\\
u0076
\\
u0061
\\
u0073
\\
u0063
\\
u0072
\\
u0069
\\
u0070
\\
u0074
\\
u003A
\\
u0061
\\
u006C
\\
u0065
\\
u0072
\\
u0074
\\
u0028
\\
u0027
\\
u0058
\\
u0053
\\
u0053
\\
u0027
\\
u0029
'
,
),
).
toBe
(
false
);
});
it
.
each
([...
relativeUrls
,
...
urlsWithoutHost
,
...
nonHttpUrls
,
...
encodedJavaScriptUrls
])(
'
returns false for %s
'
,
url
=>
{
expect
(
isSafeURL
(
url
)).
toBe
(
false
);
},
);
});
describe
(
'
without URL constructor support
'
,
()
=>
{
...
...
@@ -67,60 +51,15 @@ describe('isSafeUrl', () => {
});
});
it
(
'
returns true for absolute http(s) urls
'
,
()
=>
{
expect
(
isSafeURL
(
'
http://example.org
'
)).
toBe
(
true
);
expect
(
isSafeURL
(
'
http://example.org:8080
'
)).
toBe
(
true
);
expect
(
isSafeURL
(
'
https://example.org
'
)).
toBe
(
true
);
expect
(
isSafeURL
(
'
https://example.org:8080
'
)).
toBe
(
true
);
expect
(
isSafeURL
(
'
https://192.168.1.1
'
)).
toBe
(
true
);
it
.
each
(
absoluteUrls
)(
'
returns true for %s
'
,
url
=>
{
expect
(
isSafeURL
(
url
)).
toBe
(
true
);
});
it
(
'
returns true for relative urls
'
,
()
=>
{
expect
(
isSafeURL
(
'
./relative/link
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
/relative/link
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
../relative/link
'
)).
toBe
(
false
);
});
it
(
'
returns false for http(s) urls without host
'
,
()
=>
{
expect
(
isSafeURL
(
'
http://
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
https://
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
https:https:https:
'
)).
toBe
(
false
);
});
it
(
'
returns false for non http(s) links
'
,
()
=>
{
expect
(
isSafeURL
(
'
javascript:
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
javascript:alert("XSS")
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
jav
\t
ascript:alert("XSS");
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
 javascript:alert("XSS");
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
ftp://192.168.1.1
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
file:///
'
)).
toBe
(
false
);
expect
(
isSafeURL
(
'
file:///etc/hosts
'
)).
toBe
(
false
);
});
it
(
'
returns false for encoded javascript links
'
,
()
=>
{
expect
(
isSafeURL
(
'
javascript:alert('XSS')
'
,
),
).
toBe
(
false
);
expect
(
isSafeURL
(
'
javascript:alert('XSS')
'
,
),
).
toBe
(
false
);
expect
(
isSafeURL
(
'
javascript:alert('XSS')
'
,
),
).
toBe
(
false
);
expect
(
isSafeURL
(
'
\\
u006A
\\
u0061
\\
u0076
\\
u0061
\\
u0073
\\
u0063
\\
u0072
\\
u0069
\\
u0070
\\
u0074
\\
u003A
\\
u0061
\\
u006C
\\
u0065
\\
u0072
\\
u0074
\\
u0028
\\
u0027
\\
u0058
\\
u0053
\\
u0053
\\
u0027
\\
u0029
'
,
),
).
toBe
(
false
);
});
it
.
each
([...
relativeUrls
,
...
urlsWithoutHost
,
...
nonHttpUrls
,
...
encodedJavaScriptUrls
])(
'
returns false for %s
'
,
url
=>
{
expect
(
isSafeURL
(
url
)).
toBe
(
false
);
},
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment