This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
feat: add support to resolve dns to ipns #458
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
188de11
feat: add support to resolve dns to ipns
hugomrdias c42ee1c
fix: fix feedback
hugomrdias 4daef77
feat: add append remainder tests
hugomrdias 45f2bad
fix: chai chaining for some reason doesnt work
hugomrdias cee7e9c
fix: more pubsub tests fixes
hugomrdias 6be0f63
fix: cleanup dns tests
hugomrdias d845e49
fix: refactor tests
hugomrdias 64924ae
fix: make recursive true by default
hugomrdias 40f2aee
chore: fix linter
hugomrdias 42acfb7
fix: skip some ping test cause of go
hugomrdias c0ed670
fix: remove chai as promised
hugomrdias 2ea7511
fix: unskip ping tests
hugomrdias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,28 +2,20 @@ | |
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const hat = require('hat') | ||
|
||
const { fixture } = require('./utils') | ||
const { spawnNodeWithId } = require('../utils/spawn') | ||
const { getDescribe, getIt, expect } = require('../utils/mocha') | ||
const delay = require('../utils/delay') | ||
|
||
module.exports = (createCommon, options) => { | ||
const describe = getDescribe(options) | ||
const it = getIt(options) | ||
const common = createCommon() | ||
|
||
describe('.name.resolve', function () { | ||
const keyName = hat() | ||
describe('.name.resolve offline', function () { | ||
const common = createCommon() | ||
let ipfs | ||
let nodeId | ||
let keyId | ||
|
||
before(function (done) { | ||
// CI takes longer to instantiate the daemon, so we need to increase the | ||
// timeout for the before step | ||
this.timeout(60 * 1000) | ||
|
||
common.setup((err, factory) => { | ||
expect(err).to.not.exist() | ||
|
||
|
@@ -32,106 +24,157 @@ module.exports = (createCommon, options) => { | |
|
||
ipfs = node | ||
nodeId = node.peerId.id | ||
|
||
ipfs.add(fixture.data, { pin: false }, done) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
after((done) => common.teardown(done)) | ||
|
||
it('should resolve a record with the default params after a publish', function (done) { | ||
this.timeout(50 * 1000) | ||
it('should resolve a record default options', async () => { | ||
const [{ path }] = await ipfs.add(Buffer.from('should resolve a record default options')) | ||
|
||
const value = fixture.cid | ||
const { id: keyId } = await ipfs.key.gen('key-name-default', { type: 'rsa', size: 2048 }) | ||
|
||
ipfs.name.publish(value, (err, res) => { | ||
expect(err).to.not.exist() | ||
expect(res).to.exist() | ||
await ipfs.name.publish(path, { 'allow-offline': true }) | ||
await ipfs.name.publish(`/ipns/${nodeId}`, { 'allow-offline': true, key: 'key-name-default' }) | ||
|
||
ipfs.name.resolve(nodeId, (err, res) => { | ||
expect(err).to.not.exist() | ||
expect(res).to.exist() | ||
expect(res.path).to.equal(`/ipfs/${value}`) | ||
return expect(await ipfs.name.resolve(`/ipns/${keyId}`)) | ||
.to.eq(`/ipfs/${path}`) | ||
}) | ||
|
||
done() | ||
}) | ||
}) | ||
it('should resolve a record recursive === false', async () => { | ||
const [{ path }] = await ipfs.add(Buffer.from('should resolve a record recursive === false')) | ||
await ipfs.name.publish(path, { 'allow-offline': true }) | ||
return expect(await ipfs.name.resolve(`/ipns/${nodeId}`, { recursive: false })) | ||
.to.eq(`/ipfs/${path}`) | ||
}) | ||
|
||
it('should not get the entry if its validity time expired', function (done) { | ||
this.timeout(50 * 1000) | ||
it('should resolve a record recursive === true', async () => { | ||
const [{ path }] = await ipfs.add(Buffer.from('should resolve a record recursive === true')) | ||
|
||
const value = fixture.cid | ||
const publishOptions = { | ||
resolve: true, | ||
lifetime: '1ms', | ||
ttl: '10s', | ||
key: 'self' | ||
} | ||
const { id: keyId } = await ipfs.key.gen('key-name', { type: 'rsa', size: 2048 }) | ||
|
||
ipfs.name.publish(value, publishOptions, (err, res) => { | ||
expect(err).to.not.exist() | ||
expect(res).to.exist() | ||
|
||
// guarantee that the record has an expired validity. | ||
setTimeout(function () { | ||
ipfs.name.resolve(nodeId, (err, res) => { | ||
expect(err).to.exist() | ||
expect(err.message).to.equal('record has expired') | ||
expect(res).to.not.exist() | ||
|
||
done() | ||
}) | ||
}, 1) | ||
}) | ||
await ipfs.name.publish(path, { 'allow-offline': true }) | ||
await ipfs.name.publish(`/ipns/${nodeId}`, { 'allow-offline': true, key: 'key-name' }) | ||
|
||
return expect(await ipfs.name.resolve(`/ipns/${keyId}`, { recursive: true })) | ||
.to.eq(`/ipfs/${path}`) | ||
}) | ||
|
||
it('should resolve a record default options with remainder', async () => { | ||
const [{ path }] = await ipfs.add(Buffer.from('should resolve a record default options with remainder')) | ||
|
||
const { id: keyId } = await ipfs.key.gen('key-name-remainder-default', { type: 'rsa', size: 2048 }) | ||
|
||
await ipfs.name.publish(path, { 'allow-offline': true }) | ||
await ipfs.name.publish(`/ipns/${nodeId}`, { 'allow-offline': true, key: 'key-name-remainder-default' }) | ||
|
||
return expect(await ipfs.name.resolve(`/ipns/${keyId}/remainder/file.txt`)) | ||
.to.eq(`/ipfs/${path}/remainder/file.txt`) | ||
}) | ||
|
||
it('should resolve a record recursive === false with remainder', async () => { | ||
const [{ path }] = await ipfs.add(Buffer.from('should resolve a record recursive = false with remainder')) | ||
await ipfs.name.publish(path, { 'allow-offline': true }) | ||
return expect(await ipfs.name.resolve(`/ipns/${nodeId}/remainder/file.txt`, { recursive: false })) | ||
.to.eq(`/ipfs/${path}/remainder/file.txt`) | ||
}) | ||
|
||
it('should recursively resolve to an IPFS hash', function (done) { | ||
this.timeout(100 * 1000) | ||
it('should resolve a record recursive === true with remainder', async () => { | ||
const [{ path }] = await ipfs.add(Buffer.from('should resolve a record recursive = true with remainder')) | ||
|
||
const { id: keyId } = await ipfs.key.gen('key-name-remainder', { type: 'rsa', size: 2048 }) | ||
|
||
const value = fixture.cid | ||
await ipfs.name.publish(path, { 'allow-offline': true }) | ||
await ipfs.name.publish(`/ipns/${nodeId}`, { 'allow-offline': true, key: 'key-name-remainder' }) | ||
|
||
return expect(await ipfs.name.resolve(`/ipns/${keyId}/remainder/file.txt`, { recursive: true })) | ||
.to.eq(`/ipfs/${path}/remainder/file.txt`) | ||
}) | ||
|
||
it('should not get the entry if its validity time expired', async () => { | ||
const publishOptions = { | ||
resolve: false, | ||
lifetime: '24h', | ||
lifetime: '100ms', | ||
ttl: '10s', | ||
key: 'self' | ||
'allow-offline': true | ||
} | ||
|
||
// Generate new key | ||
ipfs.key.gen(keyName, { type: 'rsa', size: 2048 }, (err, key) => { | ||
expect(err).to.not.exist() | ||
// we add new data instead of re-using fixture to make sure lifetime handling doesn't break | ||
const [{ path }] = await ipfs.add(Buffer.from('should not get the entry if its validity time expired')) | ||
await ipfs.name.publish(path, publishOptions) | ||
await delay(500) | ||
// go only has 1 possible error https://github.com/ipfs/go-ipfs/blob/master/namesys/interface.go#L51 | ||
// so here we just expect an Error and don't match the error type to expiration | ||
try { | ||
await ipfs.name.resolve(nodeId) | ||
} catch (error) { | ||
expect(error).to.exist() | ||
} | ||
}) | ||
}) | ||
|
||
describe('.name.resolve dns', function () { | ||
const common = createCommon() | ||
let ipfs | ||
this.retries(3) | ||
|
||
keyId = key.id | ||
before(function (done) { | ||
common.setup((err, factory) => { | ||
expect(err).to.not.exist() | ||
|
||
// publish ipfs | ||
ipfs.name.publish(value, publishOptions, (err, res) => { | ||
spawnNodeWithId(factory, (err, node) => { | ||
expect(err).to.not.exist() | ||
expect(res).to.exist() | ||
|
||
publishOptions.key = keyName | ||
ipfs = node | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
// publish ipns with the generated key | ||
ipfs.name.publish(`/ipns/${nodeId}`, publishOptions, (err, res) => { | ||
expect(err).to.not.exist() | ||
expect(res).to.exist() | ||
after((done) => common.teardown(done)) | ||
|
||
const resolveOptions = { | ||
nocache: false, | ||
recursive: true | ||
} | ||
it('should resolve /ipns/ipfs.io', async () => { | ||
return expect(await ipfs.name.resolve('/ipns/ipfs.io')) | ||
.to.match(/\/ipfs\/.+$/) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we cant for the remainder tests i would prefer to keep them all the same |
||
}) | ||
|
||
// recursive resolve (will get ipns first, and will resolve again to find the ipfs) | ||
ipfs.name.resolve(keyId, resolveOptions, (err, res) => { | ||
expect(err).to.not.exist() | ||
expect(res).to.exist() | ||
expect(res.path).to.equal(`/ipfs/${value}`) | ||
it('should resolve /ipns/ipfs.io recursive === false', async () => { | ||
return expect(await ipfs.name.resolve('/ipns/ipfs.io', { recursive: false })) | ||
.to.match(/\/ipns\/.+$/) | ||
}) | ||
|
||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
it('should resolve /ipns/ipfs.io recursive === true', async () => { | ||
return expect(await ipfs.name.resolve('/ipns/ipfs.io', { recursive: true })) | ||
.to.match(/\/ipfs\/.+$/) | ||
}) | ||
|
||
it('should resolve /ipns/ipfs.io with remainder', async () => { | ||
return expect(await ipfs.name.resolve('/ipns/ipfs.io/images/ipfs-logo.svg')) | ||
.to.match(/\/ipfs\/.+\/images\/ipfs-logo.svg$/) | ||
}) | ||
|
||
it('should resolve /ipns/ipfs.io with remainder recursive === false', async () => { | ||
return expect(await ipfs.name.resolve('/ipns/ipfs.io/images/ipfs-logo.svg', { recursive: false })) | ||
.to.match(/\/ipns\/.+\/images\/ipfs-logo.svg$/) | ||
}) | ||
|
||
it('should resolve /ipns/ipfs.io with remainder recursive === true', async () => { | ||
return expect(await ipfs.name.resolve('/ipns/ipfs.io/images/ipfs-logo.svg', { recursive: true })) | ||
.to.match(/\/ipfs\/.+\/images\/ipfs-logo.svg$/) | ||
}) | ||
|
||
it('should fail to resolve /ipns/ipfs.a', async () => { | ||
try { | ||
await ipfs.name.resolve('ipfs.a') | ||
} catch (error) { | ||
expect(error).to.exist() | ||
} | ||
hugomrdias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
|
||
it('should resolve ipns path with hamt-shard recursive === true', async () => { | ||
return expect(await ipfs.name.resolve('/ipns/tr.wikipedia-on-ipfs.org/wiki/Anasayfa.html', { recursive: true })) | ||
.to.match(/\/ipfs\/.+$/) | ||
}) | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Camel case please -
allowOffline
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
camel case doesn't work alan, this is used directly as http payload for go-ipfs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't be - core takes camel case options, if it needs to be converted to dash-case for the query string then
js-ipfs-http-client
needs to convert it andjs-ipfs
HTTP endpoint needs to convert it back. This is consistent with many of the other endpoints.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alanshaw can we defer this to another PR ? ill make an issue to track
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but we should get it resolved before the next release as it's a breaking change to a brand new feature otherwise.