mirror of
https://github.com/outline/outline.git
synced 2026-11-22 05:51:43 +03:00
fix: Require GitHub account ownership when connecting an installation (#14323)
This commit is contained in:
1 parent
b0b307259a
commit
71af4d6901
6 files changed
+304
-15
No files matched your search
@@ -1,10 +1,54 @@
|
||||
import { buildUser, buildViewer } from "@server/test/factories";
|
||||
import { IntegrationService } from "@shared/types";
|
||||
import { Integration } from "@server/models";
|
||||
import { buildAdmin, buildUser, buildViewer } from "@server/test/factories";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
import { GitHub, InstallationAccess } from "../github";
|
||||
import { SetupAction } from "./schema";
|
||||
|
||||
const server = getTestServer();
|
||||
|
||||
describe("#github.callback", () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("should reject an installation the user cannot manage", async () => {
|
||||
const user = await buildAdmin();
|
||||
const state = JSON.stringify({ teamId: user.teamId, nonce: "nonce" });
|
||||
const client = {
|
||||
requestAppInstallations: async () => [
|
||||
{ id: 1, permissions: { issues: "read" }, account: null },
|
||||
],
|
||||
} as unknown as Awaited<ReturnType<typeof GitHub.authenticateAsUser>>;
|
||||
vi.spyOn(GitHub, "authenticateAsUser").mockResolvedValue(client);
|
||||
const spy = vi
|
||||
.spyOn(GitHub, "canManageInstallation")
|
||||
.mockResolvedValue(InstallationAccess.Denied);
|
||||
|
||||
const res = await server.get(
|
||||
`/api/github.callback?state=${encodeURIComponent(
|
||||
state
|
||||
)}&code=123&setup_action=${SetupAction.install}&installation_id=1`,
|
||||
user,
|
||||
{
|
||||
redirect: "manual",
|
||||
headers: { Cookie: "githubOAuthNonce=nonce" },
|
||||
}
|
||||
);
|
||||
|
||||
expect(res.status).toEqual(302);
|
||||
expect(res.headers.get("location")).toContain("error=denied");
|
||||
expect(spy).toHaveBeenCalledWith(
|
||||
client,
|
||||
expect.objectContaining({ id: 1 })
|
||||
);
|
||||
expect(
|
||||
await Integration.count({
|
||||
where: { teamId: user.teamId, service: IntegrationService.GitHub },
|
||||
})
|
||||
).toEqual(0);
|
||||
});
|
||||
|
||||
it("should reject callback when state cookie is missing", async () => {
|
||||
const user = await buildUser();
|
||||
const state = JSON.stringify({
|
||||
|
||||
Reference in new issue
Block a user