Ignore a .git suffix when matching checkout repositories

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Francesco Renzi
2026-12-04 11:13:15 +01:00
parent 5a9e0139f1
commit 830bba2f1c
3 changed files with 68 additions and 4 deletions

View File

@@ -187,6 +187,30 @@ describe('unsafe-pr-checkout-helper', () => {
).toThrow()
})
it('refuses pull_request_target when repository points at the fork with a .git suffix', () => {
setContext('pull_request_target', forkPullRequestTargetPayload())
expect(() =>
assertSafePrCheckout({
qualifiedRepository: `${FORK_QUALIFIED_REPO}.git`,
ref: 'refs/heads/main',
commit: '',
allowUnsafePrCheckout: false
})
).toThrow()
})
it('strips only one .git suffix from the repository', () => {
setContext('pull_request_target', forkPullRequestTargetPayload())
expect(() =>
assertSafePrCheckout({
qualifiedRepository: `${FORK_QUALIFIED_REPO}.git.git`,
ref: 'refs/heads/main',
commit: '',
allowUnsafePrCheckout: false
})
).not.toThrow()
})
it('allows pull_request_target checkout of an unrelated third-party repo', () => {
setContext('pull_request_target', forkPullRequestTargetPayload())
expect(() =>
@@ -309,6 +333,33 @@ describe('unsafe-pr-checkout-helper', () => {
})
})
it('verifies a workflow_run pin on the workflow repository with a .git suffix', async () => {
setContext('workflow_run', forkWorkflowRunPayload())
github.context.sha = SAFE_BASE_SHA
mockCompareCommits.mockResolvedValue({
data: {
base_commit: {sha: SAFE_BASE_SHA},
merge_base_commit: {sha: '5555555555555555555555555555555555555555'}
}
})
await expect(
assertSafePrCheckout(
{
qualifiedRepository: `${BASE_QUALIFIED_REPO}.git`,
ref: '',
commit: PR_MERGE_SHA,
allowUnsafePrCheckout: false
},
'checkout-token'
)
).rejects.toThrow(/Refusing to check out the requested commit/)
expect(mockCompareCommits).toHaveBeenCalledWith(
expect.objectContaining({owner: 'some-owner', repo: 'some-repo'})
)
})
it('allows a workflow_run pin verified in workflow history', async () => {
setContext('workflow_run', forkWorkflowRunPayload())
github.context.sha = SAFE_BASE_SHA