Skip to content

A plugin marketplace for GitHub Copilot and other AI agents that provides Power Platform development plugins, including reusable skills, agents, and commands for building and deploying solutions.

fix(mobile-apps): stop repeated Graph pagination (#683)

Prabhat Ojhae41e62c2b05b
diff --git a/plugins/mobile-apps/scripts/discover-app-registrations.js b/plugins/mobile-apps/scripts/discover-app-registrations.js
index 78157930b..b36ae4b8e 100644
--- a/plugins/mobile-apps/scripts/discover-app-registrations.js
+++ b/plugins/mobile-apps/scripts/discover-app-registrations.js
@@ -127,7 +127,12 @@ function listAvailableApplications(clientId = '', request = graphGet) {
if (clientId) query.$filter = `appId eq '${clientId}'`;
let nextLink = graphUrl('/applications', query);
const applications = [];
+ const visitedLinks = new Set();
while (nextLink) {
+ if (visitedLinks.has(nextLink)) {
+ throw new Error('Microsoft Graph returned a repeated applications next link.');
+ }
+ visitedLinks.add(nextLink);
const page = request(nextLink);
if (!Array.isArray(page.value)) throw new Error('Microsoft Graph returned an invalid applications page.');
applications.push(...page.value);
diff --git a/plugins/mobile-apps/scripts/tests/discover-app-registrations.test.js b/plugins/mobile-apps/scripts/tests/discover-app-registrations.test.js
index 1f486c96f..2489ba709 100644
--- a/plugins/mobile-apps/scripts/tests/discover-app-registrations.test.js
+++ b/plugins/mobile-apps/scripts/tests/discover-app-registrations.test.js
@@ -102,6 +102,22 @@ test('lists every tenant-visible registration across Graph pages instead of owne
assert.equal(requested[1], 'https://graph.microsoft.com/v1.0/applications?page=2');
});
+test('rejects repeated Graph next links without requesting a visited page again', () => {
+ const repeatedLink = 'https://graph.microsoft.com/v1.0/applications?page=2';
+ const requested = [];
+
+ assert.throws(() => listAvailableApplications('', (url) => {
+ requested.push(url);
+ return {
+ value: [{ appId: `${requested.length}` }],
+ '@odata.nextLink': repeatedLink,
+ };
+ }), /repeated applications next link/);
+
+ assert.equal(requested.length, 2);
+ assert.equal(requested[1], repeatedLink);
+});
+
test('filters a specific client ID at Graph instead of downloading the tenant list', () => {
const clientId = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa';
let requested;