-
Notifications
You must be signed in to change notification settings - Fork 18
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
feat/update webrtc star with dns support #12
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
64b51a3
chore: update deps
daviddias ade442f
feat: add support for dns validation, make IPFS validation much nicer…
daviddias 3b99a73
feat: WebSocketsSecure
daviddias 1d4aa10
feat: rules for dns4 and dns6
daviddias af4db1d
test: test for bad cases as well
daviddias 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 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 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 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,78 +2,104 @@ | |
|
||
'use strict' | ||
|
||
var expect = require('chai').expect | ||
var mafmt = require('./../src') | ||
const expect = require('chai').expect | ||
const mafmt = require('./../src') | ||
|
||
describe('multiaddr validation', function () { | ||
var goodIP = [ | ||
const goodDNS = [ | ||
'/dns/ipfs.io', | ||
'/dns4/ipfs.io', | ||
'/dns4/libp2p.io', | ||
'/dns6/protocol.ai' | ||
] | ||
|
||
const badDNS = [ | ||
'/ip4/127.0.0.1' | ||
] | ||
|
||
const goodIP = [ | ||
'/ip4/0.0.0.0', | ||
'/ip6/fc00::' | ||
] | ||
|
||
var badIP = [ | ||
const badIP = [ | ||
'/ip4/0.0.0.0/tcp/555', | ||
'/udp/789/ip6/fc00::' | ||
] | ||
|
||
var goodTCP = [ | ||
const goodTCP = [ | ||
'/ip4/0.0.7.6/tcp/1234', | ||
'/ip6/::/tcp/0' | ||
] | ||
|
||
var badTCP = [ | ||
const badTCP = [ | ||
'/tcp/12345', | ||
'/ip6/fc00::/udp/5523/tcp/9543' | ||
] | ||
|
||
var goodUDP = [ | ||
const goodUDP = [ | ||
'/ip4/0.0.7.6/udp/1234', | ||
'/ip6/::/udp/0' | ||
] | ||
|
||
var badUDP = [ | ||
const badUDP = [ | ||
'/udp/12345', | ||
'/ip6/fc00::/tcp/5523/udp/9543' | ||
] | ||
|
||
var goodUTP = [ | ||
const goodUTP = [ | ||
'/ip4/1.2.3.4/udp/3456/utp', | ||
'/ip6/::/udp/0/utp' | ||
] | ||
|
||
var badUTP = [ | ||
const badUTP = [ | ||
'/ip4/0.0.0.0/tcp/12345/utp', | ||
'/ip6/::/ip4/0.0.0.0/udp/1234/utp' | ||
] | ||
|
||
var goodWS = [ | ||
const goodWS = [ | ||
'/dns/ipfs.io/ws', | ||
'/ip4/1.2.3.4/tcp/3456/ws', | ||
'/ip6/::/tcp/0/ws' | ||
] | ||
|
||
var goodWebRTCStar = [ | ||
const goodWSS = [ | ||
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. Same here, need a bad example |
||
'/dns/ipfs.io/wss', | ||
'/ip4/1.2.3.4/tcp/3456/wss', | ||
'/ip6/::/tcp/0/wss' | ||
] | ||
|
||
const goodWebRTCStar = [ | ||
'/libp2p-webrtc-star/ip4/1.2.3.4/tcp/3456/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', | ||
'/libp2p-webrtc-star/dns/ipfs.io/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', | ||
'/libp2p-webrtc-star/dns/ipfs.io/wss/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', | ||
'/libp2p-webrtc-star/ip6/::/tcp/0/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo5' | ||
] | ||
|
||
var goodWebRTCDirect = [ | ||
const goodWebRTCDirect = [ | ||
// '/libp2p-webrtc-direct/dns/ipfs.io', | ||
'/libp2p-webrtc-direct/ip4/1.2.3.4/tcp/3456/http', | ||
'/libp2p-webrtc-direct/ip6/::/tcp/0/http' | ||
] | ||
|
||
var badWS = [ | ||
const badWS = [ | ||
'/ip4/0.0.0.0/tcp/12345/udp/2222/ws', | ||
'/ip6/::/ip4/0.0.0.0/udp/1234/ws' | ||
] | ||
|
||
var goodIPFS = [ | ||
const badWSS = [ | ||
'/ip4/0.0.0.0/tcp/12345/udp/2222/wss', | ||
'/ip6/::/ip4/0.0.0.0/udp/1234/wss' | ||
] | ||
|
||
const goodIPFS = [ | ||
'/ip4/127.0.0.1/tcp/20008/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj', | ||
'/libp2p-webrtc-star/ip4/1.2.3.4/tcp/3456/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', | ||
'/ip4/1.2.3.4/tcp/3456/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' | ||
] | ||
|
||
function assertMatches (p) { | ||
var tests = Array.from(arguments).slice(1) | ||
const tests = Array.from(arguments).slice(1) | ||
tests.forEach(function (test) { | ||
test.forEach(function (testcase) { | ||
expect(p.matches(testcase)).to.be.eql(true) | ||
|
@@ -82,14 +108,19 @@ describe('multiaddr validation', function () { | |
} | ||
|
||
function assertMismatches (p) { | ||
var tests = Array.from(arguments).slice(1) | ||
const tests = Array.from(arguments).slice(1) | ||
tests.forEach(function (test) { | ||
test.forEach(function (testcase) { | ||
expect(p.matches(testcase)).to.be.eql(false) | ||
}) | ||
}) | ||
} | ||
|
||
it('DNS validation', function () { | ||
assertMatches(mafmt.DNS, goodDNS) | ||
assertMismatches(mafmt.DNS, badDNS, badIP, goodTCP) | ||
}) | ||
|
||
it('IP validation', function () { | ||
assertMatches(mafmt.IP, goodIP) | ||
assertMismatches(mafmt.IP, badIP, goodTCP) | ||
|
@@ -120,6 +151,11 @@ describe('multiaddr validation', function () { | |
assertMismatches(mafmt.WebSockets, goodIP, goodUDP, badWS) | ||
}) | ||
|
||
it('WebSocketsSecure validation', function () { | ||
assertMatches(mafmt.WebSocketsSecure, goodWSS) | ||
assertMismatches(mafmt.WebSocketsSecure, goodIP, badWSS, goodUDP, badWS) | ||
}) | ||
|
||
it('WebRTC-star validation', function () { | ||
assertMatches(mafmt.WebRTCStar, goodWebRTCStar) | ||
assertMismatches(mafmt.WebRTCStar, goodIP, goodUDP, badWS) | ||
|
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.
We should have at least one example of bad dns as well