Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: passed config validation (#2270)
Browse files Browse the repository at this point in the history
Fixes validation for `config.Addresses.API` and `config.Addresses.Gateway` to allow array of multiaddr and adds missing `config.Swarm.ConnMgr` validation.

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
  • Loading branch information
alanshaw committed Jul 17, 2019
1 parent 298e541 commit 80e7d81
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ const configSchema = s({
Addresses: optional(s({
Delegates: optional(s(['multiaddr'])),
Swarm: optional(s(['multiaddr'])),
API: 'multiaddr?',
Gateway: 'multiaddr'
API: optional(union([s('multiaddr'), s(['multiaddr'])])),
Gateway: optional(union([s('multiaddr'), s(['multiaddr'])]))
})),
Discovery: optional(s({
MDNS: optional(s({
Expand All @@ -67,7 +67,13 @@ const configSchema = s({
Enabled: 'boolean?'
}))
})),
Bootstrap: optional(s(['multiaddr-ipfs']))
Bootstrap: optional(s(['multiaddr-ipfs'])),
Swarm: optional(s({
ConnMgr: optional(s({
LowWater: 'number?',
HighWater: 'number?'
}))
}))
})),
ipld: 'object?',
libp2p: optional(union(['function', 'object'])) // libp2p validates this
Expand Down
18 changes: 15 additions & 3 deletions test/core/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,17 @@ describe('config', () => {
{ config: { Addresses: { Swarm: undefined } } },

{ config: { Addresses: { API: '/ip4/127.0.0.1/tcp/5002' } } },
{ config: { Addresses: { API: ['/ip4/127.0.0.1/tcp/5002', '/ip4/127.0.0.1/tcp/5003'] } } },
{ config: { Addresses: { API: undefined } } },

{ config: { Addresses: { Gateway: '/ip4/127.0.0.1/tcp/9090' } } },
{ config: { Addresses: { Gateway: ['/ip4/127.0.0.1/tcp/9090', '/ip4/127.0.0.1/tcp/9091'] } } },
{ config: { Addresses: { Gateway: undefined } } },

{ config: { Addresses: { Delegates: ['/dns4/node0.preload.ipfs.io/tcp/443/https'] } } },
{ config: { Addresses: { Delegates: [] } } },
{ config: { Addresses: { Delegates: undefined } } },

{ config: { Addresses: undefined } },

{ config: { Discovery: { MDNS: { Enabled: true } } } },
Expand All @@ -144,9 +150,10 @@ describe('config', () => {
{ config: { Bootstrap: ['/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'] } },
{ config: { Bootstrap: [] } },

{ config: { Addresses: { Delegates: ['/dns4/node0.preload.ipfs.io/tcp/443/https'] } } },
{ config: { Addresses: { Delegates: [] } } },
{ config: { Addresses: { Delegates: undefined } } },
{ config: { Swarm: { ConnMgr: { LowWater: 200, HighWater: 500 } } } },
{ config: { Swarm: { ConnMgr: { LowWater: undefined, HighWater: undefined } } } },
{ config: { Swarm: { ConnMgr: undefined } } },
{ config: { Swarm: undefined } },

{ config: undefined }
]
Expand All @@ -173,6 +180,11 @@ describe('config', () => {
{ config: { Bootstrap: ['/ip4/0.0.0.0/tcp/4002'] } },
{ config: { Bootstrap: 138 } },

{ config: { Swarm: { ConnMgr: { LowWater: 200, HighWater: {} } } } },
{ config: { Swarm: { ConnMgr: { LowWater: {}, HighWater: 500 } } } },
{ config: { Swarm: { ConnMgr: 138 } } },
{ config: { Swarm: 138 } },

{ config: 138 }
]

Expand Down

0 comments on commit 80e7d81

Please sign in to comment.