diff --git a/package-lock.json b/package-lock.json index 72d988e..a539c61 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "auth0-source-control-extension-tools", - "version": "3.5.0", + "version": "3.5.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1bc24d6..c373125 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "auth0-source-control-extension-tools", - "version": "3.5.1", + "version": "3.5.2", "description": "Supporting tools for the Source Control extensions", "main": "lib/index.js", "scripts": { diff --git a/src/auth0/handlers/clientGrants.js b/src/auth0/handlers/clientGrants.js index df384e4..36b897a 100644 --- a/src/auth0/handlers/clientGrants.js +++ b/src/auth0/handlers/clientGrants.js @@ -80,7 +80,7 @@ export default class ClientHandler extends DefaultHandler { const filterGrants = (list) => { if (excludedClients.length) { - return list.filter(item => item.client_id !== currentClient && !excludedClients.includes(item.client_id)); + return list.filter(item => item.client_id !== currentClient && ![ ...excludedClientsByNames, ...excludedClients ].includes(item.client_id)); } return list.filter(item => item.client_id !== currentClient); diff --git a/src/auth0/handlers/connections.js b/src/auth0/handlers/connections.js index 8b4b8f4..783c896 100644 --- a/src/auth0/handlers/connections.js +++ b/src/auth0/handlers/connections.js @@ -48,6 +48,12 @@ export default class ConnectionsHandler extends DefaultHandler { // Convert enabled_clients by name to the id const clients = await this.client.clients.getAll({ paginate: true }); + const excludedClientsByNames = (assets.exclude && assets.exclude.clients) || []; + const excludedClients = excludedClientsByNames.map((clientName) => { + const found = clients.find(c => c.name === clientName); + return (found && found.client_id) || clientName; + }); + const formatted = assets.connections.map(connection => ({ ...connection, enabled_clients: [ @@ -55,7 +61,7 @@ export default class ConnectionsHandler extends DefaultHandler { const found = clients.find(c => c.name === name); if (found) return found.client_id; return name; - }) + }).filter(item => ![ ...excludedClientsByNames, ...excludedClients ].includes(item)) ] })); diff --git a/src/auth0/handlers/databases.js b/src/auth0/handlers/databases.js index 65da739..2326e4e 100644 --- a/src/auth0/handlers/databases.js +++ b/src/auth0/handlers/databases.js @@ -68,6 +68,11 @@ export default class DatabaseHandler extends DefaultHandler { // Convert enabled_clients by name to the id const clients = await this.client.clients.getAll({ paginate: true }); + const excludedClientsByNames = (assets.exclude && assets.exclude.clients) || []; + const excludedClients = excludedClientsByNames.map((clientName) => { + const found = clients.find(c => c.name === clientName); + return (found && found.client_id) || clientName; + }); const formatted = databases.map((db) => { if (db.enabled_clients) { return { @@ -76,7 +81,7 @@ export default class DatabaseHandler extends DefaultHandler { const found = clients.find(c => c.name === name); if (found) return found.client_id; return name; - }) + }).filter(item => ![ ...excludedClientsByNames, ...excludedClients ].includes(item)) }; } diff --git a/tests/auth0/handlers/connections.tests.js b/tests/auth0/handlers/connections.tests.js index 6e804c5..c2047d0 100644 --- a/tests/auth0/handlers/connections.tests.js +++ b/tests/auth0/handlers/connections.tests.js @@ -144,6 +144,51 @@ describe('#connections handler', () => { await stageFn.apply(handler, [ { connections: data } ]); }); + it('should omit excluded clients', async () => { + const auth0 = { + connections: { + create: (data) => { + expect(data).to.be.an('undefined'); + return Promise.resolve(data); + }, + update: (params, data) => { + expect(params).to.be.an('object'); + expect(params.id).to.equal('con1'); + expect(data).to.deep.equal({ + enabled_clients: [ 'YwqVtt8W3pw5AuEz3B2Kse9l2Ruy7Tec' ], + options: { passwordPolicy: 'testPolicy' } + }); + + return Promise.resolve({ ...params, ...data }); + }, + delete: () => Promise.resolve([]), + getAll: () => [ { name: 'someConnection', id: 'con1', strategy: 'custom' } ] + }, + clients: { + getAll: () => [ + { name: 'client1', client_id: 'YwqVtt8W3pw5AuEz3B2Kse9l2Ruy7Tec' }, + { name: 'excluded-one', client_id: 'YwqVtt8W3pw5AuEz3B2Kse9l2Ruy7Teb' } + ] + }, + pool + }; + + const handler = new connections.default({ client: auth0, config }); + const stageFn = Object.getPrototypeOf(handler).processChanges; + const data = [ + { + name: 'someConnection', + strategy: 'custom', + enabled_clients: [ 'client1', 'excluded-one', 'excluded-two' ], + options: { + passwordPolicy: 'testPolicy' + } + } + ]; + + await stageFn.apply(handler, [ { connections: data, exclude: { clients: [ 'excluded-one', 'excluded-two' ] } } ]); + }); + it('should delete connection and create another one instead', async () => { const auth0 = { connections: { diff --git a/tests/auth0/handlers/databases.tests.js b/tests/auth0/handlers/databases.tests.js index 8781a21..0774b33 100644 --- a/tests/auth0/handlers/databases.tests.js +++ b/tests/auth0/handlers/databases.tests.js @@ -140,6 +140,54 @@ describe('#databases handler', () => { await stageFn.apply(handler, [ { databases: data } ]); }); + it('should omit excluded clients', async () => { + const auth0 = { + connections: { + get: (params) => { + expect(params).to.be.an('object'); + expect(params.id).to.equal('con1'); + return Promise.resolve({ options: { someOldOption: true } }); + }, + create: (data) => { + expect(data).to.be.an('undefined'); + return Promise.resolve(data); + }, + update: (params, data) => { + expect(params).to.be.an('object'); + expect(params.id).to.equal('con1'); + expect(data).to.deep.equal({ + enabled_clients: [ 'YwqVtt8W3pw5AuEz3B2Kse9l2Ruy7Tec' ], + options: { passwordPolicy: 'testPolicy', someOldOption: true } + }); + + return Promise.resolve({ ...params, ...data }); + }, + delete: () => Promise.resolve([]), + getAll: () => [ { name: 'someDatabase', id: 'con1', strategy: 'auth0' } ] + }, + clients: { + getAll: () => [ + { name: 'client1', client_id: 'YwqVtt8W3pw5AuEz3B2Kse9l2Ruy7Tec' }, + { name: 'excluded-one', client_id: 'YwqVtt8W3pw5AuEz3B2Kse9l2Ruy7Teb' } + ] + }, + pool + }; + + const handler = new databases.default({ client: auth0, config }); + const stageFn = Object.getPrototypeOf(handler).processChanges; + const data = [ + { + name: 'someDatabase', + strategy: 'auth0', + options: { passwordPolicy: 'testPolicy' }, + enabled_clients: [ 'client1', 'excluded-one', 'excluded-two' ] + } + ]; + + await stageFn.apply(handler, [ { databases: data, exclude: { clients: [ 'excluded-one', 'excluded-two' ] } } ]); + }); + it('should update database without "enabled_clients" setting', async () => { const auth0 = { connections: {