From a452899a0dd1f86809c5889c8900244f0f7be107 Mon Sep 17 00:00:00 2001 From: makeworld Date: Wed, 27 Apr 2022 10:45:17 -0400 Subject: [PATCH 01/12] Update README and fix existing tests --- README.md | 26 +++++++++------ mutable-tests.js | 86 +++++++++++++++++++++++------------------------- 2 files changed, 58 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index ba0ed95..6083ee8 100644 --- a/README.md +++ b/README.md @@ -31,17 +31,23 @@ Progress: https://github.com/ipfs/community/discussions/573 - [x] Render empty directories - [x] Resolve `index.html` in a path - `mutable.html` Tests (experimental, some things subject to change) - - [x] JS `fetch('ipfs://CID/example.txt', {method: 'POST'})` - - [x] JS `fetch('ipns://CID/', {method: 'POST'})` - - [x] JS `fetch('ipns://CID/example.txt', {method: 'POST'})` - - [x] JS `fetch('ipfs://CID/', {method: 'POST', body: new FormData})` - - [x] JS `fetch('ipfs://CID/example.txt', {method: 'DELETE'})` - - [x] JS `fetch('ipns://CID/example.txt', {method: 'DELETE'})` + - [x] JS `fetch('ipfs:///example.txt', {method: 'PUT'})` + - [x] JS `fetch('ipfs:///', {method: 'PUT', body: new FormData})` + - [x] JS `fetch('ipfs:///example.txt', {method: 'DELETE'})` + - [x] JS `fetch('ipns://localhost?key=', {method: 'POST', body: })` + - [ ] JS `fetch('ipns://localhost/example.txt?key=', {method: 'POST', body: })` + - [ ] JS `fetch('ipns://', {method: 'POST', body: })` + - [ ] JS `fetch('ipns:///example.txt', {method: 'POST', body: })` + - [ ] JS `fetch('ipns://localhost?key=', {method: 'PUT', body: file or formdata})` + - [ ] JS `fetch('ipns://localhost/example.txt?key=', {method: 'PUT', body: file or formdata})` + - [ ] JS `fetch('ipns://', {method: 'PUT', body: file or formdata})` + - [ ] JS `fetch('ipns:///example.txt', {method: 'PUT', body: file or formdata})` + - [ ] JS `fetch('ipns:///example.txt', {method: 'DELETE'})` - `dag.html` Tests (experimental, some things subject to change) - - [x] GET `ipfs://CID/?format=CAR` - - [x] GET `ipfs://CID/?format=block` - - [x] GET `ipfs://CID/?format=dag-json` - - [x] GET `ipfs://CID/?format=dag-cbor` + - [x] GET `ipfs:///?format=CAR` + - [x] GET `ipfs:///?format=block` + - [x] GET `ipfs:///?format=dag-json` + - [x] GET `ipfs:///?format=dag-cbor` - [x] POST `Content-Type: application/json` `?format=dag-cbor` & GET `?format=dag-cbor` - [x] POST over existing CID to add to graph diff --git a/mutable-tests.js b/mutable-tests.js index ec75b0f..ca41980 100644 --- a/mutable-tests.js +++ b/mutable-tests.js @@ -12,14 +12,14 @@ const OTHER_TEST_FILE_NAME = 'example2.txt' const EMPTY_DIR_URL = 'ipfs://bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354/' promise_test(async (t) => { - const postResponse = await fetch(`ipfs://${TEST_FILE_NAME}`, { - method: 'POST', + const putResponse = await fetch(`${EMPTY_DIR_URL}/${TEST_FILE_NAME}`, { + method: 'PUT', body: TEST_FILE_CONTENT }) - assert_true(postResponse.ok, 'Able to POST') + assert_true(putResponse.status == 201, 'Able to PUT') - const url = await postResponse.text() + const url = await putResponse.url assert_true(url.startsWith('ipfs://'), 'Got an IPFS url for the content') assert_true(url.endsWith(TEST_FILE_NAME), 'URL ends with the file name') @@ -39,26 +39,26 @@ promise_test(async (t) => { const listing = await listingRequest.text() assert_true(listing.includes(TEST_FILE_NAME), 'File shows up in parent folder') -}, 'POST text file to IPFS without infohash') +}, 'PUT text file to IPFS inside empty dir') promise_test(async (t) => { - const firstFileResponse = await fetch(`ipfs://${TEST_FILE_NAME}`, { - method: 'POST', + const firstFileResponse = await fetch(`${EMPTY_DIR_URL}/${TEST_FILE_NAME}`, { + method: 'PUT', body: TEST_FILE_CONTENT }) - assert_true(firstFileResponse.ok, 'Able to post first file') + assert_true(firstFileResponse.status == 201, 'Able to PUT first file') - const url = await firstFileResponse.text() + const url = await firstFileResponse.url const base = new URL('./', url).href const secondFileResponse = await fetch(new URL(`./${OTHER_TEST_FILE_NAME}`, base).href, { - method: 'POST', + method: 'PUT', body: OTHER_TEST_FILE_CONTENT }) - assert_true(secondFileResponse.ok, 'Able to post second file') + assert_true(secondFileResponse.status == 201, 'Able to post second file') const secondUrl = await secondFileResponse.text() @@ -73,28 +73,28 @@ promise_test(async (t) => { assert_true(listing.includes(TEST_FILE_NAME), 'First file shows up in parent folder') assert_true(listing.includes(OTHER_TEST_FILE_NAME), 'Second file shows up in parent folder') -}, 'POST text file to existing infohash') +}, 'PUT text file to existing infohash') promise_test(async (t) => { - const firstFileResponse = await fetch(`ipfs://${TEST_FILE_NAME}`, { - method: 'POST', + const firstFileResponse = await fetch(`${EMPTY_DIR_URL}/${TEST_FILE_NAME}`, { + method: 'PUT', body: TEST_FILE_CONTENT }) - assert_true(firstFileResponse.ok, 'Able to post first file') + assert_true(firstFileResponse.status == 201, 'Able to PUT first file') - const url = await firstFileResponse.text() + const url = await firstFileResponse.url const base = new URL('./', url).href const secondFileResponse = await fetch(new URL(`./${OTHER_TEST_FILE_NAME}`, base).href, { - method: 'POST', + method: 'PUT', body: OTHER_TEST_FILE_CONTENT }) - assert_true(secondFileResponse.ok, 'Able to post second file') + assert_true(secondFileResponse.status == 201, 'Able to PUT second file') - const secondUrl = await secondFileResponse.text() + const secondUrl = await secondFileResponse.url const secondBase = new URL('./', secondUrl).href @@ -109,9 +109,9 @@ promise_test(async (t) => { method: 'DELETE' }) - assert_true(deleteResponse.ok, 'Able to DELETE file URL') + assert_true(deleteResponse.status == 201, 'Able to DELETE file URL') - const finalUrl = await deleteResponse.text() + const finalUrl = await deleteResponse.url assert_true(finalUrl.startsWith('ipfs://'), 'Got an IPFS url for the content') assert_true(finalUrl.endsWith('/'), 'URL ends with a / to signify a directory') @@ -125,25 +125,25 @@ promise_test(async (t) => { }, 'DELETE file from an infohash') promise_test(async (t) => { - const firstFileResponse = await fetch(`ipfs://${TEST_FILE_NAME}`, { - method: 'POST', + const firstFileResponse = await fetch(`${EMPTY_DIR_URL}/${TEST_FILE_NAME}`, { + method: 'PUT', body: TEST_FILE_CONTENT }) - assert_true(firstFileResponse.ok, 'Able to post first file') + assert_true(firstFileResponse.status == 201, 'Able to post first file') - const url = await firstFileResponse.text() + const url = await firstFileResponse.url const base = new URL('./', url).href - const ipnsResponse = await fetch('ipns://compliance-suite-example/', { + const ipnsResponse = await fetch('ipns://localhost?key=compliance-suite-example', { method: 'POST', body: base }) - assert_true(ipnsResponse.ok, 'Able to POST url to ipns') + assert_true(ipnsResponse.status == 301, 'Able to POST url to ipns') - const ipnsUrl = await ipnsResponse.text() + const ipnsUrl = await ipnsResponse.url assert_true(ipnsUrl.startsWith('ipns://'), 'Got an IPNS URL') assert_true(ipnsUrl.endsWith('/'), 'Ends as a directory') @@ -163,14 +163,14 @@ promise_test(async (t) => { formData.append('file', new Blob([TEST_FILE_CONTENT]), TEST_FILE_NAME) formData.append('file', new Blob([OTHER_TEST_FILE_CONTENT]), OTHER_TEST_FILE_NAME) - const postResponse = await fetch(EMPTY_DIR_URL, { - method: 'POST', + const putResponse = await fetch(EMPTY_DIR_URL, { + method: 'PUT', body: formData }) - assert_true(postResponse.ok, 'Able to POST') + assert_true(putResponse.status == 201, 'Able to PUT') - const url = await postResponse.text() + const url = await putResponse.url assert_true(url.startsWith('ipfs://'), 'Got an IPFS url for the content') assert_true(url.endsWith('/'), 'URL is a directory') @@ -189,30 +189,28 @@ promise_test(async (t) => { assert_true(listing.includes(TEST_FILE_NAME), 'File shows up in parent folder') assert_true(listing.includes(OTHER_TEST_FILE_NAME), 'Other file shows up in parent folder') -}, 'POST FormData with files to IPFS') +}, 'PUT FormData with files to IPFS') promise_test(async (t) => { - const firstFileResponse = await fetch(`ipfs://${TEST_FILE_NAME}`, { - method: 'POST', + const firstFileResponse = await fetch(`${EMPTY_DIR_URL}/${TEST_FILE_NAME}`, { + method: 'PUT', body: TEST_FILE_CONTENT }) - assert_true(firstFileResponse.ok, 'Able to post first file') + assert_true(firstFileResponse.status == 201, 'Able to PUT first file') - const url = await firstFileResponse.text() + const url = await firstFileResponse.url const base = new URL('./', url).href - // Note that the key pet name is a temporary measure - // This should be replaced with public keys once a key generation standard is figured out - const ipnsResponse = await fetch('ipns://compliance-suite-example2/', { + const ipnsResponse = await fetch('ipns://localhost?key=compliance-suite-example2', { method: 'POST', body: base }) - assert_true(ipnsResponse.ok, 'Able to POST url to ipns') + assert_true(ipnsResponse.status == 301, 'Able to POST url to ipns') - const ipnsUrl = await ipnsResponse.text() + const ipnsUrl = await ipnsResponse.url const otherFileURL = new URL(`/${OTHER_TEST_FILE_NAME}`, ipnsUrl) @@ -221,7 +219,7 @@ promise_test(async (t) => { body: OTHER_TEST_FILE_CONTENT }) - assert_true(secondFileResponse.ok, 'Able to POST file to existing IPNS path') + assert_true(secondFileResponse.status == 301, 'Able to POST url to existing IPNS path') const listingRequest = await fetch(ipnsUrl) @@ -231,4 +229,4 @@ promise_test(async (t) => { assert_true(listing.includes(TEST_FILE_NAME), 'First file shows up in IPNS folder') assert_true(listing.includes(OTHER_TEST_FILE_NAME), 'Second file shows up in IPNS folder') -}, 'POST text file to IPNS with existing data') +}, 'POST url to IPNS with existing data') From 1c2b23b31edd30ac65ca8dbba1eb7e7da1ca2608 Mon Sep 17 00:00:00 2001 From: makeworld Date: Wed, 27 Apr 2022 11:24:21 -0400 Subject: [PATCH 02/12] Add remaining mutable tests --- README.md | 14 ++-- mutable-tests.js | 171 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 170 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 6083ee8..cbabe79 100644 --- a/README.md +++ b/README.md @@ -35,14 +35,12 @@ Progress: https://github.com/ipfs/community/discussions/573 - [x] JS `fetch('ipfs:///', {method: 'PUT', body: new FormData})` - [x] JS `fetch('ipfs:///example.txt', {method: 'DELETE'})` - [x] JS `fetch('ipns://localhost?key=', {method: 'POST', body: })` - - [ ] JS `fetch('ipns://localhost/example.txt?key=', {method: 'POST', body: })` - - [ ] JS `fetch('ipns://', {method: 'POST', body: })` - - [ ] JS `fetch('ipns:///example.txt', {method: 'POST', body: })` - - [ ] JS `fetch('ipns://localhost?key=', {method: 'PUT', body: file or formdata})` - - [ ] JS `fetch('ipns://localhost/example.txt?key=', {method: 'PUT', body: file or formdata})` - - [ ] JS `fetch('ipns://', {method: 'PUT', body: file or formdata})` - - [ ] JS `fetch('ipns:///example.txt', {method: 'PUT', body: file or formdata})` - - [ ] JS `fetch('ipns:///example.txt', {method: 'DELETE'})` + - [x] JS `fetch('ipns://localhost/example.txt?key=', {method: 'POST', body: })` + - [x] JS `fetch('ipns://localhost?key=', {method: 'PUT', body: file})` + - [x] JS `fetch('ipns://localhost/example?key=', {method: 'PUT', body: file})` + - [x] JS `fetch('ipns://localhost?key=', {method: 'PUT', body: formdata})` + - [x] JS `fetch('ipns://localhost/example?key=', {method: 'PUT', body: formdata})` + - [x] JS `fetch('ipns:///example.txt', {method: 'DELETE'})` - `dag.html` Tests (experimental, some things subject to change) - [x] GET `ipfs:///?format=CAR` - [x] GET `ipfs:///?format=block` diff --git a/mutable-tests.js b/mutable-tests.js index ca41980..d41bc1f 100644 --- a/mutable-tests.js +++ b/mutable-tests.js @@ -124,6 +124,54 @@ promise_test(async (t) => { assert_true(!finalListing.includes(OTHER_TEST_FILE_NAME), 'Second file no longer shows up in folder') }, 'DELETE file from an infohash') +promise_test(async (t) => { + const firstFileResponse = await fetch(`ipns://localhost?key=compliance-suite-example6/${TEST_FILE_NAME}`, { + method: 'PUT', + body: TEST_FILE_CONTENT + }) + + assert_true(firstFileResponse.status == 301, 'Able to PUT first file') + + const url = await firstFileResponse.url + + const base = new URL('./', url).href + + const secondFileResponse = await fetch(new URL(`./${OTHER_TEST_FILE_NAME}`, base).href, { + method: 'PUT', + body: OTHER_TEST_FILE_CONTENT + }) + + assert_true(secondFileResponse.status == 301, 'Able to PUT second file') + + const secondUrl = await secondFileResponse.url + + const secondBase = new URL('./', secondUrl).href + + const listingRequest = await fetch(secondBase) + + const listing = await listingRequest.text() + + assert_true(listing.includes(TEST_FILE_NAME), 'First file shows up in parent folder') + assert_true(listing.includes(OTHER_TEST_FILE_NAME), 'Second file shows up in parent folder') + + const deleteResponse = await fetch(secondUrl, { + method: 'DELETE' + }) + + assert_true(deleteResponse.status == 301, 'Able to DELETE file URL') + + const finalUrl = await deleteResponse.url + + assert_true(finalUrl.startsWith('ipns://'), 'Got an IPNS url for the content') + + const finalListingRequest = await fetch(finalUrl) + + const finalListing = await finalListingRequest.text() + + assert_true(finalListing.includes(TEST_FILE_NAME), 'First file still shows up in folder') + assert_true(!finalListing.includes(OTHER_TEST_FILE_NAME), 'Second file no longer shows up in folder') +}, 'DELETE file from IPNS') + promise_test(async (t) => { const firstFileResponse = await fetch(`${EMPTY_DIR_URL}/${TEST_FILE_NAME}`, { method: 'PUT', @@ -146,17 +194,126 @@ promise_test(async (t) => { const ipnsUrl = await ipnsResponse.url assert_true(ipnsUrl.startsWith('ipns://'), 'Got an IPNS URL') - assert_true(ipnsUrl.endsWith('/'), 'Ends as a directory') - const listingRequest = await fetch(ipnsUrl) + const getResponse = await fetch(ipnsUrl) - assert_true(listingRequest.ok, 'Able to GET from IPNS') + assert_true(getResponse.ok, 'Able to use URL from POST') - const listing = await listingRequest.text() + const text = await getResponse.text() - assert_true(listing.includes(TEST_FILE_NAME), 'File shows up in IPNS folder') + assert_equals(text, TEST_FILE_CONTENT, 'Got content back out') }, 'POST IPFS URL to IPNS') +promise_test(async (t) => { + const ipnsResponse = await fetch('ipns://localhost?key=compliance-suite-example2', { + method: 'PUT', + body: TEST_FILE_CONTENT + }) + + assert_true(ipnsResponse.status == 301, 'Able to POST url to ipns') + + const ipnsUrl = await ipnsResponse.url + + assert_true(ipnsUrl.startsWith('ipns://'), 'Got an IPNS URL') + + const getResponse = await fetch(ipnsUrl) + + assert_true(getResponse.ok, 'Able to use URL from POST') + + const text = await getResponse.text() + + assert_equals(text, TEST_FILE_CONTENT, 'Got content back out') +}, 'PUT IPFS file to IPNS') + +promise_test(async (t) => { + const ipnsResponse = await fetch('ipns://localhost/test?key=compliance-suite-example3', { + method: 'PUT', + body: TEST_FILE_CONTENT + }) + + assert_true(ipnsResponse.status == 301, 'Able to POST url to ipns') + + const ipnsUrl = await ipnsResponse.url + + assert_true(ipnsUrl.startsWith('ipns://'), 'Got an IPNS URL') + + const getResponse = await fetch(ipnsUrl) + + assert_true(getResponse.ok, 'Able to use URL from POST') + + const text = await getResponse.text() + + assert_equals(text, TEST_FILE_CONTENT, 'Got content back out') +}, 'PUT IPFS file to IPNS subpath') + +promise_test(async (t) => { + const formData = new FormData() + + formData.append('file', new Blob([TEST_FILE_CONTENT]), TEST_FILE_NAME) + formData.append('file', new Blob([OTHER_TEST_FILE_CONTENT]), OTHER_TEST_FILE_NAME) + + const putResponse = await fetch('ipns://localhost?key=compliance-suite-example5', { + method: 'PUT', + body: formData + }) + + assert_true(putResponse.status == 201, 'Able to PUT') + + const url = putResponse.url + + assert_true(url.startsWith('ipns://'), 'Got an IPNS url for the content') + assert_true(url.endsWith('/'), 'URL is a directory') + + const getResponse = await fetch(url + TEST_FILE_NAME) + + assert_true(getResponse.ok, 'Able to use URL from POST') + + const text = await getResponse.text() + + assert_equals(text, TEST_FILE_CONTENT, 'Got content back out') + + const listingRequest = await fetch(url) + + const listing = await listingRequest.text() + + assert_true(listing.includes(TEST_FILE_NAME), 'File shows up in parent folder') + assert_true(listing.includes(OTHER_TEST_FILE_NAME), 'Other file shows up in parent folder') +}, 'PUT FormData to IPNS') + +promise_test(async (t) => { + const formData = new FormData() + + formData.append('file', new Blob([TEST_FILE_CONTENT]), TEST_FILE_NAME) + formData.append('file', new Blob([OTHER_TEST_FILE_CONTENT]), OTHER_TEST_FILE_NAME) + + const putResponse = await fetch('ipns://localhost/test?key=compliance-suite-example5', { + method: 'PUT', + body: formData + }) + + assert_true(putResponse.status == 201, 'Able to PUT') + + const url = putResponse.url + + assert_true(url.startsWith('ipns://'), 'Got an IPNS url for the content') + assert_true(url.endsWith('/'), 'URL is a directory') + + const getResponse = await fetch(url + TEST_FILE_NAME) + + assert_true(getResponse.ok, 'Able to use URL from POST') + + const text = await getResponse.text() + + assert_equals(text, TEST_FILE_CONTENT, 'Got content back out') + + const listingRequest = await fetch(url) + + const listing = await listingRequest.text() + + assert_true(listing.includes(TEST_FILE_NAME), 'File shows up in parent folder') + assert_true(listing.includes(OTHER_TEST_FILE_NAME), 'Other file shows up in parent folder') +}, 'PUT FormData to IPNS subpath') + promise_test(async (t) => { const formData = new FormData() @@ -203,14 +360,14 @@ promise_test(async (t) => { const base = new URL('./', url).href - const ipnsResponse = await fetch('ipns://localhost?key=compliance-suite-example2', { + const ipnsResponse = await fetch(`ipns://localhost?key=compliance-suite-example4/${TEST_FILE_NAME}`, { method: 'POST', body: base }) assert_true(ipnsResponse.status == 301, 'Able to POST url to ipns') - const ipnsUrl = await ipnsResponse.url + const ipnsUrl = new URL('../', ipnsResponse.url) const otherFileURL = new URL(`/${OTHER_TEST_FILE_NAME}`, ipnsUrl) From 21eb5ec2b98c5904c119a037b10497cd5b69bdb1 Mon Sep 17 00:00:00 2001 From: makeworld Date: Wed, 11 May 2022 10:40:03 -0400 Subject: [PATCH 03/12] Update for spec changes (IPNS key API) --- README.md | 28 ++++++++------- mutable-tests.js | 92 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 100 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index cbabe79..33d1027 100644 --- a/README.md +++ b/README.md @@ -34,20 +34,22 @@ Progress: https://github.com/ipfs/community/discussions/573 - [x] JS `fetch('ipfs:///example.txt', {method: 'PUT'})` - [x] JS `fetch('ipfs:///', {method: 'PUT', body: new FormData})` - [x] JS `fetch('ipfs:///example.txt', {method: 'DELETE'})` - - [x] JS `fetch('ipns://localhost?key=', {method: 'POST', body: })` - - [x] JS `fetch('ipns://localhost/example.txt?key=', {method: 'POST', body: })` - - [x] JS `fetch('ipns://localhost?key=', {method: 'PUT', body: file})` - - [x] JS `fetch('ipns://localhost/example?key=', {method: 'PUT', body: file})` - - [x] JS `fetch('ipns://localhost?key=', {method: 'PUT', body: formdata})` - - [x] JS `fetch('ipns://localhost/example?key=', {method: 'PUT', body: formdata})` - - [x] JS `fetch('ipns:///example.txt', {method: 'DELETE'})` + - [x] JS `fetch('ipns://', {method: 'POST', body: })` + - [x] JS `fetch('ipns:///example.txt', {method: 'POST', body: })` + - [x] JS `fetch('ipns://', {method: 'PUT', body: file})` + - [x] JS `fetch('ipns:///example', {method: 'PUT', body: file})` + - [x] JS `fetch('ipns://', {method: 'PUT', body: formdata})` + - [x] JS `fetch('ipns:///example', {method: 'PUT', body: formdata})` + - [x] JS `fetch('ipns:///example.txt', {method: 'DELETE'})` + - [x] JS `fetch('ipns://localhost?key=', {method: 'GET})` + - [x] JS `fetch('ipns://localhost?key=', {method: 'DELETE})` - `dag.html` Tests (experimental, some things subject to change) - - [x] GET `ipfs:///?format=CAR` - - [x] GET `ipfs:///?format=block` - - [x] GET `ipfs:///?format=dag-json` - - [x] GET `ipfs:///?format=dag-cbor` - - [x] POST `Content-Type: application/json` `?format=dag-cbor` & GET `?format=dag-cbor` - - [x] POST over existing CID to add to graph + - [x] GET `ipfs:///?format=CAR` + - [x] GET `ipfs:///?format=block` + - [x] GET `ipfs:///?format=dag-json` + - [x] GET `ipfs:///?format=dag-cbor` + - [x] POST `Content-Type: application/json` `?format=dag-cbor` & GET `?format=dag-cbor` + - [x] POST over existing CID to add to graph ## Screenshots: diff --git a/mutable-tests.js b/mutable-tests.js index d41bc1f..29d2fd9 100644 --- a/mutable-tests.js +++ b/mutable-tests.js @@ -125,7 +125,13 @@ promise_test(async (t) => { }, 'DELETE file from an infohash') promise_test(async (t) => { - const firstFileResponse = await fetch(`ipns://localhost?key=compliance-suite-example6/${TEST_FILE_NAME}`, { + const createKey = await fetch(`ipns://localhost?key=compliance-suite-example6`, { + method: 'POST', + }) + assert_true(createKey.status == 201, 'Able to create key') + const keyURL = createKey.url + + const firstFileResponse = await fetch(`${keyURL}/${TEST_FILE_NAME}`, { method: 'PUT', body: TEST_FILE_CONTENT }) @@ -184,7 +190,13 @@ promise_test(async (t) => { const base = new URL('./', url).href - const ipnsResponse = await fetch('ipns://localhost?key=compliance-suite-example', { + const createKey = await fetch(`ipns://localhost?key=compliance-suite-example`, { + method: 'POST', + }) + assert_true(createKey.status == 201, 'Able to create key') + const keyURL = createKey.url + + const ipnsResponse = await fetch(keyURL, { method: 'POST', body: base }) @@ -205,7 +217,13 @@ promise_test(async (t) => { }, 'POST IPFS URL to IPNS') promise_test(async (t) => { - const ipnsResponse = await fetch('ipns://localhost?key=compliance-suite-example2', { + const createKey = await fetch(`ipns://localhost?key=compliance-suite-example2`, { + method: 'POST', + }) + assert_true(createKey.status == 201, 'Able to create key') + const keyURL = createKey.url + + const ipnsResponse = await fetch(keyURL, { method: 'PUT', body: TEST_FILE_CONTENT }) @@ -226,7 +244,13 @@ promise_test(async (t) => { }, 'PUT IPFS file to IPNS') promise_test(async (t) => { - const ipnsResponse = await fetch('ipns://localhost/test?key=compliance-suite-example3', { + const createKey = await fetch(`ipns://localhost?key=compliance-suite-example3`, { + method: 'POST', + }) + assert_true(createKey.status == 201, 'Able to create key') + const keyURL = createKey.url + + const ipnsResponse = await fetch(`${keyURL}/test`, { method: 'PUT', body: TEST_FILE_CONTENT }) @@ -252,7 +276,13 @@ promise_test(async (t) => { formData.append('file', new Blob([TEST_FILE_CONTENT]), TEST_FILE_NAME) formData.append('file', new Blob([OTHER_TEST_FILE_CONTENT]), OTHER_TEST_FILE_NAME) - const putResponse = await fetch('ipns://localhost?key=compliance-suite-example5', { + const createKey = await fetch(`ipns://localhost?key=compliance-suite-example5`, { + method: 'POST', + }) + assert_true(createKey.status == 201, 'Able to create key') + const keyURL = createKey.url + + const putResponse = await fetch(keyURL, { method: 'PUT', body: formData }) @@ -286,7 +316,13 @@ promise_test(async (t) => { formData.append('file', new Blob([TEST_FILE_CONTENT]), TEST_FILE_NAME) formData.append('file', new Blob([OTHER_TEST_FILE_CONTENT]), OTHER_TEST_FILE_NAME) - const putResponse = await fetch('ipns://localhost/test?key=compliance-suite-example5', { + const createKey = await fetch(`ipns://localhost?key=compliance-suite-example7`, { + method: 'POST', + }) + assert_true(createKey.status == 201, 'Able to create key') + const keyURL = createKey.url + + const putResponse = await fetch(`${keyURL}/test`, { method: 'PUT', body: formData }) @@ -360,7 +396,13 @@ promise_test(async (t) => { const base = new URL('./', url).href - const ipnsResponse = await fetch(`ipns://localhost?key=compliance-suite-example4/${TEST_FILE_NAME}`, { + const createKey = await fetch(`ipns://localhost?key=compliance-suite-example4`, { + method: 'POST', + }) + assert_true(createKey.status == 201, 'Able to create key') + const keyURL = createKey.url + + const ipnsResponse = await fetch(`${keyURL}/${TEST_FILE_NAME}`, { method: 'POST', body: base }) @@ -387,3 +429,39 @@ promise_test(async (t) => { assert_true(listing.includes(TEST_FILE_NAME), 'First file shows up in IPNS folder') assert_true(listing.includes(OTHER_TEST_FILE_NAME), 'Second file shows up in IPNS folder') }, 'POST url to IPNS with existing data') + +promise_test(async (t) => { + const getKey = await fetch(`ipns://localhost?key=compliance-suite-get-key`, { + method: 'GET', + }) + assert_true(getKey.status == 404, "key doesn't exist yet") + + const createKey = await fetch(`ipns://localhost?key=compliance-suite-get-key`, { + method: 'POST', + }) + assert_true(createKey.status == 201, 'Able to create key') + const keyURL = createKey.url + + const getKey2 = await fetch(`ipns://localhost?key=compliance-suite-get-key`, { + method: 'GET', + }) + assert_true(getKey2.status == 301, '301 redirect to key') + assert_true(getKey2.url == keyURL, 'redirected to correct key URL') +}, 'GET IPNS key') + +promise_test(async (t) => { + const createKey = await fetch(`ipns://localhost?key=compliance-suite-delete-key`, { + method: 'POST', + }) + assert_true(createKey.status == 201, 'Able to create key') + + const deleteKey = await fetch(`ipns://localhost?key=compliance-suite-delete-key`, { + method: 'DELETE', + }) + assert_true(deleteKey.status == 200, '200, deleted key') + + const getKey = await fetch(`ipns://localhost?key=compliance-suite-delete-key`, { + method: 'GET', + }) + assert_true(getKey.status == 404, "404, key doesn't exist") +}, 'DELETE IPNS key') From a888639f99c896c427c445733f821d98a8805a6d Mon Sep 17 00:00:00 2001 From: makeworld Date: Wed, 11 May 2022 12:26:02 -0400 Subject: [PATCH 04/12] Update for spec changes and errant URLs. Also .url won\ t get redirect url --- mutable-tests.js | 128 +++++++++++++++-------------------------------- 1 file changed, 41 insertions(+), 87 deletions(-) diff --git a/mutable-tests.js b/mutable-tests.js index 29d2fd9..7df8727 100644 --- a/mutable-tests.js +++ b/mutable-tests.js @@ -9,7 +9,7 @@ const TEST_FILE_CONTENT = 'Hello World' const TEST_FILE_NAME = 'example.txt' const OTHER_TEST_FILE_CONTENT = 'Goodby World' const OTHER_TEST_FILE_NAME = 'example2.txt' -const EMPTY_DIR_URL = 'ipfs://bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354/' +const EMPTY_DIR_URL = 'ipfs://bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354' promise_test(async (t) => { const putResponse = await fetch(`${EMPTY_DIR_URL}/${TEST_FILE_NAME}`, { @@ -19,7 +19,7 @@ promise_test(async (t) => { assert_true(putResponse.status == 201, 'Able to PUT') - const url = await putResponse.url + const url = await putResponse.headers.get("Location") assert_true(url.startsWith('ipfs://'), 'Got an IPFS url for the content') assert_true(url.endsWith(TEST_FILE_NAME), 'URL ends with the file name') @@ -49,7 +49,7 @@ promise_test(async (t) => { assert_true(firstFileResponse.status == 201, 'Able to PUT first file') - const url = await firstFileResponse.url + const url = await firstFileResponse.headers.get("Location") const base = new URL('./', url).href @@ -83,7 +83,7 @@ promise_test(async (t) => { assert_true(firstFileResponse.status == 201, 'Able to PUT first file') - const url = await firstFileResponse.url + const url = await firstFileResponse.headers.get("Location") const base = new URL('./', url).href @@ -94,7 +94,7 @@ promise_test(async (t) => { assert_true(secondFileResponse.status == 201, 'Able to PUT second file') - const secondUrl = await secondFileResponse.url + const secondUrl = await secondFileResponse.headers.get("Location") const secondBase = new URL('./', secondUrl).href @@ -111,7 +111,7 @@ promise_test(async (t) => { assert_true(deleteResponse.status == 201, 'Able to DELETE file URL') - const finalUrl = await deleteResponse.url + const finalUrl = await deleteResponse.headers.get("Location") assert_true(finalUrl.startsWith('ipfs://'), 'Got an IPFS url for the content') assert_true(finalUrl.endsWith('/'), 'URL ends with a / to signify a directory') @@ -129,31 +129,23 @@ promise_test(async (t) => { method: 'POST', }) assert_true(createKey.status == 201, 'Able to create key') - const keyURL = createKey.url + const keyURL = createKey.headers.get("Location") const firstFileResponse = await fetch(`${keyURL}/${TEST_FILE_NAME}`, { method: 'PUT', body: TEST_FILE_CONTENT }) + assert_true(firstFileResponse.status == 200, 'Able to PUT first file') - assert_true(firstFileResponse.status == 301, 'Able to PUT first file') - - const url = await firstFileResponse.url - - const base = new URL('./', url).href + const base = new URL('./', keyURL).href const secondFileResponse = await fetch(new URL(`./${OTHER_TEST_FILE_NAME}`, base).href, { method: 'PUT', body: OTHER_TEST_FILE_CONTENT }) + assert_true(secondFileResponse.status == 200, 'Able to PUT second file') - assert_true(secondFileResponse.status == 301, 'Able to PUT second file') - - const secondUrl = await secondFileResponse.url - - const secondBase = new URL('./', secondUrl).href - - const listingRequest = await fetch(secondBase) + const listingRequest = await fetch(base) const listing = await listingRequest.text() @@ -164,13 +156,9 @@ promise_test(async (t) => { method: 'DELETE' }) - assert_true(deleteResponse.status == 301, 'Able to DELETE file URL') + assert_true(deleteResponse.status == 200, 'Able to DELETE file URL') - const finalUrl = await deleteResponse.url - - assert_true(finalUrl.startsWith('ipns://'), 'Got an IPNS url for the content') - - const finalListingRequest = await fetch(finalUrl) + const finalListingRequest = await fetch(base) const finalListing = await finalListingRequest.text() @@ -186,7 +174,7 @@ promise_test(async (t) => { assert_true(firstFileResponse.status == 201, 'Able to post first file') - const url = await firstFileResponse.url + const url = await firstFileResponse.headers.get("Location") const base = new URL('./', url).href @@ -194,23 +182,16 @@ promise_test(async (t) => { method: 'POST', }) assert_true(createKey.status == 201, 'Able to create key') - const keyURL = createKey.url + const keyURL = createKey.headers.get("Location") const ipnsResponse = await fetch(keyURL, { method: 'POST', body: base }) - assert_true(ipnsResponse.status == 301, 'Able to POST url to ipns') - - const ipnsUrl = await ipnsResponse.url - - assert_true(ipnsUrl.startsWith('ipns://'), 'Got an IPNS URL') - - const getResponse = await fetch(ipnsUrl) - - assert_true(getResponse.ok, 'Able to use URL from POST') + assert_true(ipnsResponse.status == 200, 'Able to POST url to ipns') + const getResponse = await fetch(keyURL) const text = await getResponse.text() assert_equals(text, TEST_FILE_CONTENT, 'Got content back out') @@ -221,23 +202,16 @@ promise_test(async (t) => { method: 'POST', }) assert_true(createKey.status == 201, 'Able to create key') - const keyURL = createKey.url + const keyURL = createKey.headers.get("Location") const ipnsResponse = await fetch(keyURL, { method: 'PUT', body: TEST_FILE_CONTENT }) - assert_true(ipnsResponse.status == 301, 'Able to POST url to ipns') - - const ipnsUrl = await ipnsResponse.url - - assert_true(ipnsUrl.startsWith('ipns://'), 'Got an IPNS URL') - - const getResponse = await fetch(ipnsUrl) - - assert_true(getResponse.ok, 'Able to use URL from POST') + assert_true(ipnsResponse.status == 200, 'Able to POST url to ipns') + const getResponse = await fetch(keyURL) const text = await getResponse.text() assert_equals(text, TEST_FILE_CONTENT, 'Got content back out') @@ -248,23 +222,16 @@ promise_test(async (t) => { method: 'POST', }) assert_true(createKey.status == 201, 'Able to create key') - const keyURL = createKey.url + const keyURL = createKey.headers.get("Location") const ipnsResponse = await fetch(`${keyURL}/test`, { method: 'PUT', body: TEST_FILE_CONTENT }) - assert_true(ipnsResponse.status == 301, 'Able to POST url to ipns') - - const ipnsUrl = await ipnsResponse.url - - assert_true(ipnsUrl.startsWith('ipns://'), 'Got an IPNS URL') - - const getResponse = await fetch(ipnsUrl) - - assert_true(getResponse.ok, 'Able to use URL from POST') + assert_true(ipnsResponse.status == 200, 'Able to POST url to ipns') + const getResponse = await fetch(keyURL) const text = await getResponse.text() assert_equals(text, TEST_FILE_CONTENT, 'Got content back out') @@ -280,21 +247,16 @@ promise_test(async (t) => { method: 'POST', }) assert_true(createKey.status == 201, 'Able to create key') - const keyURL = createKey.url + const keyURL = createKey.headers.get("Location") const putResponse = await fetch(keyURL, { method: 'PUT', body: formData }) - assert_true(putResponse.status == 201, 'Able to PUT') - - const url = putResponse.url - - assert_true(url.startsWith('ipns://'), 'Got an IPNS url for the content') - assert_true(url.endsWith('/'), 'URL is a directory') + assert_true(putResponse.status == 200, 'Able to PUT') - const getResponse = await fetch(url + TEST_FILE_NAME) + const getResponse = await fetch(`${keyURL}/${TEST_FILE_NAME}`) assert_true(getResponse.ok, 'Able to use URL from POST') @@ -302,7 +264,7 @@ promise_test(async (t) => { assert_equals(text, TEST_FILE_CONTENT, 'Got content back out') - const listingRequest = await fetch(url) + const listingRequest = await fetch(keyURL) const listing = await listingRequest.text() @@ -320,21 +282,16 @@ promise_test(async (t) => { method: 'POST', }) assert_true(createKey.status == 201, 'Able to create key') - const keyURL = createKey.url + const keyURL = createKey.headers.get("Location") const putResponse = await fetch(`${keyURL}/test`, { method: 'PUT', body: formData }) - assert_true(putResponse.status == 201, 'Able to PUT') - - const url = putResponse.url - - assert_true(url.startsWith('ipns://'), 'Got an IPNS url for the content') - assert_true(url.endsWith('/'), 'URL is a directory') + assert_true(putResponse.status == 200, 'Able to PUT') - const getResponse = await fetch(url + TEST_FILE_NAME) + const getResponse = await fetch(`${keyURL}/${TEST_FILE_NAME}`) assert_true(getResponse.ok, 'Able to use URL from POST') @@ -342,7 +299,7 @@ promise_test(async (t) => { assert_equals(text, TEST_FILE_CONTENT, 'Got content back out') - const listingRequest = await fetch(url) + const listingRequest = await fetch(keyURL) const listing = await listingRequest.text() @@ -363,7 +320,7 @@ promise_test(async (t) => { assert_true(putResponse.status == 201, 'Able to PUT') - const url = await putResponse.url + const url = await putResponse.headers.get("Location") assert_true(url.startsWith('ipfs://'), 'Got an IPFS url for the content') assert_true(url.endsWith('/'), 'URL is a directory') @@ -392,7 +349,7 @@ promise_test(async (t) => { assert_true(firstFileResponse.status == 201, 'Able to PUT first file') - const url = await firstFileResponse.url + const url = await firstFileResponse.headers.get("Location") const base = new URL('./', url).href @@ -400,27 +357,23 @@ promise_test(async (t) => { method: 'POST', }) assert_true(createKey.status == 201, 'Able to create key') - const keyURL = createKey.url + const keyURL = createKey.headers.get("Location") const ipnsResponse = await fetch(`${keyURL}/${TEST_FILE_NAME}`, { method: 'POST', body: base }) - assert_true(ipnsResponse.status == 301, 'Able to POST url to ipns') - - const ipnsUrl = new URL('../', ipnsResponse.url) - - const otherFileURL = new URL(`/${OTHER_TEST_FILE_NAME}`, ipnsUrl) + assert_true(ipnsResponse.status == 200, 'Able to POST url to ipns') - const secondFileResponse = await fetch(otherFileURL, { + const secondFileResponse = await fetch(`${keyURL}/${OTHER_TEST_FILE_NAME}`, { method: 'POST', body: OTHER_TEST_FILE_CONTENT }) - assert_true(secondFileResponse.status == 301, 'Able to POST url to existing IPNS path') + assert_true(secondFileResponse.status == 200, 'Able to POST url to existing IPNS path') - const listingRequest = await fetch(ipnsUrl) + const listingRequest = await fetch(keyURL) assert_true(listingRequest.ok, 'Able to GET from IPNS') @@ -440,12 +393,13 @@ promise_test(async (t) => { method: 'POST', }) assert_true(createKey.status == 201, 'Able to create key') - const keyURL = createKey.url + const keyURL = createKey.headers.get("Location") const getKey2 = await fetch(`ipns://localhost?key=compliance-suite-get-key`, { method: 'GET', }) - assert_true(getKey2.status == 301, '301 redirect to key') + // Should redirect to key ^ + assert_true(getKey2.status == 200, '200, redirected to key') assert_true(getKey2.url == keyURL, 'redirected to correct key URL') }, 'GET IPNS key') From 03f94383457bea383bfba511857fecb4e2925ca6 Mon Sep 17 00:00:00 2001 From: makeworld Date: Wed, 11 May 2022 13:58:58 -0400 Subject: [PATCH 05/12] Fix key GET test --- mutable-tests.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mutable-tests.js b/mutable-tests.js index 7df8727..d07467e 100644 --- a/mutable-tests.js +++ b/mutable-tests.js @@ -229,7 +229,7 @@ promise_test(async (t) => { body: TEST_FILE_CONTENT }) - assert_true(ipnsResponse.status == 200, 'Able to POST url to ipns') + assert_true(ipnsResponse.status == 200, 'Able to PUT url to ipns') const getResponse = await fetch(keyURL) const text = await getResponse.text() @@ -395,6 +395,13 @@ promise_test(async (t) => { assert_true(createKey.status == 201, 'Able to create key') const keyURL = createKey.headers.get("Location") + // Upload file so key resolves when GET is done later + const ipnsResponse = await fetch(`${keyURL}/test`, { + method: 'PUT', + body: TEST_FILE_CONTENT + }) + assert_true(ipnsResponse.status == 200, 'Able to PUT url to ipns') + const getKey2 = await fetch(`ipns://localhost?key=compliance-suite-get-key`, { method: 'GET', }) From b228994c005c9af061d7eb8d251dd2d737f881df Mon Sep 17 00:00:00 2001 From: mauve Date: Thu, 12 May 2022 01:16:59 -0400 Subject: [PATCH 06/12] Fixes for mutable tests --- constants.js | 2 +- mutable-tests.js | 39 +++++++++++++++++++++++---------------- mutable.html | 2 +- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/constants.js b/constants.js index 7f17e78..1fe30af 100644 --- a/constants.js +++ b/constants.js @@ -25,7 +25,7 @@ export const URL_IPFS_DIRECTORY_NO_INDEX = `${URL_IPFS_MEDIA}` export const URL_IPFS_DIRECTORY_WITH_INDEX = `${URL_IPFS_MEDIA}with-index/` export const URL_IPFS_DIRECTORY_EMPTY = `${URL_IPFS_MEDIA}empty` export const URL_IPFS_REDIRECT_FILE = `${URL_IPFS_MEDIA}redirect.html` -export const URL_IPNS_MEDIA = `ipns://ipfs-protocol-compliance-suite.on.fleek.co/files/` +export const URL_IPNS_MEDIA = `ipns://k2k4r8k8i7kqpm8rc5ju7qyw3rvvrp6oq8991dhlrmwa1tzobo7vxumm/` export const URL_IPNS_TEXT_FILE = `${URL_IPNS_MEDIA}example.txt` export const URL_IPNS_IMAGE_FILE = `${URL_IPNS_MEDIA}ipfs-logo.svg` export const URL_IPNS_VIDEO_FILE = `${URL_IPNS_MEDIA}IPFS.mp4` diff --git a/mutable-tests.js b/mutable-tests.js index d07467e..5abd233 100644 --- a/mutable-tests.js +++ b/mutable-tests.js @@ -11,6 +11,8 @@ const OTHER_TEST_FILE_CONTENT = 'Goodby World' const OTHER_TEST_FILE_NAME = 'example2.txt' const EMPTY_DIR_URL = 'ipfs://bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354' +setup({timeout_multiplier: 2}) + promise_test(async (t) => { const putResponse = await fetch(`${EMPTY_DIR_URL}/${TEST_FILE_NAME}`, { method: 'PUT', @@ -60,7 +62,7 @@ promise_test(async (t) => { assert_true(secondFileResponse.status == 201, 'Able to post second file') - const secondUrl = await secondFileResponse.text() + const secondUrl = await secondFileResponse.headers.get("Location") assert_true(secondUrl.startsWith('ipfs://'), 'Got an IPFS url for the content') assert_true(secondUrl.endsWith(OTHER_TEST_FILE_NAME), 'URL ends with the file name') @@ -139,10 +141,13 @@ promise_test(async (t) => { const base = new URL('./', keyURL).href - const secondFileResponse = await fetch(new URL(`./${OTHER_TEST_FILE_NAME}`, base).href, { + const secondUrl = new URL(`./${OTHER_TEST_FILE_NAME}`, base).href + + const secondFileResponse = await fetch(secondUrl, { method: 'PUT', body: OTHER_TEST_FILE_CONTENT }) + assert_true(secondFileResponse.status == 200, 'Able to PUT second file') const listingRequest = await fetch(base) @@ -209,13 +214,13 @@ promise_test(async (t) => { body: TEST_FILE_CONTENT }) - assert_true(ipnsResponse.status == 200, 'Able to POST url to ipns') + assert_true(ipnsResponse.status == 200, 'Able to POST file to ipns') const getResponse = await fetch(keyURL) const text = await getResponse.text() assert_equals(text, TEST_FILE_CONTENT, 'Got content back out') -}, 'PUT IPFS file to IPNS') +}, 'PUT IPFS file to IPNS', {timeout: 120 * 1000}) promise_test(async (t) => { const createKey = await fetch(`ipns://localhost?key=compliance-suite-example3`, { @@ -231,7 +236,7 @@ promise_test(async (t) => { assert_true(ipnsResponse.status == 200, 'Able to PUT url to ipns') - const getResponse = await fetch(keyURL) + const getResponse = await fetch(`${keyURL}/test`) const text = await getResponse.text() assert_equals(text, TEST_FILE_CONTENT, 'Got content back out') @@ -258,7 +263,7 @@ promise_test(async (t) => { const getResponse = await fetch(`${keyURL}/${TEST_FILE_NAME}`) - assert_true(getResponse.ok, 'Able to use URL from POST') + assert_true(getResponse.status === 200, 'Able to get uploaded file') const text = await getResponse.text() @@ -284,14 +289,14 @@ promise_test(async (t) => { assert_true(createKey.status == 201, 'Able to create key') const keyURL = createKey.headers.get("Location") - const putResponse = await fetch(`${keyURL}/test`, { + const putResponse = await fetch(new URL("/test", keyURL).href, { method: 'PUT', body: formData }) assert_true(putResponse.status == 200, 'Able to PUT') - const getResponse = await fetch(`${keyURL}/${TEST_FILE_NAME}`) + const getResponse = await fetch(new URL(`/test/${TEST_FILE_NAME}`, keyURL).href) assert_true(getResponse.ok, 'Able to use URL from POST') @@ -299,7 +304,7 @@ promise_test(async (t) => { assert_equals(text, TEST_FILE_CONTENT, 'Got content back out') - const listingRequest = await fetch(keyURL) + const listingRequest = await fetch(new URL('/test', keyURL).href) const listing = await listingRequest.text() @@ -384,25 +389,26 @@ promise_test(async (t) => { }, 'POST url to IPNS with existing data') promise_test(async (t) => { - const getKey = await fetch(`ipns://localhost?key=compliance-suite-get-key`, { + const key = `compliance-suite-get-key-${Math.random()}` + const getKey = await fetch(`ipns://localhost?key=${key}`, { method: 'GET', }) assert_true(getKey.status == 404, "key doesn't exist yet") - const createKey = await fetch(`ipns://localhost?key=compliance-suite-get-key`, { + const createKey = await fetch(`ipns://localhost?key=${key}`, { method: 'POST', }) assert_true(createKey.status == 201, 'Able to create key') const keyURL = createKey.headers.get("Location") // Upload file so key resolves when GET is done later - const ipnsResponse = await fetch(`${keyURL}/test`, { + const ipnsResponse = await fetch(new URL('/test', keyURL).href, { method: 'PUT', body: TEST_FILE_CONTENT }) assert_true(ipnsResponse.status == 200, 'Able to PUT url to ipns') - const getKey2 = await fetch(`ipns://localhost?key=compliance-suite-get-key`, { + const getKey2 = await fetch(`ipns://localhost?key=${key}`, { method: 'GET', }) // Should redirect to key ^ @@ -411,17 +417,18 @@ promise_test(async (t) => { }, 'GET IPNS key') promise_test(async (t) => { - const createKey = await fetch(`ipns://localhost?key=compliance-suite-delete-key`, { + const key = `compliance-suite-delete-key-${Math.random()}` + const createKey = await fetch(`ipns://localhost?key=${key}`, { method: 'POST', }) assert_true(createKey.status == 201, 'Able to create key') - const deleteKey = await fetch(`ipns://localhost?key=compliance-suite-delete-key`, { + const deleteKey = await fetch(`ipns://localhost?key=${key}`, { method: 'DELETE', }) assert_true(deleteKey.status == 200, '200, deleted key') - const getKey = await fetch(`ipns://localhost?key=compliance-suite-delete-key`, { + const getKey = await fetch(`ipns://localhost?key=${key}`, { method: 'GET', }) assert_true(getKey.status == 404, "404, key doesn't exist") diff --git a/mutable.html b/mutable.html index 1aa7e29..34a9264 100644 --- a/mutable.html +++ b/mutable.html @@ -1,6 +1,6 @@ IPFS Protocol Compliance Suite - Mutability - + From b13756c4f040a61c90beab24d970df07e294efb7 Mon Sep 17 00:00:00 2001 From: makeworld Date: Fri, 13 May 2022 11:02:21 -0400 Subject: [PATCH 07/12] Undo IPNS key change --- constants.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constants.js b/constants.js index 1fe30af..7f17e78 100644 --- a/constants.js +++ b/constants.js @@ -25,7 +25,7 @@ export const URL_IPFS_DIRECTORY_NO_INDEX = `${URL_IPFS_MEDIA}` export const URL_IPFS_DIRECTORY_WITH_INDEX = `${URL_IPFS_MEDIA}with-index/` export const URL_IPFS_DIRECTORY_EMPTY = `${URL_IPFS_MEDIA}empty` export const URL_IPFS_REDIRECT_FILE = `${URL_IPFS_MEDIA}redirect.html` -export const URL_IPNS_MEDIA = `ipns://k2k4r8k8i7kqpm8rc5ju7qyw3rvvrp6oq8991dhlrmwa1tzobo7vxumm/` +export const URL_IPNS_MEDIA = `ipns://ipfs-protocol-compliance-suite.on.fleek.co/files/` export const URL_IPNS_TEXT_FILE = `${URL_IPNS_MEDIA}example.txt` export const URL_IPNS_IMAGE_FILE = `${URL_IPNS_MEDIA}ipfs-logo.svg` export const URL_IPNS_VIDEO_FILE = `${URL_IPNS_MEDIA}IPFS.mp4` From f4a15fc30fe20b275795bc356971e52e0982cd97 Mon Sep 17 00:00:00 2001 From: mauve Date: Fri, 13 May 2022 12:48:31 -0400 Subject: [PATCH 08/12] Use URL to check hostname on ipns redirect --- mutable-tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mutable-tests.js b/mutable-tests.js index 5abd233..592f119 100644 --- a/mutable-tests.js +++ b/mutable-tests.js @@ -413,7 +413,7 @@ promise_test(async (t) => { }) // Should redirect to key ^ assert_true(getKey2.status == 200, '200, redirected to key') - assert_true(getKey2.url == keyURL, 'redirected to correct key URL') + assert_true(new URL(getKey2.url).hostname == new URL(keyURL).hostname, 'redirected to correct key URL') }, 'GET IPNS key') promise_test(async (t) => { From d31cd84097218b383a74316a4cdfb7f83c8d41b4 Mon Sep 17 00:00:00 2001 From: makeworld Date: Fri, 13 May 2022 15:37:21 -0400 Subject: [PATCH 09/12] Fix up tests --- mutable-tests.js | 70 ++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/mutable-tests.js b/mutable-tests.js index 5abd233..e1032fb 100644 --- a/mutable-tests.js +++ b/mutable-tests.js @@ -11,7 +11,7 @@ const OTHER_TEST_FILE_CONTENT = 'Goodby World' const OTHER_TEST_FILE_NAME = 'example2.txt' const EMPTY_DIR_URL = 'ipfs://bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354' -setup({timeout_multiplier: 2}) +setup({ timeout_multiplier: 2 }) promise_test(async (t) => { const putResponse = await fetch(`${EMPTY_DIR_URL}/${TEST_FILE_NAME}`, { @@ -127,13 +127,14 @@ promise_test(async (t) => { }, 'DELETE file from an infohash') promise_test(async (t) => { - const createKey = await fetch(`ipns://localhost?key=compliance-suite-example6`, { + const key = `compliance-suite-${Date.now()}` + const createKey = await fetch(`ipns://localhost?key=${key}`, { method: 'POST', }) assert_true(createKey.status == 201, 'Able to create key') const keyURL = createKey.headers.get("Location") - const firstFileResponse = await fetch(`${keyURL}/${TEST_FILE_NAME}`, { + const firstFileResponse = await fetch(`${keyURL}${TEST_FILE_NAME}`, { method: 'PUT', body: TEST_FILE_CONTENT }) @@ -147,7 +148,7 @@ promise_test(async (t) => { method: 'PUT', body: OTHER_TEST_FILE_CONTENT }) - + assert_true(secondFileResponse.status == 200, 'Able to PUT second file') const listingRequest = await fetch(base) @@ -169,7 +170,7 @@ promise_test(async (t) => { assert_true(finalListing.includes(TEST_FILE_NAME), 'First file still shows up in folder') assert_true(!finalListing.includes(OTHER_TEST_FILE_NAME), 'Second file no longer shows up in folder') -}, 'DELETE file from IPNS') +}, 'DELETE file from IPNS', { timeout: 120 * 1000 }) promise_test(async (t) => { const firstFileResponse = await fetch(`${EMPTY_DIR_URL}/${TEST_FILE_NAME}`, { @@ -183,7 +184,8 @@ promise_test(async (t) => { const base = new URL('./', url).href - const createKey = await fetch(`ipns://localhost?key=compliance-suite-example`, { + const key = `POST-IPFS-TO-IPNS` + const createKey = await fetch(`ipns://localhost?key=${key}`, { method: 'POST', }) assert_true(createKey.status == 201, 'Able to create key') @@ -203,7 +205,8 @@ promise_test(async (t) => { }, 'POST IPFS URL to IPNS') promise_test(async (t) => { - const createKey = await fetch(`ipns://localhost?key=compliance-suite-example2`, { + const key = `compliance-suite-${Date.now()}` + const createKey = await fetch(`ipns://localhost?key=${key}`, { method: 'POST', }) assert_true(createKey.status == 201, 'Able to create key') @@ -214,29 +217,30 @@ promise_test(async (t) => { body: TEST_FILE_CONTENT }) - assert_true(ipnsResponse.status == 200, 'Able to POST file to ipns') + assert_true(ipnsResponse.status == 200, 'Able to PUT file to ipns') const getResponse = await fetch(keyURL) const text = await getResponse.text() assert_equals(text, TEST_FILE_CONTENT, 'Got content back out') -}, 'PUT IPFS file to IPNS', {timeout: 120 * 1000}) +}, 'PUT IPFS file to IPNS', { timeout: 120 * 1000 }) promise_test(async (t) => { - const createKey = await fetch(`ipns://localhost?key=compliance-suite-example3`, { + const key = `compliance-suite-${Date.now()}` + const createKey = await fetch(`ipns://localhost?key=${key}`, { method: 'POST', }) assert_true(createKey.status == 201, 'Able to create key') const keyURL = createKey.headers.get("Location") - const ipnsResponse = await fetch(`${keyURL}/test`, { + const ipnsResponse = await fetch(`${keyURL}test`, { method: 'PUT', body: TEST_FILE_CONTENT }) assert_true(ipnsResponse.status == 200, 'Able to PUT url to ipns') - const getResponse = await fetch(`${keyURL}/test`) + const getResponse = await fetch(`${keyURL}test`) const text = await getResponse.text() assert_equals(text, TEST_FILE_CONTENT, 'Got content back out') @@ -248,7 +252,8 @@ promise_test(async (t) => { formData.append('file', new Blob([TEST_FILE_CONTENT]), TEST_FILE_NAME) formData.append('file', new Blob([OTHER_TEST_FILE_CONTENT]), OTHER_TEST_FILE_NAME) - const createKey = await fetch(`ipns://localhost?key=compliance-suite-example5`, { + const key = `compliance-suite-${Date.now()}` + const createKey = await fetch(`ipns://localhost?key=${key}`, { method: 'POST', }) assert_true(createKey.status == 201, 'Able to create key') @@ -261,7 +266,7 @@ promise_test(async (t) => { assert_true(putResponse.status == 200, 'Able to PUT') - const getResponse = await fetch(`${keyURL}/${TEST_FILE_NAME}`) + const getResponse = await fetch(`${keyURL}${TEST_FILE_NAME}`) assert_true(getResponse.status === 200, 'Able to get uploaded file') @@ -275,7 +280,7 @@ promise_test(async (t) => { assert_true(listing.includes(TEST_FILE_NAME), 'File shows up in parent folder') assert_true(listing.includes(OTHER_TEST_FILE_NAME), 'Other file shows up in parent folder') -}, 'PUT FormData to IPNS') +}, 'PUT FormData to IPNS', { timeout: 120 * 1000 }) promise_test(async (t) => { const formData = new FormData() @@ -283,7 +288,8 @@ promise_test(async (t) => { formData.append('file', new Blob([TEST_FILE_CONTENT]), TEST_FILE_NAME) formData.append('file', new Blob([OTHER_TEST_FILE_CONTENT]), OTHER_TEST_FILE_NAME) - const createKey = await fetch(`ipns://localhost?key=compliance-suite-example7`, { + const key = `compliance-suite-${Date.now()}` + const createKey = await fetch(`ipns://localhost?key=${key}`, { method: 'POST', }) assert_true(createKey.status == 201, 'Able to create key') @@ -310,7 +316,7 @@ promise_test(async (t) => { assert_true(listing.includes(TEST_FILE_NAME), 'File shows up in parent folder') assert_true(listing.includes(OTHER_TEST_FILE_NAME), 'Other file shows up in parent folder') -}, 'PUT FormData to IPNS subpath') +}, 'PUT FormData to IPNS subpath', { timeout: 120 * 1000 }) promise_test(async (t) => { const formData = new FormData() @@ -358,25 +364,37 @@ promise_test(async (t) => { const base = new URL('./', url).href - const createKey = await fetch(`ipns://localhost?key=compliance-suite-example4`, { + const key = `compliance-suite-${Date.now()}` + const createKey = await fetch(`ipns://localhost?key=${key}`, { method: 'POST', }) assert_true(createKey.status == 201, 'Able to create key') const keyURL = createKey.headers.get("Location") - const ipnsResponse = await fetch(`${keyURL}/${TEST_FILE_NAME}`, { + const ipnsResponse = await fetch(`${keyURL}${TEST_FILE_NAME}`, { method: 'POST', body: base }) assert_true(ipnsResponse.status == 200, 'Able to POST url to ipns') - const secondFileResponse = await fetch(`${keyURL}/${OTHER_TEST_FILE_NAME}`, { - method: 'POST', + const secondFileResponse = await fetch(`${EMPTY_DIR_URL}/${OTHER_TEST_FILE_NAME}`, { + method: 'PUT', body: OTHER_TEST_FILE_CONTENT }) - assert_true(secondFileResponse.status == 200, 'Able to POST url to existing IPNS path') + assert_true(secondFileResponse.status == 201, 'Able to PUT second file') + + const url2 = await secondFileResponse.headers.get("Location") + + const base2 = new URL('./', url2).href + + const ipnsResponse2 = await fetch(`${keyURL}${OTHER_TEST_FILE_NAME}`, { + method: 'POST', + body: base2 + }) + + assert_true(ipnsResponse2.status == 200, 'Able to POST url to existing IPNS key') const listingRequest = await fetch(keyURL) @@ -389,7 +407,7 @@ promise_test(async (t) => { }, 'POST url to IPNS with existing data') promise_test(async (t) => { - const key = `compliance-suite-get-key-${Math.random()}` + const key = `compliance-suite-${Date.now()}` const getKey = await fetch(`ipns://localhost?key=${key}`, { method: 'GET', }) @@ -402,7 +420,7 @@ promise_test(async (t) => { const keyURL = createKey.headers.get("Location") // Upload file so key resolves when GET is done later - const ipnsResponse = await fetch(new URL('/test', keyURL).href, { + const ipnsResponse = await fetch(keyURL, { method: 'PUT', body: TEST_FILE_CONTENT }) @@ -414,10 +432,10 @@ promise_test(async (t) => { // Should redirect to key ^ assert_true(getKey2.status == 200, '200, redirected to key') assert_true(getKey2.url == keyURL, 'redirected to correct key URL') -}, 'GET IPNS key') +}, 'GET IPNS key', { timeout: 120 * 1000 }) promise_test(async (t) => { - const key = `compliance-suite-delete-key-${Math.random()}` + const key = `compliance-suite-${Date.now()}` const createKey = await fetch(`ipns://localhost?key=${key}`, { method: 'POST', }) From 2c4f44408d44faedef1929e246fb731e47ec1d9e Mon Sep 17 00:00:00 2001 From: makeworld Date: Fri, 13 May 2022 16:37:51 -0400 Subject: [PATCH 10/12] Fix last failing mutable test, all pass now --- mutable-tests.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mutable-tests.js b/mutable-tests.js index e1032fb..b528156 100644 --- a/mutable-tests.js +++ b/mutable-tests.js @@ -182,9 +182,7 @@ promise_test(async (t) => { const url = await firstFileResponse.headers.get("Location") - const base = new URL('./', url).href - - const key = `POST-IPFS-TO-IPNS` + const key = `compliance-suite-${Date.now()}` const createKey = await fetch(`ipns://localhost?key=${key}`, { method: 'POST', }) @@ -193,7 +191,7 @@ promise_test(async (t) => { const ipnsResponse = await fetch(keyURL, { method: 'POST', - body: base + body: url }) assert_true(ipnsResponse.status == 200, 'Able to POST url to ipns') From 097fe35c51eafe71bc3deaea30628c8d6b857ab8 Mon Sep 17 00:00:00 2001 From: mauve Date: Fri, 3 Jun 2022 23:08:23 -0400 Subject: [PATCH 11/12] Manually specify API to use so that Agregore's built in node can be contacted --- publish-files.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish-files.js b/publish-files.js index f46766e..5e8f053 100755 --- a/publish-files.js +++ b/publish-files.js @@ -63,7 +63,7 @@ async function run () { await fs.mkdir(emptyDir, { recursive: true }) console.log('Uploading to IPFS') - const { stdout: output } = await exec('ipfs add ./files/ --cid-version=1 --raw-leaves=false -r') + const { stdout: output } = await exec('ipfs add ./files/ --cid-version=1 --raw-leaves=false -r --api /ip4/127.0.0.1/tcp/5001') const lines = output.split(/\r?\n/) From 9bd62d4794cd84ea446b379cb7c423d97f5a2e9b Mon Sep 17 00:00:00 2001 From: RangerMauve Date: Fri, 24 Jun 2022 16:31:58 -0400 Subject: [PATCH 12/12] Use proper format strings Co-authored-by: Marcin Rataj --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 33d1027..83ed1c4 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,8 @@ Progress: https://github.com/ipfs/community/discussions/573 - [x] JS `fetch('ipns://localhost?key=', {method: 'GET})` - [x] JS `fetch('ipns://localhost?key=', {method: 'DELETE})` - `dag.html` Tests (experimental, some things subject to change) - - [x] GET `ipfs:///?format=CAR` - - [x] GET `ipfs:///?format=block` + - [x] GET `ipfs:///?format=car` + - [x] GET `ipfs:///?format=raw` - [x] GET `ipfs:///?format=dag-json` - [x] GET `ipfs:///?format=dag-cbor` - [x] POST `Content-Type: application/json` `?format=dag-cbor` & GET `?format=dag-cbor`