make ipv4 and ipv6 settings separate
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
exports = module.exports = {
|
||||
getServerIPv4,
|
||||
getServerIPv6,
|
||||
testConfig
|
||||
testIPv4Config,
|
||||
testIPv6Config
|
||||
};
|
||||
|
||||
const assert = require('assert'),
|
||||
@@ -24,16 +25,20 @@ async function getServerIPv6(config) {
|
||||
throw new BoxError(BoxError.NETWORK_ERROR, 'No IPv6 configured');
|
||||
}
|
||||
|
||||
async function testConfig(config) {
|
||||
async function testIPv4Config(config) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
|
||||
if (typeof config.ipv4 !== 'string') return new BoxError(BoxError.BAD_FIELD, 'ipv4 must be a string');
|
||||
if (!net.isIPv4(config.ipv4)) return new BoxError(BoxError.BAD_FIELD, 'invalid IPv4');
|
||||
|
||||
if ('ipv6' in config) {
|
||||
if (typeof config.ipv6 !== 'string') return new BoxError(BoxError.BAD_FIELD, 'ipv6 must be a string');
|
||||
if (!net.isIPv6(config.ipv6)) return new BoxError(BoxError.BAD_FIELD, 'invalid IPv6');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function testIPv6Config(config) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
|
||||
if (typeof config.ipv6 !== 'string') return new BoxError(BoxError.BAD_FIELD, 'ipv6 must be a string');
|
||||
if (!net.isIPv6(config.ipv6)) return new BoxError(BoxError.BAD_FIELD, 'invalid IPv6');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
exports = module.exports = {
|
||||
getServerIPv4,
|
||||
getServerIPv6,
|
||||
testConfig
|
||||
testIPv4Config,
|
||||
testIPv6Config
|
||||
};
|
||||
|
||||
const assert = require('assert'),
|
||||
@@ -62,7 +63,13 @@ async function getServerIPv6(config) {
|
||||
return response.body.ip;
|
||||
}
|
||||
|
||||
async function testConfig(config) {
|
||||
async function testIPv4Config(config) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async function testIPv6Config(config) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
|
||||
return null;
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
exports = module.exports = {
|
||||
getServerIPv4,
|
||||
getServerIPv6,
|
||||
testConfig
|
||||
testIPv4Config,
|
||||
testIPv6Config
|
||||
};
|
||||
|
||||
const assert = require('assert'),
|
||||
@@ -27,7 +28,13 @@ async function getServerIPv6(config) {
|
||||
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'getServerIPv6 is not implemented');
|
||||
}
|
||||
|
||||
async function testConfig(config) {
|
||||
async function testIPv4Config(config) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async function testIPv6Config(config) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
|
||||
return null;
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
exports = module.exports = {
|
||||
getServerIPv4,
|
||||
getServerIPv6,
|
||||
testConfig
|
||||
testIPv4Config,
|
||||
testIPv6Config
|
||||
};
|
||||
|
||||
const assert = require('assert'),
|
||||
@@ -40,7 +41,7 @@ async function getServerIPv6(config) {
|
||||
return addresses[0];
|
||||
}
|
||||
|
||||
async function testConfig(config) {
|
||||
async function testIPv4Config(config) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
@@ -49,3 +50,13 @@ async function testConfig(config) {
|
||||
const [error] = await safe(getServerIPv4(config));
|
||||
return error || null;
|
||||
}
|
||||
|
||||
async function testIPv6Config(config) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
if (typeof config.ifname !== 'string') return new BoxError(BoxError.BAD_FIELD, 'ifname is not a string');
|
||||
|
||||
const [error] = await safe(getServerIPv6(config));
|
||||
return error || null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user