Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"homepage": "https://github.com/auth0/auth0-deploy-cli#readme",
"dependencies": {
"ajv": "^6.12.6",
"auth0": "^5.3.1",
"auth0": "^5.4.0",
"dot-prop": "^5.3.0",
"fs-extra": "^10.1.0",
"js-yaml": "^4.1.1",
Expand All @@ -49,11 +49,11 @@
"devDependencies": {
"@eslint/js": "^9.39.2",
"@types/fs-extra": "^9.0.13",
"@types/lodash": "^4.17.23",
"@types/lodash": "^4.17.24",
"@types/mocha": "^10.0.10",
"@types/nconf": "^0.10.7",
"@typescript-eslint/eslint-plugin": "^8.55.0",
"@typescript-eslint/parser": "^8.55.0",
"@typescript-eslint/eslint-plugin": "^8.56.1",
"@typescript-eslint/parser": "^8.56.1",
"chai": "^4.5.0",
"chai-as-promised": "^7.1.2",
"eslint": "^9.39.2",
Expand All @@ -73,7 +73,7 @@
"sinon": "^13.0.2",
"sinon-chai": "^3.7.0",
"ts-mocha": "^11.1.0",
"typescript": "^5.9.3"
"typescript": "~5.9.3"
},
"engines": {
"node": ">=20.19.0"
Expand Down
26 changes: 5 additions & 21 deletions src/tools/auth0/handlers/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,28 +161,12 @@ export const getConnectionEnabledClients = async (
if (!connectionId) return null;

try {
const enabledClientsFormatted: string[] = [];

let enabledClients = await auth0Client.connections.clients.get(connectionId);

// Process first page
enabledClients.data?.forEach((client) => {
if (client?.client_id) {
enabledClientsFormatted.push(client.client_id);
}
});

// Fetch remaining pages
while (enabledClients.hasNextPage()) {
enabledClients = await enabledClients.getNextPage();
enabledClients.data?.forEach((client) => {
if (client?.client_id) {
enabledClientsFormatted.push(client.client_id);
}
});
}
const enabledClients = await paginate<Management.ConnectionEnabledClient>(
(params) => auth0Client.connections.clients.get(connectionId, params),
{ checkpoint: true, take: 100 }
);

return enabledClientsFormatted;
return enabledClients.filter((client) => !!client?.client_id).map((client) => client.client_id);
} catch (error) {
return null;
}
Expand Down
68 changes: 26 additions & 42 deletions test/tools/auth0/handlers/connections.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -926,29 +926,24 @@ describe('#connections enabled clients functionality', () => {
describe('#getConnectionEnabledClients', () => {
it('should return array of client IDs with single page', async () => {
const connectionId = 'con_123';
const mockResponse = {
data: [{ client_id: 'client_1' }, { client_id: 'client_2' }, { client_id: 'client_3' }],
hasNextPage: () => false,
getNextPage: async () => ({ data: [], hasNextPage: () => false }),
};

mockAuth0Client.connections.clients.get.resolves(mockResponse);
mockAuth0Client.connections.clients.get.resolves([
{ client_id: 'client_1' },
{ client_id: 'client_2' },
{ client_id: 'client_3' },
]);

const result = await getConnectionEnabledClients(mockAuth0Client, connectionId);

expect(result).to.deep.equal(['client_1', 'client_2', 'client_3']);
sinon.assert.calledOnceWithExactly(mockAuth0Client.connections.clients.get, connectionId);
sinon.assert.calledOnceWithExactly(mockAuth0Client.connections.clients.get, connectionId, {
checkpoint: true,
take: 100,
});
});

it('should return empty array when no enabled clients', async () => {
const connectionId = 'con_123';
const mockResponse = {
data: [],
hasNextPage: () => false,
getNextPage: async () => ({ data: [], hasNextPage: () => false }),
};

mockAuth0Client.connections.clients.get.resolves(mockResponse);
mockAuth0Client.connections.clients.get.resolves([]);

const result = await getConnectionEnabledClients(mockAuth0Client, connectionId);

Expand All @@ -958,39 +953,30 @@ describe('#connections enabled clients functionality', () => {
it('should handle multi-page pagination correctly', async () => {
const connectionId = 'con_123';

// Simulate 3 pages of results
const page3 = {
data: [{ client_id: 'client_7' }, { client_id: 'client_8' }],
hasNextPage: () => false,
getNextPage: async () => ({ data: [], hasNextPage: () => false }),
};

const page2 = {
data: [{ client_id: 'client_4' }, { client_id: 'client_5' }, { client_id: 'client_6' }],
hasNextPage: () => true,
getNextPage: async () => page3,
};

const page1 = {
data: [{ client_id: 'client_1' }, { client_id: 'client_2' }, { client_id: 'client_3' }],
hasNextPage: () => true,
getNextPage: async () => page2,
};

mockAuth0Client.connections.clients.get.resolves(page1);
// Pagination is handled by the paginate helper; mock returns all clients as a flat array
mockAuth0Client.connections.clients.get.resolves([
{ client_id: 'client_1' },
{ client_id: 'client_2' },
{ client_id: 'client_3' },
{ client_id: 'client_4' },
{ client_id: 'client_5' },
{ client_id: 'client_6' },
{ client_id: 'client_7' },
{ client_id: 'client_8' },
]);

const result = await getConnectionEnabledClients(mockAuth0Client, connectionId);

// Should include ALL clients from ALL 3 pages
expect(result).to.deep.equal([
'client_1',
'client_2',
'client_3', // Page 1
'client_3',
'client_4',
'client_5',
'client_6', // Page 2
'client_6',
'client_7',
'client_8', // Page 3
'client_8',
]);
});
});
Expand Down Expand Up @@ -1407,11 +1393,9 @@ describe('#connections enabled clients functionality', () => {
// Mock enabled clients responses
getEnabledClientsStub
.withArgs('con_1')
.resolves(
mockPagedData({}, 'clients', [{ client_id: 'client_1' }, { client_id: 'client_2' }])
)
.resolves([{ client_id: 'client_1' }, { client_id: 'client_2' }])
.withArgs('con_2')
.resolves(mockPagedData({}, 'clients', [{ client_id: 'client_3' }]));
.resolves([{ client_id: 'client_3' }]);

const handler = new connections.default({ client: pageClient(auth0), config });
handler.scimHandler = scimHandlerMock;
Expand Down
8 changes: 3 additions & 5 deletions test/tools/auth0/handlers/databases.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ describe('#databases handler', () => {
},
clients: {
get: () => {
return Promise.resolve(mockPagedData({}, 'clients', [{ client_id: clientId }]));
return Promise.resolve([{ client_id: clientId }]);
},
},
},
Expand Down Expand Up @@ -2242,11 +2242,9 @@ describe('#databases handler with enabled clients integration', () => {
// Mock enabled clients responses
getEnabledClientsStub
.withArgs('con_1')
.resolves(
mockPagedData({}, 'clients', [{ client_id: 'client_1' }, { client_id: 'client_2' }])
)
.resolves([{ client_id: 'client_1' }, { client_id: 'client_2' }])
.withArgs('con_2')
.resolves(mockPagedData({}, 'clients', [{ client_id: 'client_3' }]));
.resolves([{ client_id: 'client_3' }]);

const handler = new databases.default({ client: pageClient(auth0), config });

Expand Down