mirror of
https://github.com/actions/checkout.git
synced 2026-12-03 18:00:06 +00:00
Scope workflow history verification to the checkout server
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot App
parent
57c9bdfe25
commit
b1df8e93a6
@@ -175,6 +175,91 @@ describe('input-helper tests', () => {
|
||||
expect(settings.workflowOrganizationId).toBe(123456)
|
||||
})
|
||||
|
||||
describe('workflow checkout server', () => {
|
||||
const originalServerUrl = process.env['GITHUB_SERVER_URL']
|
||||
const originalEventName = github.context.eventName
|
||||
const originalPayload = github.context.payload
|
||||
const workflowSha = '1234567890123456789012345678901234567890'
|
||||
const ancestorSha = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
|
||||
const mockCompareCommits = jest.fn()
|
||||
|
||||
beforeEach(() => {
|
||||
process.env['GITHUB_SERVER_URL'] = 'https://github.com'
|
||||
github.context.eventName = 'workflow_run'
|
||||
github.context.payload = {
|
||||
repository: {id: 100, name: 'some-repo', owner: {login: 'some-owner'}},
|
||||
workflow_run: {
|
||||
event: 'pull_request',
|
||||
head_repository: {id: 200, full_name: 'fork-owner/some-repo'},
|
||||
head_sha: 'cccccccccccccccccccccccccccccccccccccccc'
|
||||
}
|
||||
}
|
||||
inputs.token = 'checkout-token'
|
||||
inputs.ref = ancestorSha
|
||||
mockCompareCommits.mockReset()
|
||||
mockCompareCommits.mockResolvedValue({
|
||||
data: {
|
||||
base_commit: {sha: workflowSha},
|
||||
merge_base_commit: {sha: ancestorSha}
|
||||
}
|
||||
})
|
||||
jest.spyOn(github, 'getOctokit').mockReturnValue({
|
||||
rest: {repos: {compareCommitsWithBasehead: mockCompareCommits}}
|
||||
} as any)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
github.context.eventName = originalEventName
|
||||
github.context.payload = originalPayload
|
||||
jest.mocked(github.getOctokit).mockRestore()
|
||||
if (originalServerUrl === undefined) {
|
||||
delete process.env['GITHUB_SERVER_URL']
|
||||
} else {
|
||||
process.env['GITHUB_SERVER_URL'] = originalServerUrl
|
||||
}
|
||||
})
|
||||
|
||||
it.each([
|
||||
'https://other.example.com',
|
||||
'http://github.com',
|
||||
'https://github.com:8443'
|
||||
])(
|
||||
'skips workflow history on another server origin: %s',
|
||||
async serverUrl => {
|
||||
inputs['github-server-url'] = serverUrl
|
||||
|
||||
await expect(inputHelper.getInputs()).resolves.toMatchObject({
|
||||
commit: ancestorSha
|
||||
})
|
||||
expect(github.getOctokit).not.toHaveBeenCalled()
|
||||
expect(mockCompareCommits).not.toHaveBeenCalled()
|
||||
}
|
||||
)
|
||||
|
||||
it.each([
|
||||
[
|
||||
'https://github.example.com',
|
||||
'https://GITHUB.EXAMPLE.COM:443/',
|
||||
'https://github.example.com/api/v3'
|
||||
],
|
||||
['https://org.ghe.com', 'https://org.ghe.com/', 'https://api.org.ghe.com']
|
||||
])(
|
||||
'uses the checkout API URL for workflow history on %s',
|
||||
async (workflowServer, checkoutServer, apiUrl) => {
|
||||
process.env['GITHUB_SERVER_URL'] = workflowServer
|
||||
inputs['github-server-url'] = checkoutServer
|
||||
|
||||
await expect(inputHelper.getInputs()).resolves.toMatchObject({
|
||||
commit: ancestorSha
|
||||
})
|
||||
expect(github.getOctokit).toHaveBeenCalledWith('checkout-token', {
|
||||
baseUrl: apiUrl
|
||||
})
|
||||
expect(mockCompareCommits).toHaveBeenCalledTimes(1)
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
describe('unsafe PR checkout guard', () => {
|
||||
const forkPayload = {
|
||||
repository: {id: 100},
|
||||
|
||||
Reference in New Issue
Block a user