
* validateAllowSaleorUrls impl * Implement in handler and add test * update codeowners * Apply suggestions from code review Co-authored-by: Krzysztof Wolski <krzysztof.k.wolski@gmail.com> * Rename param Co-authored-by: Krzysztof Wolski <krzysztof.k.wolski@gmail.com>
42 lines
1.6 KiB
TypeScript
42 lines
1.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { validateAllowSaleorUrls } from "./validate-allow-saleor-urls";
|
|
|
|
const saleorCloudUrlMock = "https://my-shop.saleor.cloud/graphql/";
|
|
const onPremiseSaleorUrlMock = "https://my-shop-123.aws-services.com/graphql/";
|
|
|
|
const saleorCloudRegexValidator = (url: string) => /https:\/\/.*.saleor.cloud\/graphql\//.test(url);
|
|
|
|
describe("validateAllowSaleorUrls", () => {
|
|
it("Passes any URL if allow list is empty", () => {
|
|
expect(validateAllowSaleorUrls(saleorCloudUrlMock, [])).toBe(true);
|
|
expect(validateAllowSaleorUrls(onPremiseSaleorUrlMock, [])).toBe(true);
|
|
});
|
|
|
|
it("Passes only for URL that was exactly matched in provided allow list array", () => {
|
|
expect(validateAllowSaleorUrls(saleorCloudUrlMock, [saleorCloudUrlMock])).toBe(true);
|
|
expect(validateAllowSaleorUrls(onPremiseSaleorUrlMock, [saleorCloudUrlMock])).toBe(false);
|
|
});
|
|
|
|
it("Validates against custom function provided to allow list", () => {
|
|
expect(validateAllowSaleorUrls(saleorCloudUrlMock, [saleorCloudRegexValidator])).toBe(true);
|
|
expect(validateAllowSaleorUrls(onPremiseSaleorUrlMock, [saleorCloudRegexValidator])).toBe(
|
|
false
|
|
);
|
|
});
|
|
|
|
it("Validates against more than one argument in allow list", () => {
|
|
expect(
|
|
validateAllowSaleorUrls(saleorCloudUrlMock, [
|
|
saleorCloudRegexValidator,
|
|
onPremiseSaleorUrlMock,
|
|
])
|
|
).toBe(true);
|
|
expect(
|
|
validateAllowSaleorUrls(onPremiseSaleorUrlMock, [
|
|
saleorCloudRegexValidator,
|
|
onPremiseSaleorUrlMock,
|
|
])
|
|
).toBe(true);
|
|
});
|
|
});
|