From 261a484a452293c3388ad397cada40d55b4a5ff4 Mon Sep 17 00:00:00 2001 From: Aaron_GH Date: Wed, 1 Jan 2020 20:02:37 -0600 Subject: [PATCH] added, client db url similarity validation to fix issue where source and target clients would bee matched even when the url is different --- bin/__tests__/commands/add/client.test.js | 1 + bin/commands/add/client.js | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/__tests__/commands/add/client.test.js b/bin/__tests__/commands/add/client.test.js index 390ddb8..713ff89 100644 --- a/bin/__tests__/commands/add/client.test.js +++ b/bin/__tests__/commands/add/client.test.js @@ -29,6 +29,7 @@ describe('weaver add client command tests', () => { 'isSameFamily', 'isSameType', 'isSameName', + 'isSameURL', 'validateParams', 'validateConfig', ]; diff --git a/bin/commands/add/client.js b/bin/commands/add/client.js index 6125ce6..a12cc39 100644 --- a/bin/commands/add/client.js +++ b/bin/commands/add/client.js @@ -12,6 +12,7 @@ const commandDesc = 'Interactive creation of a new client'; const isSameFamily = (c, _c) => c.family === _c.family; const isSameType = (c, _c) => c.type === _c.type; const isSameName = (c, _c) => c.db.name === _c.name; +const isSameURL = (c, _c) => c.db.url === _c.url; const clientExists = (client) => { const config = { ...getConfig() }; @@ -21,8 +22,9 @@ const clientExists = (client) => { const matchFam = isSameFamily(c, client); const matchName = isSameName(c, client); const matchType = isSameType(c, client); - const isSibling = matchFam && matchName && matchType; - const sourceIsTarget = matchFam && matchName && !matchType; + const matchUrl = isSameURL(c, client); + const isSibling = matchFam && matchName && matchType && matchUrl; + const sourceIsTarget = matchFam && matchName && !matchType && matchUrl; if (isSibling) res.message = 'Error: client exists'; if (sourceIsTarget) res.message = 'Error: source and target clients are the same'; return isSibling || sourceIsTarget; @@ -150,6 +152,7 @@ module.exports = { isSameFamily, isSameType, isSameName, + isSameURL, validateParams, validateConfig, };