-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
106 additions
and
10 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import request from "supertest"; | ||
import { beforeEach, describe, expect, it } from "vitest"; | ||
|
||
import type { Build, Project } from "@/database/models/index.js"; | ||
import { factory, setupDatabase } from "@/database/testing/index.js"; | ||
|
||
import { createTestHandlerApp } from "../test-util"; | ||
import { getAuthProject } from "./getAuthProject"; | ||
|
||
const app = createTestHandlerApp(getAuthProject); | ||
|
||
describe("getAuthProject", () => { | ||
let project: Project; | ||
let builds: Build[]; | ||
|
||
beforeEach(async () => { | ||
await setupDatabase(); | ||
project = await factory.Project.create({ | ||
token: "the-awesome-token", | ||
}); | ||
builds = await factory.Build.createMany(3, { | ||
projectId: project.id, | ||
name: "default", | ||
}); | ||
// Sort builds by id desc | ||
builds.sort((a: Build, b: Build) => b.id.localeCompare(a.id)); | ||
}); | ||
|
||
describe("without a valid token", () => { | ||
it("returns 401 status code", async () => { | ||
await request(app) | ||
.get("/project") | ||
.set("Authorization", "Bearer invalid-token") | ||
Check failure Code scanning / CodeQL Hard-coded credentials Critical
The hard-coded value "Bearer invalid-token" is used as
authorization header Error loading related location Loading |
||
.expect((res) => { | ||
expect(res.text).toBe( | ||
`Project not found in Argos. If the issue persists, verify your token. (token: "invalid-token").`, | ||
); | ||
}) | ||
.expect(401); | ||
}); | ||
}); | ||
|
||
it("returns a project", async () => { | ||
await request(app) | ||
.get("/project") | ||
.set("Authorization", "Bearer the-awesome-token") | ||
Check failure Code scanning / CodeQL Hard-coded credentials Critical
The hard-coded value "Bearer the-awesome-token" is used as
authorization header Error loading related location Loading |
||
.expect(200) | ||
.expect((res) => { | ||
expect(res.body).toEqual({ | ||
id: project.id, | ||
defaultBaseBranch: "main", | ||
}); | ||
}); | ||
}); | ||
}); |
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,19 @@ | ||
import { repoAuth } from "@/web/middlewares/repoAuth.js"; | ||
import { boom } from "@/web/util.js"; | ||
|
||
import { CreateAPIHandler } from "../util.js"; | ||
|
||
export const getAuthProject: CreateAPIHandler = ({ get }) => { | ||
return get("/project", repoAuth, async (req, res) => { | ||
if (!req.authProject) { | ||
throw boom(401, "Unauthorized"); | ||
} | ||
|
||
const referenceBranch = await req.authProject.$getReferenceBranch(); | ||
|
||
res.send({ | ||
id: req.authProject.id, | ||
defaultBaseBranch: referenceBranch, | ||
}); | ||
}); | ||
}; |
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