Skip to content

Commit

Permalink
Allow local "http" in worker messages
Browse files Browse the repository at this point in the history
- Fixes #56
  • Loading branch information
TimDaub committed Oct 24, 2022
1 parent cb73865 commit 43c45a3
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const https = {
url: {
type: "string",
format: "uri",
pattern: "https://",
pattern: "^(https|http)://",
},
method: { type: "string" },
body: { type: "string" },
Expand Down Expand Up @@ -61,7 +61,7 @@ export const graphql = {
url: {
type: "string",
format: "uri",
pattern: "^https://",
pattern: "^(https|http)://",
},
body: { type: "string" },
headers: { type: "object" },
Expand Down Expand Up @@ -101,7 +101,7 @@ export const jsonrpc = {
url: {
type: "string",
format: "uri",
pattern: "^https://",
pattern: "^(https|http)://",
},
},
required: ["url"],
Expand Down Expand Up @@ -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.",
},
Expand Down Expand Up @@ -195,7 +195,7 @@ export const arweave = {
gateway: {
type: "string",
format: "uri",
pattern: "^https://",
pattern: "^(https|http)://",
},
headers: { type: "object" },
},
Expand Down
85 changes: 80 additions & 5 deletions test/schema_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import {
crawlPath,
ipfs,
arweave,
graphql,
jsonrpc,
https,
} from "../src/schema.mjs";

const ajv = new Ajv();
Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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);
});

0 comments on commit 43c45a3

Please sign in to comment.