Refactor of OAuth account linking flows (#12246)

* Refactor of OAuth account linking flows

* PR feedback
This commit is contained in:
Tom Moor authored and GitHub committed 2026-05-02 18:54:38 -04:00
1 parent 8c716b173a
commit f50bb00b29
30 files changed
+590 -84

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
import { buildUser } from "@server/test/factories";
import { getTestServer } from "@server/test/support";
import { SetupAction } from "./schema";
const server = getTestServer();
describe("#github.callback", () => {
it("should reject callback when state nonce does not match cookie", async () => {
const user = await buildUser();
const state = JSON.stringify({
teamId: user.teamId,
nonce: "attacker-nonce",
});
const res = await server.get(
`/api/github.callback?state=${encodeURIComponent(
state
)}&code=123&setup_action=${SetupAction.install}&installation_id=1&token=${user.getJwtToken()}`,
{ redirect: "manual" }
);
const body = await res.json();
expect(res.status).toEqual(400);
expect(body.error).toEqual("state_mismatch");
});
it("should reject callback when nonce is missing from state", async () => {
const user = await buildUser();
const state = JSON.stringify({ teamId: user.teamId });
const res = await server.get(
`/api/github.callback?state=${encodeURIComponent(
state
)}&code=123&setup_action=${SetupAction.install}&installation_id=1&token=${user.getJwtToken()}`,
{ redirect: "manual" }
);
expect(res.status).toEqual(400);
});
it("should fail when state is not valid JSON", async () => {
const user = await buildUser();
const res = await server.get(
`/api/github.callback?state=bad&code=123&setup_action=${SetupAction.install}&installation_id=1&token=${user.getJwtToken()}`,
{ redirect: "manual" }
);
expect(res.status).toEqual(400);
});
});