提交 e88e032d 编写于 作者: P Pine Wu

Refactor link protection test

上级 2d8b41d2
......@@ -8,42 +8,49 @@ import * as assert from 'assert';
import { isURLDomainTrusted } from 'vs/workbench/contrib/url/common/trustedDomainsValidator';
import { URI } from 'vs/base/common/uri';
suite('Link protection domain matching', () => {
function linkProtectedByRules(link: string, rules: string[]) {
assert.ok(isURLDomainTrusted(URI.parse(link), rules));
}
function linkNotProtectedByRules(link: string, rules: string[]) {
assert.ok(!isURLDomainTrusted(URI.parse(link), rules));
}
suite('Link protection domain matching', () => {
test('simple', () => {
assert.ok(!isURLDomainTrusted(URI.parse('https://x.org'), []));
assert.ok(isURLDomainTrusted(URI.parse('https://x.org'), ['https://x.org']));
assert.ok(isURLDomainTrusted(URI.parse('https://x.org/foo'), ['https://x.org']));
linkNotProtectedByRules('https://x.org', []);
linkProtectedByRules('https://x.org', ['https://x.org']);
linkProtectedByRules('https://x.org/foo', ['https://x.org']);
assert.ok(!isURLDomainTrusted(URI.parse('https://x.org'), ['http://x.org']));
assert.ok(!isURLDomainTrusted(URI.parse('http://x.org'), ['https://x.org']));
linkNotProtectedByRules('https://x.org', ['http://x.org']);
linkNotProtectedByRules('http://x.org', ['https://x.org']);
assert.ok(!isURLDomainTrusted(URI.parse('https://www.x.org'), ['https://x.org']));
linkNotProtectedByRules('https://www.x.org', ['https://x.org']);
assert.ok(isURLDomainTrusted(URI.parse('https://www.x.org'), ['https://www.x.org', 'https://y.org']));
linkProtectedByRules('https://www.x.org', ['https://www.x.org', 'https://y.org']);
});
test('localhost', () => {
assert.ok(isURLDomainTrusted(URI.parse('https://127.0.0.1'), []));
assert.ok(isURLDomainTrusted(URI.parse('https://127.0.0.1:3000'), []));
assert.ok(isURLDomainTrusted(URI.parse('https://localhost'), []));
assert.ok(isURLDomainTrusted(URI.parse('https://localhost:3000'), []));
linkProtectedByRules('https://127.0.0.1', []);
linkProtectedByRules('https://127.0.0.1:3000', []);
linkProtectedByRules('https://localhost', []);
linkProtectedByRules('https://localhost:3000', []);
});
test('* star', () => {
assert.ok(isURLDomainTrusted(URI.parse('https://a.x.org'), ['https://*.x.org']));
assert.ok(isURLDomainTrusted(URI.parse('https://a.b.x.org'), ['https://*.x.org']));
assert.ok(isURLDomainTrusted(URI.parse('https://a.x.org'), ['https://a.x.*']));
assert.ok(isURLDomainTrusted(URI.parse('https://a.x.org'), ['https://a.*.org']));
assert.ok(isURLDomainTrusted(URI.parse('https://a.x.org'), ['https://*.*.org']));
assert.ok(isURLDomainTrusted(URI.parse('https://a.b.x.org'), ['https://*.b.*.org']));
assert.ok(isURLDomainTrusted(URI.parse('https://a.a.b.x.org'), ['https://*.b.*.org']));
linkProtectedByRules('https://a.x.org', ['https://*.x.org']);
linkProtectedByRules('https://a.b.x.org', ['https://*.x.org']);
linkProtectedByRules('https://a.x.org', ['https://a.x.*']);
linkProtectedByRules('https://a.x.org', ['https://a.*.org']);
linkProtectedByRules('https://a.x.org', ['https://*.*.org']);
linkProtectedByRules('https://a.b.x.org', ['https://*.b.*.org']);
linkProtectedByRules('https://a.a.b.x.org', ['https://*.b.*.org']);
});
test('no scheme', () => {
assert.ok(isURLDomainTrusted(URI.parse('https://a.x.org'), ['a.x.org']));
assert.ok(isURLDomainTrusted(URI.parse('https://a.x.org'), ['*.x.org']));
assert.ok(isURLDomainTrusted(URI.parse('https://a.b.x.org'), ['*.x.org']));
assert.ok(isURLDomainTrusted(URI.parse('https://x.org'), ['*.x.org']));
linkProtectedByRules('https://a.x.org', ['a.x.org']);
linkProtectedByRules('https://a.x.org', ['*.x.org']);
linkProtectedByRules('https://a.b.x.org', ['*.x.org']);
linkProtectedByRules('https://x.org', ['*.x.org']);
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册