From 5576c223ce7a5fb7ace0745a54668e6f0c91d053 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 27 Jan 2021 13:27:41 +0100 Subject: [PATCH 1/3] fix hns links redirects --- docker/nginx/conf.d/client.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/nginx/conf.d/client.conf b/docker/nginx/conf.d/client.conf index db69542f..276b8872 100644 --- a/docker/nginx/conf.d/client.conf +++ b/docker/nginx/conf.d/client.conf @@ -212,7 +212,7 @@ server { end ngx.var.skylink = skylink - if request_uri_rest == "/" and skylink_rest ~= "" and skylink_rest ~= "/" then + if request_uri_rest == "/" and skylink_rest ~= nil and skylink_rest ~= "" and skylink_rest ~= "/" then ngx.var.rest = skylink_rest else ngx.var.rest = request_uri_rest From 203ff0fd849e0d5d7f071ea9ef5acf57dfe51835 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 27 Jan 2021 13:39:00 +0100 Subject: [PATCH 2/3] ensure skylink_rest is local --- docker/nginx/conf.d/client.conf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker/nginx/conf.d/client.conf b/docker/nginx/conf.d/client.conf index 276b8872..8376067d 100644 --- a/docker/nginx/conf.d/client.conf +++ b/docker/nginx/conf.d/client.conf @@ -176,6 +176,9 @@ server { -- example response: '{"skylink":"sia://XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg"}' local hnsres_json = json.decode(hnsres_res.body) + -- define local variable containing rest of the skylink if provided + local skylink_rest + if hnsres_json.skylink then -- try to match the skylink with sia:// prefix skylink, skylink_rest = string.match(hnsres_json.skylink, "sia://([^/?]+)(.*)") From a002b21dacb7003d2668175bb10c0bc3a0121352 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 27 Jan 2021 15:11:03 +0100 Subject: [PATCH 3/3] add handshake redirect test --- packages/health-check/src/checks/verbose.js | 39 +++++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/packages/health-check/src/checks/verbose.js b/packages/health-check/src/checks/verbose.js index e7143fed..235ab8de 100644 --- a/packages/health-check/src/checks/verbose.js +++ b/packages/health-check/src/checks/verbose.js @@ -1024,6 +1024,20 @@ function fileEndpointCheck(done) { skylinkVerification(done, linkInfo); } +// check whether hns/note-to-self would properly redirect to note-to-self/ +function hnsEndpointDirectoryRedirect(done) { + const expected = { + name: "hns endpoint directory redirect", + skylink: "hns/note-to-self", + statusCode: 307, + headers: { + location: "note-to-self/", + }, + }; + + skylinkVerification(done, expected, { redirects: 0 }); +} + function parseHeaderString(header) { try { return JSON.parse(header); @@ -1033,26 +1047,36 @@ function parseHeaderString(header) { } // skylinkVerification verifies a skylink against provided information. -function skylinkVerification(done, { name, skylink, bodyHash, headers }) { +function skylinkVerification(done, { name, skylink, bodyHash, headers, statusCode }, { redirects } = {}) { const time = process.hrtime(); // Create the query for the skylink - const query = `${process.env.PORTAL_URL}/${skylink}?nocache=true`; + const query = `${process.env.PORTAL_URL}/${skylink}`; // Get the Skylink superagent .get(query) + .set("cookie", "nocache=true") + .redirects(redirects) + .ok((res) => (redirects === undefined ? res.ok : res.status < 400)) .responseType("blob") .then( (response) => { const entry = { name, up: true, statusCode: response.statusCode, time: calculateElapsedTime(time) }; const info = {}; - // Check if the response body is valid by checking against the known hash - const currentBodyHash = hash(response.body); - if (currentBodyHash !== bodyHash) { + if (statusCode && statusCode !== response.statusCode) { entry.up = false; - info.bodyHash = { expected: bodyHash, current: currentBodyHash }; + info.statusCode = { expected: statusCode, current: response.statusCode }; + } + + // Check if the response body is valid by checking against the known hash + if (bodyHash) { + const currentBodyHash = hash(response.body); + if (currentBodyHash !== bodyHash) { + entry.up = false; + info.bodyHash = { expected: bodyHash, current: currentBodyHash }; + } } if (headers) { @@ -1065,7 +1089,7 @@ function skylinkVerification(done, { name, skylink, bodyHash, headers }) { if (typeof currentHeader === "object") { info.headers[headerName] = ensureValidJSON(detailedDiff(expectedHeader, currentHeader)); } else { - info.headers[headerName] = currentHeader; + info.headers[headerName] = { expected: expectedHeader, current: currentHeader }; } } }); @@ -1118,4 +1142,5 @@ module.exports = [ // uniswapHNSRedirectCheck, uniswapHNSResolverCheck, uniswapHNSResolverRedirectCheck, + hnsEndpointDirectoryRedirect, ];