mirror of
https://github.com/wassname/talk.git
synced 2026-09-12 13:01:11 +08:00
[CORL-513] Permitted Domain Fixes (#2455)
* fix: adjusted allowed domains configuration * fix: removed unused logic around allowed domains prefixing * fix: removed unused localizations * fix: fixed signup flow
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { createValidator } from "./validation";
|
||||
import { createValidator, validateStrictURLList } from "./validation";
|
||||
|
||||
describe("createValidator", () => {
|
||||
it("should report error when condition is unmet", () => {
|
||||
@@ -10,3 +10,25 @@ describe("createValidator", () => {
|
||||
expect(truthy(true, {})).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe("validateStrictURLList", () => {
|
||||
it("should reject a URL without a scheme", () => {
|
||||
expect(validateStrictURLList(["localhost"], {})).toBeDefined();
|
||||
});
|
||||
|
||||
it("should reject multiple URLs without a scheme", () => {
|
||||
expect(
|
||||
validateStrictURLList(["http://localhost", "localhost"], {})
|
||||
).toBeDefined();
|
||||
});
|
||||
|
||||
it("should allow a URL with a scheme", () => {
|
||||
expect(validateStrictURLList(["http://localhost"], {})).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should allow multiple URLs with a scheme", () => {
|
||||
expect(
|
||||
validateStrictURLList(["http://localhost", "https://localhost"], {})
|
||||
).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -58,7 +58,8 @@ export function composeValidators<T = any, V = any>(
|
||||
* required is a Validator that checks that the value is truthy.
|
||||
*/
|
||||
export const required = createValidator(
|
||||
v => v !== "" && v !== null && v !== undefined,
|
||||
v =>
|
||||
Array.isArray(v) ? v.length > 0 : v !== "" && v !== null && v !== undefined,
|
||||
VALIDATION_REQUIRED()
|
||||
);
|
||||
|
||||
@@ -217,6 +218,28 @@ export const validatePercentage = (min: number, max: number) =>
|
||||
NOT_A_WHOLE_NUMBER_BETWEEN(min * 100, max * 100)
|
||||
);
|
||||
|
||||
export const validateStrictURLList = createValidator(v => {
|
||||
if (!Array.isArray(v)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const url of v) {
|
||||
if (typeof url !== "string") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!URL_REGEX.test(url)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!url.startsWith("http")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}, INVALID_URL());
|
||||
|
||||
/**
|
||||
* Condition represents a given check that can be performed for the purpose of
|
||||
* filtering a validation operation.
|
||||
|
||||
Reference in New Issue
Block a user