From c4d78ec6db87230cdd20528311c7697b15ae3dc4 Mon Sep 17 00:00:00 2001 From: Maxwell Hammad Date: Wed, 8 Jul 2020 17:35:13 -0400 Subject: [PATCH 1/5] 4.1.2 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 561b525..334b678 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "auth0-source-control-extension-tools", - "version": "4.1.1", + "version": "4.1.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index a1b11a3..345400c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "auth0-source-control-extension-tools", - "version": "4.1.1", + "version": "4.1.2", "description": "Supporting tools for the Source Control extensions", "main": "lib/index.js", "scripts": { From 5b5cc528087c1d98316afd70b519b0ea2e6762fc Mon Sep 17 00:00:00 2001 From: Maxwell Hammad Date: Wed, 23 Sep 2020 17:58:46 -0400 Subject: [PATCH 2/5] fix: multiple clients with the same name dropping client grants --- src/utils.js | 7 +- tests/auth0/handlers/clientGrants.tests.js | 109 +++++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index 23d4f0c..d9b6902 100644 --- a/src/utils.js +++ b/src/utils.js @@ -26,7 +26,12 @@ export function convertClientNameToId(name, clients) { } export function convertClientNamesToIds(names, clients) { - return names.map(name => convertClientNameToId(name, clients)); + return clients.reduce((acc, client) => { + if (names.includes(client.name)) { + acc.push(client.client_id); + } + return acc; + }, []); } export function loadFile(file, mappings) { diff --git a/tests/auth0/handlers/clientGrants.tests.js b/tests/auth0/handlers/clientGrants.tests.js index e86ccc4..f3a86c2 100644 --- a/tests/auth0/handlers/clientGrants.tests.js +++ b/tests/auth0/handlers/clientGrants.tests.js @@ -366,4 +366,113 @@ describe('#clientGrants handler', () => { await stageFn.apply(handler, [ assets ]); }); }); + it.only('should not delete client grants of excluded clients with multiple instances', async () => { + config.data = { + AUTH0_CLIENT_ID: 'client_id', + AUTH0_ALLOW_DELETE: true + }; + + const auth0 = { + clientGrants: { + create: (params) => { + expect(params).to.be.an('undefined'); + + return Promise.resolve([]); + }, + update: (params) => { + expect(params).to.be.an('undefined'); + + return Promise.resolve([]); + }, + delete: (params) => { + expect(params).to.be.an('undefined'); + + return Promise.resolve([]); + }, + getAll: () => [ + { + client_id: '123', + audience: 'a', + id: '1' + }, + { + client_id: '123', + audience: 'a', + id: '2' + }, + { + client_id: '123', + audience: 'a', + id: '3' + }, + { + client_id: '456', + audience: 'a', + id: '4' + }, + { + client_id: '456', + audience: 'a', + id: '5' + } + ] + }, + clients: { + getAll: () => [ + { + name: 'abc', + client_id: 'abc' + }, + { + name: 'foo_client', + client_id: '123' + }, + { + name: 'foo_client', + client_id: '456' + } + ] + }, + pool + }; + + const handler = new clientGrants.default({ client: auth0, config }); + const stageFn = Object.getPrototypeOf(handler).processChanges; + + const assets = { + clients: [ + { + name: 'foo_client' + }, + { + name: 'foo_client' + } + ], + clientGrants: [ + { + client_id: 'foo_client', + audience: 'https://example.com' + }, + { + client_id: 'foo_client', + audience: 'https://example.com' + }, + { + client_id: 'foo_client', + audience: 'https://example.com' + }, + { + client_id: 'foo_client', + audience: 'https://example.com' + }, + { + client_id: 'foo_client', + audience: 'https://example.com' + } + ], + exclude: { clients: [ 'foo_client' ] } + }; + + await stageFn.apply(handler, [ assets ]); + }); }); From c8e396f6bafe05256e9ecff98574e9ec3a2ecf68 Mon Sep 17 00:00:00 2001 From: Maxwell Hammad Date: Wed, 23 Sep 2020 18:05:29 -0400 Subject: [PATCH 3/5] tests: remove .only --- tests/auth0/handlers/clientGrants.tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auth0/handlers/clientGrants.tests.js b/tests/auth0/handlers/clientGrants.tests.js index f3a86c2..b3547b2 100644 --- a/tests/auth0/handlers/clientGrants.tests.js +++ b/tests/auth0/handlers/clientGrants.tests.js @@ -366,7 +366,7 @@ describe('#clientGrants handler', () => { await stageFn.apply(handler, [ assets ]); }); }); - it.only('should not delete client grants of excluded clients with multiple instances', async () => { + it('should not delete client grants of excluded clients with multiple instances', async () => { config.data = { AUTH0_CLIENT_ID: 'client_id', AUTH0_ALLOW_DELETE: true From a7244928480b3e817084ec87a711b7bf3f79afb8 Mon Sep 17 00:00:00 2001 From: Maxwell Hammad Date: Wed, 23 Sep 2020 18:05:53 -0400 Subject: [PATCH 4/5] 4.1.8 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index fc7d425..7d66585 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "auth0-source-control-extension-tools", - "version": "4.1.7", + "version": "4.1.8", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ec2d9b8..67446fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "auth0-source-control-extension-tools", - "version": "4.1.7", + "version": "4.1.8", "description": "Supporting tools for the Source Control extensions", "main": "lib/index.js", "scripts": { From 959ae7898f6282a85aafbdee10e6378a599eebd2 Mon Sep 17 00:00:00 2001 From: Maxwell Hammad Date: Wed, 23 Sep 2020 18:23:29 -0400 Subject: [PATCH 5/5] tests: fix missing fallback in updated utility function --- src/utils.js | 7 ++++++- tests/utils.tests.js | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/utils.js b/src/utils.js index d9b6902..64cd470 100644 --- a/src/utils.js +++ b/src/utils.js @@ -26,12 +26,17 @@ export function convertClientNameToId(name, clients) { } export function convertClientNamesToIds(names, clients) { - return clients.reduce((acc, client) => { + const resolvedNames = names.map(name => ({ name, resolved: false })); + const result = clients.reduce((acc, client) => { if (names.includes(client.name)) { + const index = resolvedNames.findIndex(item => item.name === client.name); + resolvedNames[index].resolved = true; acc.push(client.client_id); } return acc; }, []); + const unresolved = resolvedNames.filter(item => !item.resolved).map(item => item.name); + return [ ...unresolved, ...result ]; } export function loadFile(file, mappings) { diff --git a/tests/utils.tests.js b/tests/utils.tests.js index 43469c6..537c670 100644 --- a/tests/utils.tests.js +++ b/tests/utils.tests.js @@ -106,9 +106,9 @@ describe('#utils', function() { const names = [ 'dd', 'cc', 'aa' ]; - const expected = [ 'dd', '3', '1' ]; + const expected = [ '1', '3', 'dd' ]; - expect(utils.convertClientNamesToIds(names, clients)).to.deep.equal(expected); + expect(utils.convertClientNamesToIds(names, clients).sort()).to.deep.equal(expected); }); });