diff --git a/src/schema.mjs b/src/schema.mjs index a0049a7..248b01e 100644 --- a/src/schema.mjs +++ b/src/schema.mjs @@ -24,7 +24,7 @@ export const https = { url: { type: "string", format: "uri", - pattern: "https://", + pattern: "^(https|http)://", }, method: { type: "string" }, body: { type: "string" }, @@ -61,7 +61,7 @@ export const graphql = { url: { type: "string", format: "uri", - pattern: "^https://", + pattern: "^(https|http)://", }, body: { type: "string" }, headers: { type: "object" }, @@ -101,7 +101,7 @@ export const jsonrpc = { url: { type: "string", format: "uri", - pattern: "^https://", + pattern: "^(https|http)://", }, }, required: ["url"], @@ -149,7 +149,7 @@ export const ipfs = { gateway: { type: "string", format: "uri", - pattern: "^https?://[^/]+/(ip[fn]s)/", + pattern: "^(https|http)?://[^/]+/(ip[fn]s)/", $comment: "Must equate to a regular IPFS path gateway. We had initially considered supporting subdomain gateways too, but a lack of expressing their URIs generically lead us ignore their support.", }, @@ -195,7 +195,7 @@ export const arweave = { gateway: { type: "string", format: "uri", - pattern: "^https://", + pattern: "^(https|http)://", }, headers: { type: "object" }, }, diff --git a/test/schema_test.mjs b/test/schema_test.mjs index 853cfff..77806a8 100644 --- a/test/schema_test.mjs +++ b/test/schema_test.mjs @@ -20,6 +20,9 @@ import { crawlPath, ipfs, arweave, + graphql, + jsonrpc, + https, } from "../src/schema.mjs"; const ajv = new Ajv(); @@ -388,7 +391,7 @@ test.skip("if crawl path validator throws if transformer.args[0] isn't a string" t.is(check.errors[0].message, "must be string"); }); -test("should be a valid ipfs message", async (t) => { +test("should be a valid ipfs message", (t) => { const check = ajv.compile(ipfs); const message = { options: { @@ -404,7 +407,7 @@ test("should be a valid ipfs message", async (t) => { t.true(valid); }); -test("ipfs gateway is a https url", async (t) => { +test("ipfs gateway is a https url", (t) => { const check = ajv.compile(ipfs); const message = { options: { @@ -421,7 +424,7 @@ test("ipfs gateway is a https url", async (t) => { t.true(check.errors[0].instancePath.includes("/options/gateway")); }); -test("ipfs message url should end with ipfs/", async (t) => { +test("ipfs message url should end with ipfs/", (t) => { const check = ajv.compile(ipfs); const message = { options: { @@ -438,7 +441,7 @@ test("ipfs message url should end with ipfs/", async (t) => { t.true(check.errors[0].instancePath.includes("/options/gateway")); }); -test("should be a valid arweave message", async (t) => { +test("should be a valid arweave message", (t) => { const check = ajv.compile(arweave); const message = { options: { @@ -454,7 +457,7 @@ test("should be a valid arweave message", async (t) => { t.true(valid); }); -test("arweave gateway should be a https url", async (t) => { +test("arweave gateway should be a https url", (t) => { const check = ajv.compile(arweave); const message = { options: { @@ -469,3 +472,75 @@ test("arweave gateway should be a https url", async (t) => { const invalid = check(message); t.falsy(invalid); }); + +test("that all worker messages allow local (gateway) uris starting with 'http'", (t) => { + const c1 = ajv.compile(arweave); + const m1 = { + options: { + uri: "ar://ltmVC0dpe7_KxFHj0-S7mdvXSfmcJOec4_OfjwSzLRk/1", + gateway: "http://localhost", + }, + version: "1.0.0", + type: "arweave", + commissioner: "test", + }; + const r1 = c1(m1); + t.true(r1); + + const c2 = ajv.compile(ipfs); + const m2 = { + options: { + uri: "ipfs://Qme7ss3ARVgxv6rXqVPiikMJ8u2NLgmgszg13pYrDKEoiu", + gateway: "http://localhost/ipfs/", + }, + version: "1.0.0", + type: "ipfs", + commissioner: "test", + }; + + const r2 = c2(m2); + t.true(r2); + + const c3 = ajv.compile(graphql); + const m3 = { + options: { + url: "http://localhost", + body: "abc", + }, + version: "1.0.0", + type: "graphql", + commissioner: "test", + }; + + const r3 = c3(m3); + t.true(r3); + + const c4 = ajv.compile(https); + const m4 = { + options: { + url: "http://localhost", + method: "GET", + }, + version: "1.0.0", + type: "https", + commissioner: "test", + }; + + const r4 = c4(m4); + t.true(r4); + + const c5 = ajv.compile(jsonrpc); + const m5 = { + options: { + url: "http://localhost", + }, + method: "eth_call", + version: "1.0.0", + type: "json-rpc", + params: [], + commissioner: "test", + }; + + const r5 = c5(m5); + t.true(r5); +});