Skip to content

Commit d493db5

Browse files
committed
use uuidValidate
1 parent ae50fbd commit d493db5

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

components/server/src/api/auth-provider-service-api.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
import { AuthProviderService } from "../auth/auth-provider-service";
2626
import { AuthProviderEntry, AuthProviderInfo } from "@gitpod/gitpod-protocol";
2727
import { Unauthenticated } from "./unauthenticated";
28+
import { validate as uuidValidate } from "uuid";
2829

2930
@injectable()
3031
export class AuthProviderServiceAPI implements ServiceImpl<typeof AuthProviderServiceInterface> {
@@ -37,10 +38,10 @@ export class AuthProviderServiceAPI implements ServiceImpl<typeof AuthProviderSe
3738
request: CreateAuthProviderRequest,
3839
context: HandlerContext,
3940
): Promise<CreateAuthProviderResponse> {
40-
const ownerId = request.owner.case === "ownerId" ? request.owner.value : undefined;
41-
const organizationId = request.owner.case === "organizationId" ? request.owner.value : undefined;
41+
const ownerId = request.owner.case === "ownerId" ? request.owner.value : "";
42+
const organizationId = request.owner.case === "organizationId" ? request.owner.value : "";
4243

43-
if (!organizationId && !ownerId) {
44+
if (!uuidValidate(organizationId) && !uuidValidate(ownerId)) {
4445
throw new ConnectError("organizationId or ownerId is required", Code.InvalidArgument);
4546
}
4647

@@ -87,10 +88,10 @@ export class AuthProviderServiceAPI implements ServiceImpl<typeof AuthProviderSe
8788
context: HandlerContext,
8889
): Promise<ListAuthProvidersResponse> {
8990
const target = request.id;
90-
const ownerId = target.case === "userId" ? target.value : undefined;
91-
const organizationId = target.case === "organizationId" ? target.value : undefined;
91+
const ownerId = target.case === "userId" ? target.value : "";
92+
const organizationId = target.case === "organizationId" ? target.value : "";
9293

93-
if (!organizationId && !ownerId) {
94+
if (!uuidValidate(organizationId) && !uuidValidate(ownerId)) {
9495
throw new ConnectError("organizationId or ownerId is required", Code.InvalidArgument);
9596
}
9697

0 commit comments

Comments
 (0)