Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dns resolution tests #97

Merged
merged 5 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading