Skip to content
This repository has been archived by the owner on Jul 31, 2021. It is now read-only.

Commit

Permalink
Merge pull request #77 from zxan1285/excluded-clients-fix
Browse files Browse the repository at this point in the history
ESD-3190: Excluded clients fix
  • Loading branch information
lzychowski authored Dec 20, 2019
2 parents 6e5416a + 540400f commit aaa8ae4
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/auth0/handlers/clientGrants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion src/auth0/handlers/connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,20 @@ 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: [
...(connection.enabled_clients || []).map((name) => {
const found = clients.find(c => c.name === name);
if (found) return found.client_id;
return name;
})
}).filter(item => ![ ...excludedClientsByNames, ...excludedClients ].includes(item))
]
}));

Expand Down
7 changes: 6 additions & 1 deletion src/auth0/handlers/databases.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
};
}

Expand Down
45 changes: 45 additions & 0 deletions tests/auth0/handlers/connections.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
48 changes: 48 additions & 0 deletions tests/auth0/handlers/databases.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit aaa8ae4

Please sign in to comment.