-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Revert "Revert "feat: send additional_permissions in token exchange request"" #866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { describe, expect, test, beforeEach, afterEach } from "bun:test"; | ||
| import { parseAdditionalPermissions } from "../src/github/token"; | ||
|
|
||
| describe("parseAdditionalPermissions", () => { | ||
| let originalEnv: string | undefined; | ||
|
|
||
| beforeEach(() => { | ||
| originalEnv = process.env.ADDITIONAL_PERMISSIONS; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| if (originalEnv === undefined) { | ||
| delete process.env.ADDITIONAL_PERMISSIONS; | ||
| } else { | ||
| process.env.ADDITIONAL_PERMISSIONS = originalEnv; | ||
| } | ||
| }); | ||
|
|
||
| test("returns undefined when env var is not set", () => { | ||
| delete process.env.ADDITIONAL_PERMISSIONS; | ||
| expect(parseAdditionalPermissions()).toBeUndefined(); | ||
| }); | ||
|
|
||
| test("returns undefined when env var is empty string", () => { | ||
| process.env.ADDITIONAL_PERMISSIONS = ""; | ||
| expect(parseAdditionalPermissions()).toBeUndefined(); | ||
| }); | ||
|
|
||
| test("returns undefined when env var is only whitespace", () => { | ||
| process.env.ADDITIONAL_PERMISSIONS = " \n \n "; | ||
| expect(parseAdditionalPermissions()).toBeUndefined(); | ||
| }); | ||
|
|
||
| test("parses single permission and merges with defaults", () => { | ||
| process.env.ADDITIONAL_PERMISSIONS = "actions: read"; | ||
| expect(parseAdditionalPermissions()).toEqual({ | ||
| contents: "write", | ||
| pull_requests: "write", | ||
| issues: "write", | ||
| actions: "read", | ||
| }); | ||
| }); | ||
|
|
||
| test("parses multiple permissions", () => { | ||
| process.env.ADDITIONAL_PERMISSIONS = "actions: read\nworkflows: write"; | ||
| expect(parseAdditionalPermissions()).toEqual({ | ||
| contents: "write", | ||
| pull_requests: "write", | ||
| issues: "write", | ||
| actions: "read", | ||
| workflows: "write", | ||
| }); | ||
| }); | ||
|
|
||
| test("additional permissions can override defaults", () => { | ||
| process.env.ADDITIONAL_PERMISSIONS = "contents: read"; | ||
| expect(parseAdditionalPermissions()).toEqual({ | ||
| contents: "read", | ||
| pull_requests: "write", | ||
| issues: "write", | ||
| }); | ||
| }); | ||
|
|
||
| test("handles extra whitespace around keys and values", () => { | ||
| process.env.ADDITIONAL_PERMISSIONS = " actions : read "; | ||
| expect(parseAdditionalPermissions()).toEqual({ | ||
| contents: "write", | ||
| pull_requests: "write", | ||
| issues: "write", | ||
| actions: "read", | ||
| }); | ||
| }); | ||
|
|
||
| test("skips empty lines", () => { | ||
| process.env.ADDITIONAL_PERMISSIONS = | ||
| "actions: read\n\n\nworkflows: write\n\n"; | ||
| expect(parseAdditionalPermissions()).toEqual({ | ||
| contents: "write", | ||
| pull_requests: "write", | ||
| issues: "write", | ||
| actions: "read", | ||
| workflows: "write", | ||
| }); | ||
| }); | ||
|
|
||
| test("skips lines without colons", () => { | ||
| process.env.ADDITIONAL_PERMISSIONS = | ||
| "actions: read\ninvalid line\nworkflows: write"; | ||
| expect(parseAdditionalPermissions()).toEqual({ | ||
| contents: "write", | ||
| pull_requests: "write", | ||
| issues: "write", | ||
| actions: "read", | ||
| workflows: "write", | ||
| }); | ||
| }); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test Coverage Gap: Missing tests for The
Consider adding tests to verify the integration between |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security: Missing input validation on permission keys and values
The parser accepts arbitrary strings without validation. Consider adding a whitelist to prevent privilege escalation:
Without validation, malicious workflows could inject arbitrary permissions like
admin: writeor downgrade defaults by overridingcontents: write→contents: read.