-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an unlocking endpoint for admins to fix failed uploads.
- Loading branch information
Showing
5 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import * as auth from "./utils/permissions.js"; | ||
import * as lock from "./utils/lock.js"; | ||
|
||
export async function unlockProjectHandler(request, env, nonblockers) { | ||
let token = auth.extractBearerToken(request); | ||
await auth.checkAdminPermissions(token, env, nonblockers); | ||
let project = decodeURIComponent(request.params.project); | ||
await lock.unlockProject(project, env); | ||
return new Response(null, { status: 200 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as lock from "../src/utils/lock.js"; | ||
import * as lckh from "../src/lock.js"; | ||
import * as gh from "../src/utils/github.js"; | ||
import * as setup from "./setup.js"; | ||
import * as pkeys from "../src/utils/internal.js"; | ||
|
||
beforeAll(async () => { | ||
const env = getMiniflareBindings(); | ||
await setup.simpleMockProject(env); | ||
let rigging = gh.enableTestRigging(); | ||
setup.mockGitHubIdentities(rigging); | ||
}) | ||
|
||
test("unlockProjectHandler works correctly", async () => { | ||
const env = getMiniflareBindings(); | ||
|
||
let req = new Request("http://localhost", { | ||
method: "DELETE", | ||
headers: { "Content-Type": "application/json" } | ||
}); | ||
req.headers.set("Authorization", "Bearer " + setup.mockTokenAdmin); | ||
req.params = { project: "test" }; | ||
|
||
// Unlocking works if it's not locked. | ||
expect((await lckh.unlockProjectHandler(req, env, [])).status).toBe(200); | ||
expect(await env.BOUND_BUCKET.head(pkeys.lock("test"))).toBeNull() | ||
|
||
// Unlocking works if it's locked. | ||
await lock.lockProject("test", "whee", "bar", "SESSION_KEY", env) | ||
expect((await lckh.unlockProjectHandler(req, env, [])).status).toBe(200); | ||
expect(await env.BOUND_BUCKET.head(pkeys.lock("test"))).toBeNull() | ||
|
||
// Unlocking works if the project doesn't even exist. | ||
req.params = { project: "test-does-not-exist" }; | ||
expect((await lckh.unlockProjectHandler(req, env, [])).status).toBe(200); | ||
}) | ||
|
||
test("unlockProjectHandler works correctly if user is not authorized", async () => { | ||
const env = getMiniflareBindings(); | ||
let req = new Request("http://localhost", { | ||
method: "DELETE", | ||
headers: { "Content-Type": "application/json" } | ||
}); | ||
req.params = { project: "test" }; | ||
req.headers.set("Authorization", "Bearer " + setup.mockTokenUser); | ||
await setup.expectError(lckh.unlockProjectHandler(req, env, []), "not an administrator"); | ||
}) | ||
|