2020-03-23 15:35:58 +01:00
|
|
|
/*
|
|
|
|
|
* MIT License
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
import * as validator from "./validation";
|
2018-09-03 16:17:36 +02:00
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
describe("test name validation", () => {
|
2019-09-12 11:29:42 +02:00
|
|
|
// invalid names taken from ValidationUtilTest.java
|
|
|
|
|
const invalidNames = [
|
2019-10-20 16:59:02 +02:00
|
|
|
"@test",
|
|
|
|
|
" test 123",
|
|
|
|
|
" test 123 ",
|
|
|
|
|
"test 123 ",
|
|
|
|
|
"test/123",
|
|
|
|
|
"test:123",
|
|
|
|
|
"t ",
|
|
|
|
|
" t",
|
|
|
|
|
" t ",
|
|
|
|
|
"",
|
|
|
|
|
" invalid_name",
|
2021-03-25 09:59:23 +01:00
|
|
|
"%",
|
|
|
|
|
"test%name",
|
|
|
|
|
"test\\name"
|
2019-09-12 11:29:42 +02:00
|
|
|
];
|
2019-10-21 10:57:56 +02:00
|
|
|
for (const name of invalidNames) {
|
2019-09-12 11:29:42 +02:00
|
|
|
it(`should return false for '${name}'`, () => {
|
2018-09-03 16:17:36 +02:00
|
|
|
expect(validator.isNameValid(name)).toBe(false);
|
2019-09-12 11:29:42 +02:00
|
|
|
});
|
|
|
|
|
}
|
2018-09-03 16:17:36 +02:00
|
|
|
|
2019-09-12 11:29:42 +02:00
|
|
|
// valid names taken from ValidationUtilTest.java
|
|
|
|
|
const validNames = [
|
2019-10-20 16:59:02 +02:00
|
|
|
"test",
|
2021-03-25 09:59:23 +01:00
|
|
|
"test git",
|
2019-10-20 16:59:02 +02:00
|
|
|
"test.git",
|
|
|
|
|
"Test123.git",
|
|
|
|
|
"Test123-git",
|
|
|
|
|
"Test_user-123.git",
|
|
|
|
|
"test@scm-manager.de",
|
|
|
|
|
"test123",
|
|
|
|
|
"tt",
|
|
|
|
|
"t",
|
|
|
|
|
"valid_name",
|
|
|
|
|
"another1",
|
|
|
|
|
"stillValid",
|
|
|
|
|
"this.one_as-well",
|
2021-03-25 09:59:23 +01:00
|
|
|
"and@this",
|
|
|
|
|
"Лорем-ипсум",
|
|
|
|
|
"Λορεμ.ιπσθμ",
|
|
|
|
|
"լոռեմիպսում",
|
|
|
|
|
"ლორემიფსუმ",
|
|
|
|
|
"प्रमान",
|
|
|
|
|
"詳性約",
|
|
|
|
|
"隠サレニ",
|
|
|
|
|
"법률",
|
|
|
|
|
"المدن",
|
|
|
|
|
"אחד",
|
|
|
|
|
"Hu-rëm"
|
2019-09-12 11:29:42 +02:00
|
|
|
];
|
2019-10-21 10:57:56 +02:00
|
|
|
for (const name of validNames) {
|
2019-09-12 11:29:42 +02:00
|
|
|
it(`should return true for '${name}'`, () => {
|
2018-09-03 16:17:36 +02:00
|
|
|
expect(validator.isNameValid(name)).toBe(true);
|
2019-09-12 11:29:42 +02:00
|
|
|
});
|
|
|
|
|
}
|
2018-09-03 16:17:36 +02:00
|
|
|
});
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
describe("test mail validation", () => {
|
2019-09-12 11:29:42 +02:00
|
|
|
// invalid taken from ValidationUtilTest.java
|
|
|
|
|
const invalid = [
|
2019-10-20 16:59:02 +02:00
|
|
|
"ostfalia.de",
|
|
|
|
|
"@ostfalia.de",
|
|
|
|
|
"s.sdorra@",
|
|
|
|
|
"s.sdorra@ostfalia",
|
|
|
|
|
"s.sdorra@ ostfalia.de",
|
|
|
|
|
"s.sdorra@[ostfalia.de"
|
2019-09-12 11:29:42 +02:00
|
|
|
];
|
2019-10-21 10:57:56 +02:00
|
|
|
for (const mail of invalid) {
|
2019-09-12 11:29:42 +02:00
|
|
|
it(`should return false for '${mail}'`, () => {
|
2018-09-03 16:17:36 +02:00
|
|
|
expect(validator.isMailValid(mail)).toBe(false);
|
2019-09-12 11:29:42 +02:00
|
|
|
});
|
|
|
|
|
}
|
2018-09-03 16:17:36 +02:00
|
|
|
|
2019-09-12 11:29:42 +02:00
|
|
|
// valid taken from ValidationUtilTest.java
|
|
|
|
|
const valid = [
|
2019-10-20 16:59:02 +02:00
|
|
|
"s.sdorra@ostfalia.de",
|
|
|
|
|
"sdorra@ostfalia.de",
|
|
|
|
|
"s.sdorra@hbk-bs.de",
|
|
|
|
|
"s.sdorra@gmail.com",
|
|
|
|
|
"s.sdorra@t.co",
|
|
|
|
|
"s.sdorra@ucla.college",
|
|
|
|
|
"s.sdorra@example.xn--p1ai",
|
|
|
|
|
"s.sdorra@scm.solutions",
|
2019-09-12 11:29:42 +02:00
|
|
|
"s'sdorra@scm.solutions",
|
2019-10-20 16:59:02 +02:00
|
|
|
'"S Sdorra"@scm.solutions'
|
2019-09-12 11:29:42 +02:00
|
|
|
];
|
2019-10-21 10:57:56 +02:00
|
|
|
for (const mail of valid) {
|
2019-09-12 11:29:42 +02:00
|
|
|
it(`should return true for '${mail}'`, () => {
|
2018-09-03 16:17:36 +02:00
|
|
|
expect(validator.isMailValid(mail)).toBe(true);
|
2019-09-12 11:29:42 +02:00
|
|
|
});
|
|
|
|
|
}
|
2018-09-03 16:17:36 +02:00
|
|
|
});
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
describe("test number validation", () => {
|
|
|
|
|
const invalid = ["1a", "35gu", "dj6", "45,5", "test"];
|
2019-10-21 10:57:56 +02:00
|
|
|
for (const number of invalid) {
|
2019-09-12 11:29:42 +02:00
|
|
|
it(`should return false for '${number}'`, () => {
|
2019-10-19 16:38:07 +02:00
|
|
|
expect(validator.isNumberValid(number)).toBe(false);
|
2019-09-12 11:29:42 +02:00
|
|
|
});
|
|
|
|
|
}
|
2019-10-20 16:59:02 +02:00
|
|
|
const valid = ["1", "35", "2", "235", "34.4"];
|
2019-10-21 10:57:56 +02:00
|
|
|
for (const number of valid) {
|
2019-09-12 11:29:42 +02:00
|
|
|
it(`should return true for '${number}'`, () => {
|
2018-09-03 16:17:36 +02:00
|
|
|
expect(validator.isNumberValid(number)).toBe(true);
|
2019-09-12 11:29:42 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
describe("test path validation", () => {
|
2021-03-25 12:50:24 +01:00
|
|
|
const invalid = ["//", "some//path", "end//", ".", "..", "../"];
|
2019-10-21 10:57:56 +02:00
|
|
|
for (const path of invalid) {
|
2019-09-12 11:29:42 +02:00
|
|
|
it(`should return false for '${path}'`, () => {
|
2019-09-12 11:39:04 +02:00
|
|
|
expect(validator.isPathValid(path)).toBe(false);
|
2019-09-12 11:29:42 +02:00
|
|
|
});
|
|
|
|
|
}
|
2019-10-20 16:59:02 +02:00
|
|
|
const valid = ["", "/", "dir", "some/path", "end/"];
|
2019-10-21 10:57:56 +02:00
|
|
|
for (const path of valid) {
|
2019-09-12 11:29:42 +02:00
|
|
|
it(`should return true for '${path}'`, () => {
|
2019-09-12 11:39:04 +02:00
|
|
|
expect(validator.isPathValid(path)).toBe(true);
|
2019-09-12 11:29:42 +02:00
|
|
|
});
|
|
|
|
|
}
|
2018-09-03 16:17:36 +02:00
|
|
|
});
|
2020-12-02 10:42:26 +01:00
|
|
|
|
|
|
|
|
describe("test url validation", () => {
|
|
|
|
|
const invalid = [
|
|
|
|
|
"http://",
|
|
|
|
|
"http://.",
|
|
|
|
|
"http://..",
|
|
|
|
|
"http://../",
|
|
|
|
|
"http://?",
|
|
|
|
|
"http://??",
|
|
|
|
|
"http://??/",
|
|
|
|
|
"http://#",
|
|
|
|
|
"http://##",
|
|
|
|
|
"http://##/",
|
|
|
|
|
"http://foo.bar?q=Spaces should be encoded",
|
|
|
|
|
"//",
|
|
|
|
|
"//a",
|
|
|
|
|
"///a",
|
|
|
|
|
"///",
|
|
|
|
|
"foo.com",
|
|
|
|
|
"http:// shouldfail.com",
|
|
|
|
|
":// should fail",
|
|
|
|
|
"http://foo.bar/foo(bar)baz quux",
|
|
|
|
|
"http://.www.foo.bar/",
|
|
|
|
|
"http://.www.foo.bar./"
|
|
|
|
|
];
|
|
|
|
|
for (const url of invalid) {
|
|
|
|
|
it(`should return false for '${url}'`, () => {
|
|
|
|
|
expect(validator.isUrlValid(url)).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
const valid = [
|
2020-12-03 09:47:41 +01:00
|
|
|
"ftps://foo.bar/",
|
|
|
|
|
"h://test",
|
|
|
|
|
"rdar://1234",
|
|
|
|
|
"file:///blah/index.html",
|
2020-12-02 10:42:26 +01:00
|
|
|
"https://foo.com/blah_blah",
|
2020-12-03 08:54:56 +01:00
|
|
|
"ssh://foo.com/blah_blah",
|
2020-12-02 10:42:26 +01:00
|
|
|
"https://foo.com/blah_blah/",
|
|
|
|
|
"https://foo.com/blah_blah_(wikipedia)",
|
|
|
|
|
"https://foo.com/blah_blah_(wikipedia)_(again)",
|
|
|
|
|
"http://www.example.com/wpstyle/?p=364",
|
|
|
|
|
"http://foo.com/blah_blah",
|
|
|
|
|
"http://foo.com/blah_blah/",
|
|
|
|
|
"http://foo.com/blah_blah_(wikipedia)",
|
|
|
|
|
"http://foo.com/blah_blah_(wikipedia)_(again)",
|
|
|
|
|
"http://www.example.com/wpstyle/?p=364",
|
|
|
|
|
"https://www.example.com/foo/?bar=baz&inga=42&quux",
|
|
|
|
|
"http://✪df.ws/123",
|
|
|
|
|
"http://userid:password@example.com:8080",
|
|
|
|
|
"http://userid:password@example.com:8080/",
|
|
|
|
|
"http://userid@example.com",
|
|
|
|
|
"http://userid@example.com/",
|
|
|
|
|
"http://userid@example.com:8080",
|
|
|
|
|
"http://userid@example.com:8080/",
|
|
|
|
|
"http://userid:password@example.com",
|
|
|
|
|
"http://userid:password@example.com/",
|
|
|
|
|
"http://142.42.1.1/",
|
|
|
|
|
"http://142.42.1.1:8080/",
|
|
|
|
|
"http://➡.ws/䨹",
|
|
|
|
|
"http://⌘.ws",
|
|
|
|
|
"http://⌘.ws/",
|
|
|
|
|
"http://foo.com/blah_(wikipedia)#cite-1",
|
|
|
|
|
"http://foo.com/blah_(wikipedia)_blah#cite-1",
|
|
|
|
|
"http://foo.com/unicode_(✪)_in_parens",
|
|
|
|
|
"http://foo.com/(something)?after=parens",
|
|
|
|
|
"http://☺.damowmow.com/",
|
|
|
|
|
"http://code.google.com/events/#&product=browser",
|
|
|
|
|
"http://j.mp",
|
|
|
|
|
"http://foo.bar/?q=Test%20URL-encoded%20stuff",
|
|
|
|
|
"http://مثال.إختبار",
|
|
|
|
|
"http://例子.测试",
|
|
|
|
|
"http://उदाहरण.परीक्षा",
|
|
|
|
|
"http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com",
|
|
|
|
|
"http://1337.net",
|
|
|
|
|
"http://a.b-c.de",
|
|
|
|
|
"http://223.255.255.254",
|
|
|
|
|
"http://0.0.0.0"
|
|
|
|
|
];
|
|
|
|
|
for (const url of valid) {
|
|
|
|
|
it(`should return true for '${url}'`, () => {
|
|
|
|
|
expect(validator.isUrlValid(url)).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-03-25 12:50:24 +01:00
|
|
|
|
|
|
|
|
describe("test filename validation", () => {
|
|
|
|
|
const invalid = ["", "/", "some/file", ".", "..", "../", "\\", "\\name", "file:some"];
|
|
|
|
|
for (const filename of invalid) {
|
|
|
|
|
it(`should return false for '${filename}'`, () => {
|
|
|
|
|
expect(validator.isFilenameValid(filename)).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
const valid = ["a", "test", "some_file", "end.txt", ".gitignore"];
|
|
|
|
|
for (const filename of valid) {
|
|
|
|
|
it(`should return true for '${filename}'`, () => {
|
|
|
|
|
expect(validator.isFilenameValid(filename)).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|