Skip to content

Commit 3690acb

Browse files
committed
Restrict Graph identity health keep to GET
1 parent 815e7be commit 3690acb

2 files changed

Lines changed: 53 additions & 16 deletions

File tree

packages/plugins/microsoft/src/sdk/graph.test.ts

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ paths:
191191
responses:
192192
"200":
193193
description: OK
194+
patch:
195+
operationId: me.UpdateUser
196+
security:
197+
- azureAdDelegated:
198+
- User.ReadWrite
199+
responses:
200+
"200":
201+
description: OK
194202
/me/photo:
195203
get:
196204
operationId: me.photo.GetProfilePhoto
@@ -230,6 +238,36 @@ const noWorkloadSelection = {
230238
tagPrefixes: [],
231239
} as const;
232240

241+
const profileSelection = {
242+
coversFullGraph: false,
243+
presetIds: ["profile"],
244+
customScopes: [],
245+
exactPaths: ["/me", "/me/photo", "/me/photo/$value"],
246+
pathPrefixes: [],
247+
tagPrefixes: [],
248+
} as const;
249+
250+
type MicrosoftGraphKeepPathItemSelection = Parameters<typeof microsoftGraphKeepPathItem>[0];
251+
252+
const keptIdentityFixturePaths = (
253+
selection: MicrosoftGraphKeepPathItemSelection,
254+
): Map<string, Record<string, unknown>> => {
255+
const structure = structuralSplit(identityPathFixture);
256+
expect(structure).not.toBeNull();
257+
const keepPathItem = microsoftGraphKeepPathItem(selection);
258+
const kept = new Map<string, Record<string, unknown>>();
259+
260+
for (const range of structure!.pathItems) {
261+
const entry = parseEntry(structure!.text, range, 2);
262+
expect(entry).not.toBeNull();
263+
const [path, rawPathItem] = entry!;
264+
const pathItem = keepPathItem(path, rawPathItem as Record<string, unknown>);
265+
if (pathItem) kept.set(path, pathItem as Record<string, unknown>);
266+
}
267+
268+
return kept;
269+
};
270+
233271
const keptPathItem = (fixture: string): Record<string, unknown> => {
234272
const structure = structuralSplit(fixture);
235273
expect(structure).not.toBeNull();
@@ -285,22 +323,19 @@ const responseFileHintKind = (
285323
return Option.getOrUndefined(hint)?.kind;
286324
};
287325

288-
it("keeps bare /me for identity health checks without keeping /me child paths", () => {
289-
const structure = structuralSplit(identityPathFixture);
290-
expect(structure).not.toBeNull();
291-
const keepPathItem = microsoftGraphKeepPathItem(noWorkloadSelection);
292-
const kept = new Map<string, Record<string, unknown>>();
293-
294-
for (const range of structure!.pathItems) {
295-
const entry = parseEntry(structure!.text, range, 2);
296-
expect(entry).not.toBeNull();
297-
const [path, rawPathItem] = entry!;
298-
const pathItem = keepPathItem(path, rawPathItem as Record<string, unknown>);
299-
if (pathItem) kept.set(path, pathItem as Record<string, unknown>);
300-
}
326+
it("keeps only GET /me for identity health checks without selected workloads", () => {
327+
const kept = keptIdentityFixturePaths(noWorkloadSelection);
301328

302329
expect([...kept.keys()]).toEqual(["/me"]);
303330
expect(kept.get("/me")?.get).toMatchObject({ operationId: "me.GetUser" });
331+
expect(kept.get("/me")?.patch).toBeUndefined();
332+
});
333+
334+
it("keeps all /me operations when profile selects the path", () => {
335+
const kept = keptIdentityFixturePaths(profileSelection);
336+
337+
expect(kept.get("/me")?.get).toMatchObject({ operationId: "me.GetUser" });
338+
expect(kept.get("/me")?.patch).toMatchObject({ operationId: "me.UpdateUser" });
304339
});
305340

306341
it("keeps already-binary drive content responses untouched", () => {

packages/plugins/microsoft/src/sdk/graph.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,17 +525,19 @@ const filterPathItem = (
525525
): Record<string, unknown> | null => {
526526
// Always keep bare /me: the default identity health check depends on GET /me
527527
// even when the profile workload is unchecked.
528-
const pathMatches =
529-
isIdentityHealthPath(path) || matchesGraphPath(path, options.exactPaths, options.pathPrefixes);
528+
const pathMatchesSelection = matchesGraphPath(path, options.exactPaths, options.pathPrefixes);
529+
const identityHealthGetOnly = !pathMatchesSelection && isIdentityHealthPath(path);
530530
const kept: Record<string, unknown> = {};
531531
let hasOperation = false;
532532

533533
for (const [key, value] of Object.entries(pathItem)) {
534534
const lowerKey = key.toLowerCase();
535535
if (!HTTP_METHODS.has(lowerKey)) continue;
536536
if (!isRecord(value)) continue;
537+
if (identityHealthGetOnly && lowerKey !== "get") continue;
537538
if (
538-
pathMatches ||
539+
pathMatchesSelection ||
540+
identityHealthGetOnly ||
539541
operationMatchesTagPrefix(value, options.tagPrefixes) ||
540542
operationMatchesScope(value, options.selectedScopes)
541543
) {

0 commit comments

Comments
 (0)