[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:
Wyatt Johnson
2019-08-12 18:02:15 +00:00
committed by GitHub
parent c245e9ba74
commit 86bba73919
20 changed files with 158 additions and 162 deletions
@@ -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();
});
});
+24 -1
View File
@@ -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.