-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopencode-authorize-actor.test.mjs
More file actions
40 lines (35 loc) · 1.41 KB
/
Copy pathopencode-authorize-actor.test.mjs
File metadata and controls
40 lines (35 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import assert from "node:assert/strict"
import test from "node:test"
import { authorizeActor } from "./opencode-authorize-actor.mjs"
const event = { comment: { user: { login: "trusted-user" } } }
const options = {
apiUrl: "https://api.github.test",
mode: "build",
repository: "owner/repo",
repositoryOwner: "owner",
token: "token",
}
function response(permission, username = "trusted-user") {
return async (url) => ({
ok: true,
status: 200,
json: async () => {
assert.equal(url, `https://api.github.test/repos/owner/repo/collaborators/${username}/permission`)
return { permission }
},
})
}
test("authorizes only repository write and admin access", async () => {
await assert.doesNotReject(() => authorizeActor(event, { ...options, fetchImpl: response("write") }))
await assert.doesNotReject(() => authorizeActor(event, { ...options, fetchImpl: response("admin") }))
await assert.rejects(() => authorizeActor(event, { ...options, fetchImpl: response("read") }), /write or admin/)
})
test("limits plan mode to the repository owner", async () => {
await assert.rejects(
() => authorizeActor(event, { ...options, mode: "plan", repositoryOwner: "owner", fetchImpl: response("write") }),
/repository owner/,
)
await assert.doesNotReject(
() => authorizeActor({ comment: { user: { login: "owner" } } }, { ...options, mode: "plan", fetchImpl: response("write", "owner") }),
)
})