Skip to content

Commit d806ff5

Browse files
fix: final review — userResponse error handling and org-scoped access
- checkGitlabMemberPermissions: throw on non-ok userResponse (previously silently swallowed API failures for the username lookup) - gitlab.one tRPC: relax ownership check to org-scoped only (remove userId constraint so all org members can access shared providers, consistent with how gitlabProviders filters results) - Add test: userResponse 503 throws with clear error message Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1c4d6a5 commit d806ff5

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

apps/dokploy/__test__/utils/gitlab-preview-utils.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,21 @@ describe("checkGitlabMemberPermissions", () => {
140140
expect(result).toEqual({ hasWriteAccess: false, accessLevel: null });
141141
});
142142

143+
it("throws when the user lookup API call fails (non-ok response)", async () => {
144+
vi.stubGlobal(
145+
"fetch",
146+
vi.fn().mockResolvedValueOnce({
147+
ok: false,
148+
status: 503,
149+
statusText: "Service Unavailable",
150+
}),
151+
);
152+
153+
await expect(
154+
checkGitlabMemberPermissions(FAKE_GITLAB_ID, 123, "anyuser"),
155+
).rejects.toThrow("Failed to resolve GitLab user");
156+
});
157+
143158
it("returns hasWriteAccess=false when the username lookup returns no users", async () => {
144159
// GitLab /users?username=ghost returns [] when user does not exist
145160
vi.stubGlobal(

apps/dokploy/server/api/routers/gitlab.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ export const gitlabRouter = createTRPCRouter({
5555
.query(async ({ input, ctx }) => {
5656
const result = await findGitlabById(input.gitlabId);
5757
if (
58-
result.gitProvider.organizationId !==
59-
ctx.session.activeOrganizationId ||
60-
result.gitProvider.userId !== ctx.session.userId
58+
result.gitProvider.organizationId !== ctx.session.activeOrganizationId
6159
) {
6260
throw new TRPCError({ code: "FORBIDDEN", message: "Access denied" });
6361
}

packages/server/src/utils/providers/gitlab.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,13 @@ export const checkGitlabMemberPermissions = async (
275275
`${baseUrl}/api/v4/users?username=${encodeURIComponent(username)}`,
276276
{ headers: { Authorization: `Bearer ${gitlabProvider.accessToken}` } },
277277
);
278+
279+
if (!userResponse.ok) {
280+
throw new Error(
281+
`Failed to resolve GitLab user: ${userResponse.statusText}`,
282+
);
283+
}
284+
278285
const users = await userResponse.json();
279286
const userId = users[0]?.id;
280287

0 commit comments

Comments
 (0)