Skip to content

Commit

Permalink
added, client db url similarity validation to fix issue where source …
Browse files Browse the repository at this point in the history
…and target clients would bee matched even when the url is different
  • Loading branch information
SkeloGH committed Jan 2, 2020
1 parent 3969f5a commit 261a484
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions bin/__tests__/commands/add/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('weaver add client command tests', () => {
'isSameFamily',
'isSameType',
'isSameName',
'isSameURL',
'validateParams',
'validateConfig',
];
Expand Down
7 changes: 5 additions & 2 deletions bin/commands/add/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() };
Expand All @@ -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;
Expand Down Expand Up @@ -150,6 +152,7 @@ module.exports = {
isSameFamily,
isSameType,
isSameName,
isSameURL,
validateParams,
validateConfig,
};

0 comments on commit 261a484

Please sign in to comment.