Skip to content

Commit

Permalink
Merge pull request #563 from auth0/fix-omit-enabled-connections-appro…
Browse files Browse the repository at this point in the history
…priately

Fix: omit `enabled_clients` from connection payload if not defined
  • Loading branch information
willvedd authored Jun 6, 2022
2 parents 1d91472 + 57a9004 commit 5fd6076
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ export function getEnabledClients(
connection: Asset,
existing: Asset[],
clients: Asset[]
): string[] {
): string[] | undefined {
// Convert enabled_clients by name to the id

if (connection.enabled_clients === undefined) return undefined; // If no enabled clients passed in, explicitly ignore from management, preventing unintentional disabling of connection.

const excludedClientsByNames = (assets.exclude && assets.exclude.clients) || [];
const excludedClients = convertClientNamesToIds(excludedClientsByNames, clients);
const enabledClients = [
Expand Down
64 changes: 64 additions & 0 deletions test/tools/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { expect } from 'chai';
import { getEnabledClients } from '../../src/tools/utils';

describe('#getEnabledClients', () => {
const mockExclusions = {};
const mockExistingConnections = [
{ name: 'Existing connection', enabled_clients: ['Client 1', 'Client 2'] },
];
const mockClients = [
{ name: 'Client 1', id: 'client-1-id' },
{ name: 'Client 2', id: 'client-2-id' },
{ name: 'Client 3', id: 'client-3-id' },
];

it('should return no enabled clients if connection does not have any', () => {
const mockConnection = {
enabled_clients: [], // No enabled clients!
name: 'Target connection',
};

const enabledClients = getEnabledClients(
mockExclusions,
mockConnection,
mockExistingConnections,
mockClients
);

expect(enabledClients).to.deep.equal([]);
});

it('should return enabled clients when connection defines them', () => {
const expectedEnabledClients = ['client-id-1', 'client-id-2']; // Two enabled clients!

const mockConnection = {
enabled_clients: expectedEnabledClients,
name: 'Target connection',
};

const enabledClients = getEnabledClients(
mockExclusions,
mockConnection,
mockExistingConnections,
mockClients
);

expect(enabledClients).to.deep.equal(expectedEnabledClients);
});

it('should return undefined when enable clients is not defined', () => {
const mockConnection = {
enabled_clients: undefined, // This connection has no defined clients enabled. See: GH issue #523
name: 'Target connection',
};

const enabledClients = getEnabledClients(
mockExclusions,
mockConnection,
mockExistingConnections,
mockClients
);

expect(enabledClients).to.equal(undefined);
});
});

0 comments on commit 5fd6076

Please sign in to comment.