Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions apps/server/src/auth/RpcAuthorization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
DEFAULT_SERVER_SETTINGS,
ProviderDriverKind,
ProviderInstanceId,
ProjectId,
IssueTrackerKind,
SecretProviderId,
ThreadId,
AuthOrchestrationOperateScope,
Expand Down Expand Up @@ -144,6 +146,57 @@ describe("RPC scope middleware", () => {
);
});

it.effect("allows issue reads but requires a source-control grant before commenting", () =>
Effect.gen(function* () {
const tested = [WS_METHODS.issuesList, WS_METHODS.issuesComment] as const;
const group = WsRpcGroup.omit(
...[...WsRpcGroup.requests.keys()].filter(
(tag): tag is Exclude<keyof typeof RPC_REQUIRED_SCOPES, (typeof tested)[number]> =>
!(tested as ReadonlyArray<string>).includes(tag),
),
);
const comments: string[] = [];
const handlers = Layer.mergeAll(
group.toLayerHandler(WS_METHODS.issuesList, () =>
Effect.succeed({ entries: [], trackers: [], errors: [], viewers: {}, nextCursors: {} }),
),
group.toLayerHandler(WS_METHODS.issuesComment, ({ body }) =>
Effect.sync(() => {
comments.push(body);
}),
),
);
const reader = yield* RpcTest.makeClient(group).pipe(
Effect.provide(Layer.merge(handlers, RpcAuthorization.layer([AuthOrchestrationReadScope]))),
);
const comment = {
projectId: ProjectId.make("web"),
tracker: IssueTrackerKind.make("github"),
scope: "acme/web",
key: "42",
body: "Repro attached.",
};

expect((yield* reader[WS_METHODS.issuesList]({ state: "open" })).entries).toEqual([]);
expect(yield* reader[WS_METHODS.issuesComment](comment).pipe(Effect.flip)).toMatchObject({
_tag: "EnvironmentAuthorizationError",
requiredPermission: AuthSourceControlWriteScope,
});
expect(comments).toEqual([]);

const writer = yield* RpcTest.makeClient(group).pipe(
Effect.provide(
Layer.merge(
handlers,
RpcAuthorization.layer([AuthOrchestrationReadScope, AuthSourceControlWriteScope]),
),
),
);
yield* writer[WS_METHODS.issuesComment](comment);
expect(comments).toEqual(["Repro attached."]);
}).pipe(Effect.scoped),
);

it.effect.each([WS_METHODS.subscribeVcsBranch, WS_METHODS.subscribeVcsStatus] as const)(
"enforces read permission on stream %s",
(method) =>
Expand Down
5 changes: 5 additions & 0 deletions apps/server/src/auth/RpcAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ export const RPC_REQUIRED_SCOPES = {
[WS_METHODS.pullRequestsStack]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsLinkedThreads]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsDetail]: AuthOrchestrationReadScope,
[WS_METHODS.issuesList]: AuthOrchestrationReadScope,
[WS_METHODS.issuesDetail]: AuthOrchestrationReadScope,
[WS_METHODS.issuesComments]: AuthOrchestrationReadScope,
[WS_METHODS.issuesTemplates]: AuthOrchestrationReadScope,
[WS_METHODS.issuesCandidates]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsPreview]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsChecks]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsActivity]: AuthOrchestrationReadScope,
Expand Down
Loading
Loading