Skip to content
Merged
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
3 changes: 2 additions & 1 deletion src/settings/command-authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export function normalizeCommandAuthorizationPolicy(input: unknown): { policy: R

export function commandAuthorizationAllowedRoles(policy: RepositoryCommandAuthorizationPolicy | null | undefined, commandName: string): CommandAuthorizationRole[] {
const normalized = normalizeCommandAuthorizationPolicy(policy).policy;
return dedupeRoles(normalized.commands[commandName] ?? normalized.default);
const commandRoles = Object.hasOwn(normalized.commands, commandName) ? normalized.commands[commandName] : undefined;
return dedupeRoles(commandRoles ?? normalized.default);
}

export function commandAuthorizationNeedsMinerDetection(args: {
Expand Down
12 changes: 12 additions & 0 deletions test/unit/command-authorization.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, it } from "vitest";
import {
commandAuthorizationAllowedRoles,
commandAuthorizationNeedsMinerDetection,
evaluateCommandAuthorization,
normalizeCommandAuthorizationPolicy,
Expand Down Expand Up @@ -54,6 +55,17 @@ describe("repo command authorization policy", () => {
});
});

it("falls back to default roles for inherited object property command names", () => {
for (const commandName of ["constructor", "toString", "__proto__", "hasOwnProperty"]) {
expect(commandAuthorizationAllowedRoles(undefined, commandName)).toEqual(["maintainer", "collaborator", "confirmed_miner"]);
expect(evaluateCommandAuthorization({ commandName, commenterAssociation: "OWNER" })).toMatchObject({
authorized: true,
reason: "maintainer_invocation",
allowedRoles: ["maintainer", "collaborator", "confirmed_miner"],
});
}
});

it("warns on malformed policy and falls back to default command roles", () => {
const nonObject = normalizeCommandAuthorizationPolicy("not-a-policy");
expect(nonObject.warnings).toEqual(["commandAuthorization must be an object; using secure defaults."]);
Expand Down