diff options
| author | copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> | 2026-07-15 14:54:26 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-15 14:54:26 +0000 |
| commit | d255726b1ea935ff669b21b7cd88f7e6e0b1435e (patch) | |
| tree | d8f577cd98876197d4976481b72755df2b02eb6a /__test__/input-helper.test.ts | |
| parent | 93e494ef84ba8e3de98da2927beaf09ecfa946d7 (diff) | |
skip running unsafe pr check if input is default (backport #2518 to releases/v5)copilot/backport-2518-releases-v5
Diffstat (limited to '__test__/input-helper.test.ts')
| -rw-r--r-- | __test__/input-helper.test.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/__test__/input-helper.test.ts b/__test__/input-helper.test.ts index 2b7e918..3901125 100644 --- a/__test__/input-helper.test.ts +++ b/__test__/input-helper.test.ts @@ -145,4 +145,50 @@ describe('input-helper tests', () => { const settings: IGitSourceSettings = await inputHelper.getInputs() expect(settings.workflowOrganizationId).toBe(123456) }) + + describe('unsafe PR checkout guard', () => { + const forkPayload = { + repository: {id: 100}, + pull_request: { + head: { + sha: '1234567890123456789012345678901234567890', + repo: {id: 200, full_name: 'attacker/fork'} + }, + merge_commit_sha: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + } + } + + it('allows the default self-checkout on a fork pull_request_target', async () => { + const originalEvent = github.context.eventName + const originalPayload = github.context.payload + try { + github.context.eventName = 'pull_request_target' + github.context.payload = forkPayload as any + // Simulate a rebase/fast-forward merge where the base tip (event SHA) + // equals the PR head SHA. The default self-checkout must still succeed. + github.context.sha = '1234567890123456789012345678901234567890' + const settings: IGitSourceSettings = await inputHelper.getInputs() + expect(settings.commit).toBe('1234567890123456789012345678901234567890') + } finally { + github.context.eventName = originalEvent + github.context.payload = originalPayload + } + }) + + it('refuses an explicit fork repository on pull_request_target', async () => { + const originalEvent = github.context.eventName + const originalPayload = github.context.payload + try { + github.context.eventName = 'pull_request_target' + github.context.payload = forkPayload as any + inputs.repository = 'attacker/fork' + await expect(inputHelper.getInputs()).rejects.toThrow( + /Refusing to check out fork pull request code/ + ) + } finally { + github.context.eventName = originalEvent + github.context.payload = originalPayload + } + }) + }) }) |
