Skip to content

Commit 958519c

Browse files
committed
tests: verify that only allowed repositories can trigger workflows
Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 5d3699c commit 958519c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

__tests__/index.test.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ const crypto = require('crypto')
33
const stream = require('stream')
44
const https = require('https')
55

6+
afterEach(() => {
7+
jest.clearAllMocks();
8+
})
9+
610
process.env['GITHUB_WEBHOOK_SECRET'] = 'for-testing'
711
process.env['GITGITGADGET_TRIGGER_TOKEN'] = 'token-for-testing'
812

@@ -84,8 +88,12 @@ const makeContext = (body, headers) => {
8488
}
8589
}
8690

87-
const testIssueComment = (comment, fn) => {
88-
const repoOwner = 'gitgitgadget'
91+
const testIssueComment = (comment, repoOwner, fn) => {
92+
if (!fn) {
93+
fn = repoOwner
94+
repoOwner = undefined
95+
}
96+
repoOwner ||= 'gitgitgadget'
8997
const number = 0x70756c6c
9098
const context = makeContext({
9199
action: 'created',
@@ -140,3 +148,13 @@ testIssueComment('/test', async (context) => {
140148
})
141149
expect(mockRequest.end).toHaveBeenCalledTimes(1)
142150
})
151+
152+
testIssueComment('/verify-repository', 'nope', (context) => {
153+
expect(context.done).toHaveBeenCalledTimes(1)
154+
expect(context.res).toEqual({
155+
body: 'Refusing to work on a repository other than gitgitgadget/git or git/git',
156+
'status': 403,
157+
})
158+
expect(mockRequest.write).not.toHaveBeenCalled()
159+
expect(mockRequest.end).not.toHaveBeenCalled()
160+
})

0 commit comments

Comments
 (0)