Skip to content

Commit

Permalink
Merge pull request #97 from josephmturner/dns-resolution
Browse files Browse the repository at this point in the history
Dns resolution tests
  • Loading branch information
RangerMauve authored Nov 22, 2023
2 parents 6766d08 + d7da776 commit 4bc29c2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,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
Expand Down
13 changes: 10 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down Expand Up @@ -498,11 +499,17 @@ 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()

t.ok(entries.length, 'Loaded contents with some files present')

const rawLink = loadResponse.headers.get('Link').match(/<(.+)>/)[1]
const loadRawURLResponse = await fetch(rawLink + '?noResolve')

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) => {
Expand Down Expand Up @@ -614,7 +621,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')
Expand All @@ -633,7 +640,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')
Expand Down

0 comments on commit 4bc29c2

Please sign in to comment.