Skip to content

Commit 9d42ec3

Browse files
Follow-ups from #20269 (#20272)
* Follow-ups from #20269 * `matchesNewWorkspaceIdExactly` to handle `undefined`
1 parent 3f0fc73 commit 9d42ec3

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

components/gitpod-protocol/src/util/gitpod-host-url.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const baseWorkspaceIDRegex =
1616
"(([a-f][0-9a-f]{7}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})|([0-9a-z]{2,16}-[0-9a-z]{2,16}-[0-9a-z]{8,11}))";
1717

1818
// this pattern matches v4 UUIDs as well as the new generated workspace ids (e.g. pink-panda-ns35kd21)
19-
export const workspaceIDRegex = RegExp(`^(?:debug-)?${baseWorkspaceIDRegex}$`);
19+
const workspaceIDRegex = RegExp(`^(?:debug-)?${baseWorkspaceIDRegex}$`);
2020

2121
// this pattern matches URL prefixes of workspaces
2222
const workspaceUrlPrefixRegex = RegExp(`^(([0-9]{4,6}|debug)-)?${baseWorkspaceIDRegex}\\.`);

components/gitpod-protocol/src/util/parse-workspace-id.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,9 @@ export class ParseWorkspaceIdTest {
8181
const actual = matchesNewWorkspaceIdExactly("moccasin-ferret-15599b3");
8282
expect(actual).to.be.false;
8383
}
84+
@test public matchesWorkspaceIdExactly_new_negative_empty() {
85+
const actual = matchesNewWorkspaceIdExactly(undefined);
86+
expect(actual).to.be.false;
87+
}
8488
}
8589
module.exports = new ParseWorkspaceIdTest();

components/gitpod-protocol/src/util/parse-workspace-id.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const parseWorkspaceIdFromHostname = function (hostname: string) {
3333
}
3434
};
3535

36-
/** Equalls UUIDv4 (and REGEX_WORKSPACE_ID_LEGACY!) */
36+
/** Equals UUIDv4 (and REGEX_WORKSPACE_ID_LEGACY!) */
3737
const REGEX_INSTANCE_ID = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;
3838
const REGEX_INSTANCE_ID_EXACT = new RegExp(`^${REGEX_INSTANCE_ID.source}$`);
3939

@@ -49,6 +49,10 @@ export const matchesInstanceIdOrLegacyWorkspaceIdExactly = function (maybeId: st
4949
* @param maybeWorkspaceId
5050
* @returns
5151
*/
52-
export const matchesNewWorkspaceIdExactly = function (maybeWorkspaceId: string): boolean {
52+
export const matchesNewWorkspaceIdExactly = function (maybeWorkspaceId?: string): boolean {
53+
if (!maybeWorkspaceId) {
54+
return false;
55+
}
56+
5357
return REGEX_WORKSPACE_ID_EXACT.test(maybeWorkspaceId);
5458
};

components/server/src/api/workspace-service-api.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,7 @@ import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messag
5858
import { ContextService } from "../workspace/context-service";
5959
import { UserService } from "../user/user-service";
6060
import { ContextParser } from "../workspace/context-parser-service";
61-
import { workspaceIDRegex } from "@gitpod/gitpod-protocol/lib/util/gitpod-host-url";
62-
63-
const isWorkspaceId = (workspaceId?: string) => {
64-
if (!workspaceId) {
65-
return false;
66-
}
67-
68-
return workspaceIDRegex.test(workspaceId);
69-
};
61+
import { matchesNewWorkspaceIdExactly as isWorkspaceId } from "@gitpod/gitpod-protocol/lib/util/parse-workspace-id";
7062

7163
@injectable()
7264
export class WorkspaceServiceAPI implements ServiceImpl<typeof WorkspaceServiceInterface> {

components/server/src/authorization/spicedb-authorizer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export class SpiceDBAuthorizer {
105105
const permitted = response.permissionship === v1.CheckPermissionResponse_Permissionship.HAS_PERMISSION;
106106
return { permitted, checkedAt: response.checkedAt?.token };
107107
} catch (err) {
108+
// we should not consider users supplying invalid requests as internal server errors
108109
if (isGrpcError(err) && err.code === grpc.status.INVALID_ARGUMENT) {
109110
throw new ApplicationError(ErrorCodes.BAD_REQUEST, `Invalid request for permission check: ${err}`);
110111
}

0 commit comments

Comments
 (0)