screenshotone-validations
Version:
Validation schemes for the ScreenshotOne API requests.
85 lines (84 loc) • 5.82 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const globals_1 = require("@jest/globals");
const main_1 = __importDefault(require("./main"));
(0, globals_1.describe)("URL validations", () => {
(0, globals_1.test)("https://https://example.com must be invalid", async () => {
const { error } = main_1.default.take.getScheme.validate({ url: "https://https://example.com" }, main_1.default.take.validationOptions);
(0, globals_1.expect)(error).toBeDefined();
});
(0, globals_1.test)("http://https://example.com must be invalid", async () => {
const { error } = main_1.default.take.getScheme.validate({ url: "http://https://example.com" }, main_1.default.take.validationOptions);
(0, globals_1.expect)(error).toBeDefined();
});
(0, globals_1.test)("https:// must be invalid", async () => {
const { error } = main_1.default.take.getScheme.validate({ url: "https://" }, main_1.default.take.validationOptions);
(0, globals_1.expect)(error).toBeDefined();
});
(0, globals_1.test)("https://example.com must be valid", async () => {
const { error, value } = main_1.default.take.getScheme.validate({ url: "https://example.com" }, main_1.default.take.validationOptions);
(0, globals_1.expect)(error).toBeUndefined();
});
(0, globals_1.test)("https://example.com:80 must be valid", async () => {
const { error, value } = main_1.default.take.getScheme.validate({ url: "https://example.com:80" }, main_1.default.take.validationOptions);
(0, globals_1.expect)(error).toBeUndefined();
});
(0, globals_1.test)("https://1.1.1.1:80 must be valid", async () => {
const { error, value } = main_1.default.take.getScheme.validate({ url: "https://1.1.1.1:80" }, main_1.default.take.validationOptions);
(0, globals_1.expect)(error).toBeUndefined();
});
(0, globals_1.test)("https://1.1.1.1 must be valid", async () => {
const { error, value } = main_1.default.take.getScheme.validate({ url: "https://1.1.1.1" }, main_1.default.take.validationOptions);
(0, globals_1.expect)(error).toBeUndefined();
});
(0, globals_1.test)("proxy with http://example.com must be valid", async () => {
const { error, value } = main_1.default.take.getScheme.validate({ proxy: "http://example.com", url: "https://example.com" }, main_1.default.take.validationOptions);
(0, globals_1.expect)(error).toBeUndefined();
});
(0, globals_1.test)("proxy with http://example.com:8080 must be valid", async () => {
const { error, value } = main_1.default.take.getScheme.validate({ proxy: "http://example.com:8080", url: "https://example.com" }, main_1.default.take.validationOptions);
(0, globals_1.expect)(error).toBeUndefined();
});
(0, globals_1.test)("proxy with http://1.1.1.1 must be valid", async () => {
const { error, value } = main_1.default.take.getScheme.validate({ proxy: "http://1.1.1.1", url: "https://example.com" }, main_1.default.take.validationOptions);
(0, globals_1.expect)(error).toBeUndefined();
});
(0, globals_1.test)("proxy with http://1.1.1.1:8080 must be valid", async () => {
const { error, value } = main_1.default.take.getScheme.validate({ proxy: "http://1.1.1.1:8080", url: "https://example.com" }, main_1.default.take.validationOptions);
(0, globals_1.expect)(error).toBeUndefined();
});
(0, globals_1.test)("proxy with https://example.com must be invalid", async () => {
const { error } = main_1.default.take.getScheme.validate({ proxy: "https://example.com", url: "https://example.com" }, main_1.default.take.validationOptions);
(0, globals_1.expect)(error).toBeDefined();
});
(0, globals_1.test)("proxy with invalid URL must be invalid", async () => {
const { error } = main_1.default.take.getScheme.validate({ proxy: "not-a-url", url: "https://example.com" }, main_1.default.take.validationOptions);
(0, globals_1.expect)(error).toBeDefined();
});
(0, globals_1.test)("proxy with auth credentials must be valid", async () => {
const { error, value } = main_1.default.take.getScheme.validate({
proxy: "http://user:pass@example.com:8080",
url: "https://example.com",
}, main_1.default.take.validationOptions);
(0, globals_1.expect)(() => new URL(value.proxy)).not.toThrow();
(0, globals_1.expect)(error).toBeUndefined();
});
(0, globals_1.test)("proxy with unicode characters should be valid", async () => {
const { error, value } = main_1.default.take.getScheme.validate({ proxy: "http://münchen.de", url: "https://example.com" }, main_1.default.take.validationOptions);
(0, globals_1.expect)(() => new URL(value.proxy)).not.toThrow();
(0, globals_1.expect)(error).toBeUndefined();
});
(0, globals_1.test)("proxy with spaces should not be valid", async () => {
const { error, value } = main_1.default.take.getScheme.validate({ proxy: "http://proxy server.com", url: "https://example.com" }, main_1.default.take.validationOptions);
(0, globals_1.expect)(() => new URL(value.proxy)).toThrow();
(0, globals_1.expect)(error).toBeDefined();
});
(0, globals_1.test)("proxy with unescaped brackets must invalid", async () => {
const { error, value } = main_1.default.take.getScheme.validate({ proxy: "http://proxy[1].com", url: "https://example.com" }, main_1.default.take.validationOptions);
(0, globals_1.expect)(() => new URL(value.proxy)).toThrow();
(0, globals_1.expect)(error).toBeDefined();
});
});