Make URL parsing more robust

This commit is contained in:
Robert Brignull 2020-09-28 18:28:46 +01:00
parent 2841489ddf
commit c4dc1b0438
9 changed files with 179 additions and 47 deletions

View file

@ -122,3 +122,63 @@ test("getExtraOptionsEnvParam() fails on invalid JSON", (t) => {
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;
});
test("parseGithubUrl", (t) => {
t.deepEqual(util.parseGithubUrl("github.com"), "https://github.com/");
t.deepEqual(util.parseGithubUrl("https://github.com"), "https://github.com/");
t.deepEqual(
util.parseGithubUrl("https://api.github.com"),
"https://github.com/"
);
t.deepEqual(
util.parseGithubUrl("https://github.com/foo/bar"),
"https://github.com/"
);
t.deepEqual(
util.parseGithubUrl("github.example.com"),
"https://github.example.com/"
);
t.deepEqual(
util.parseGithubUrl("https://github.example.com"),
"https://github.example.com/"
);
t.deepEqual(
util.parseGithubUrl("https://api.github.example.com"),
"https://github.example.com/"
);
t.deepEqual(
util.parseGithubUrl("https://github.example.com/api/v3"),
"https://github.example.com/"
);
t.deepEqual(
util.parseGithubUrl("https://github.example.com:1234"),
"https://github.example.com:1234/"
);
t.deepEqual(
util.parseGithubUrl("https://api.github.example.com:1234"),
"https://github.example.com:1234/"
);
t.deepEqual(
util.parseGithubUrl("https://github.example.com:1234/api/v3"),
"https://github.example.com:1234/"
);
t.deepEqual(
util.parseGithubUrl("https://github.example.com/base/path"),
"https://github.example.com/base/path/"
);
t.deepEqual(
util.parseGithubUrl("https://github.example.com/base/path/api/v3"),
"https://github.example.com/base/path/"
);
t.throws(() => util.parseGithubUrl(""), {
message: '"" is not a valid URL',
});
t.throws(() => util.parseGithubUrl("ssh://github.com"), {
message: '"ssh://github.com" is not a http or https URL',
});
t.throws(() => util.parseGithubUrl("http:///::::433"), {
message: '"http:///::::433" is not a valid URL',
});
});