From e47aa9cbb9f832ad29117446c460c2ef38984662 Mon Sep 17 00:00:00 2001 From: Joseph Turner Date: Sat, 2 Sep 2023 20:53:31 -0700 Subject: [PATCH 1/5] Move blog.mauve.moe magic constant into DNS_DOMAIN variable --- test.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test.js b/test.js index 1cb8af2..5a1784f 100755 --- a/test.js +++ b/test.js @@ -7,6 +7,7 @@ import { once } from 'events' import makeHyperFetch from './index.js' const SAMPLE_CONTENT = 'Hello World' +const DNS_DOMAIN = 'blog.mauve.moe' let count = 0 function next () { return count++ @@ -498,7 +499,7 @@ test('EventSource extension messages', async (t) => { }) test('Resolve DNS', async (t) => { - const loadResponse = await fetch('hyper://blog.mauve.moe/?noResolve') + const loadResponse = await fetch(`hyper://${DNS_DOMAIN}/?noResolve`) const entries = await loadResponse.json() @@ -614,7 +615,7 @@ test('Handle empty string pathname', async (t) => { }) test('Return status 403 Forbidden on attempt to modify read-only hyperdrive', async (t) => { - const readOnlyURL = 'hyper://blog.mauve.moe/new-file.txt' + const readOnlyURL = `hyper://${DNS_DOMAIN}/new-file.txt` const putResponse = await fetch(readOnlyURL, { method: 'PUT', body: SAMPLE_CONTENT }) if (putResponse.ok) { throw new Error('PUT file to read-only drive should have failed') @@ -633,7 +634,7 @@ test('Return status 403 Forbidden on attempt to modify read-only hyperdrive', as test('Check hyperdrive writability', async (t) => { const created = await nextURL(t) - const readOnlyRootDirectory = 'hyper://blog.mauve.moe/?noResolve' + const readOnlyRootDirectory = `hyper://${DNS_DOMAIN}/?noResolve` const readOnlyHeadResponse = await fetch(readOnlyRootDirectory, { method: 'HEAD' }) await checkResponse(readOnlyHeadResponse, t, 'Able to load HEAD') const readOnlyHeadersAllow = readOnlyHeadResponse.headers.get('Allow') From 1151aa2d4f5530869ad8494734cafe20337df29e Mon Sep 17 00:00:00 2001 From: Joseph Turner Date: Sat, 2 Sep 2023 21:07:24 -0700 Subject: [PATCH 2/5] Test that resolved links from DNS domains load the same content Currently, this test hangs. --- test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test.js b/test.js index 5a1784f..24768a2 100755 --- a/test.js +++ b/test.js @@ -504,6 +504,12 @@ test('Resolve DNS', async (t) => { const entries = await loadResponse.json() t.ok(entries.length, 'Loaded contents with some files present') + + const rawLink = loadResponse.headers.get('Link').match(/<(.+)>/)[1] + const loadRawURLResponse = await fetch(rawLink) + + const rawLinkEntries = await loadRawURLResponse.json() + t.deepEqual(rawLinkEntries, entries, 'Raw link resolves to same content as DNS domain.') }) test('Doing a `GET` on an invalid domain/public key should cause an error', async (t) => { From 6ae88d0b1a99dd1447767f5a78b4d8be17071d55 Mon Sep 17 00:00:00 2001 From: Joseph Turner Date: Sat, 2 Sep 2023 21:19:31 -0700 Subject: [PATCH 3/5] (delete me) Add comment logging drive before failure --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index f5f0948..92e0a90 100755 --- a/index.js +++ b/index.js @@ -160,6 +160,7 @@ export default async function makeHyperFetch ({ const corestore = sdk.namespace(core.id) const drive = new Hyperdrive(corestore, core.key) + console.log('drive', drive) await drive.ready() From fcf9f545b5c814f90237ea29ca17baebc10e6472 Mon Sep 17 00:00:00 2001 From: Mauve Signweaver Date: Wed, 22 Nov 2023 16:02:24 -0500 Subject: [PATCH 4/5] Fix hyperdrive not getting cached by key url --- index.js | 2 +- test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 92e0a90..2e2b4ca 100755 --- a/index.js +++ b/index.js @@ -160,7 +160,6 @@ export default async function makeHyperFetch ({ const corestore = sdk.namespace(core.id) const drive = new Hyperdrive(corestore, core.key) - console.log('drive', drive) await drive.ready() @@ -170,6 +169,7 @@ export default async function makeHyperFetch ({ }) drives.set(drive.core.id, drive) + drives.set(drive.core.url, drive) drives.set(hostname, drive) return drive diff --git a/test.js b/test.js index 24768a2..b5e603c 100755 --- a/test.js +++ b/test.js @@ -498,7 +498,7 @@ test('EventSource extension messages', async (t) => { t.ok(lastEventId, 'Event contained peer ID') }) -test('Resolve DNS', async (t) => { +test.only('Resolve DNS', async (t) => { const loadResponse = await fetch(`hyper://${DNS_DOMAIN}/?noResolve`) const entries = await loadResponse.json() @@ -506,7 +506,7 @@ test('Resolve DNS', async (t) => { t.ok(entries.length, 'Loaded contents with some files present') const rawLink = loadResponse.headers.get('Link').match(/<(.+)>/)[1] - const loadRawURLResponse = await fetch(rawLink) + const loadRawURLResponse = await fetch(rawLink + '?noResolve') const rawLinkEntries = await loadRawURLResponse.json() t.deepEqual(rawLinkEntries, entries, 'Raw link resolves to same content as DNS domain.') From d7da77649f4d27582f6100d4054413efc7049eb0 Mon Sep 17 00:00:00 2001 From: Mauve Signweaver Date: Wed, 22 Nov 2023 16:05:02 -0500 Subject: [PATCH 5/5] Re-enable all tests --- test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.js b/test.js index b5e603c..ea8ab6e 100755 --- a/test.js +++ b/test.js @@ -498,7 +498,7 @@ test('EventSource extension messages', async (t) => { t.ok(lastEventId, 'Event contained peer ID') }) -test.only('Resolve DNS', async (t) => { +test('Resolve DNS', async (t) => { const loadResponse = await fetch(`hyper://${DNS_DOMAIN}/?noResolve`) const entries = await loadResponse.json()