@jskit-ai/workspaces-core 0.2.57 → 0.2.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -0
- package/locales/en.json +0 -1
- package/package.json +9 -9
- package/src/server/common/services/workspaceDirectoryService.js +14 -7
- package/src/server/common/services/workspaceMemberContext.js +3 -3
- package/test/repositories.integration.test.js +6 -7
- package/test/workspaceDirectoryService.mysql.test.js +4 -3
- package/test/workspaceMemberListRoutes.test.js +1 -1
- package/test/workspaceRequestContextQueries.test.js +51 -10
- package/test/workspaceService.test.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- **Behaviour change:** a workspace the signed-in person is no active member of (never one, removed, inactive, or no user at all) is answered as one that doesn't exist: 404 `workspaces.workspace.notFound` ("Workspace not found."), where it was 403 `workspaces.workspace.accessDenied` ("You do not have access to this workspace."), on every route whose surface requires membership, in the bootstrap's `requestedWorkspace` (`status: "not_found"`, where it was `"forbidden"`) and from `memberContext`. Someone outside a workspace could tell an existing workspace's slug from a typo by the answer; now the two answers are identical. `workspaces.workspace.accessDenied` is gone from the catalog. A surface with `requireWorkspaceMembership: false` still resolves the workspace for a non-member, and a member without a route's permission is still 403.
|
|
5
6
|
- `workspaces_core_initial-collation`, a migration Knex runs just before `workspaces_core_initial` (run `npm run db:migrate`): on MySQL and MariaDB it creates the workspace tables, where they do not exist yet, in the collation of the existing tables (`workspaces`, then `users`, then `auth_local_users`) rather than the database's default, and converts one recorded in another collation when no character can be lost. It changes nothing where they match.
|
|
6
7
|
- `workspaces.transferOwnership({ workspaceId, toUserId, previousOwnerRoleSid = "admin" }, options)` hands a workspace to another of its active members, in the caller's transaction when `options` carries one and in one of its own otherwise. It locks the workspace's row and reads the workspace through that lock, then locks the new and the previous owner's memberships in one locking read, so two transfers of one workspace take turns and the second moves it on from the owner the first left. `owner_user_id` becomes `toUserId` and `updatedAt` moves; the new owner's membership takes the `owner` role; the previous owner's takes `previousOwnerRoleSid` and stays active, or is created active with it when they had none. A personal workspace stops being personal (`is_personal` false): the new owner's own personal workspace stays theirs, and where personal workspaces are provisioned the previous owner is given a new one at their next provisioning. A `toUserId` who already owns it writes nothing and answers `changed: false`. A missing or deleted workspace is 404 `workspaces.workspace.notFound` and a `toUserId` with no active membership 409 `workspaces.member.newOwnerNotActive` (new, "The new owner must be an active member of the workspace."), with nothing written; ids that are no record ids and a `previousOwnerRoleSid` that is not the text of a role other than `owner` are a TypeError before any statement. It answers the workspace as `findById` answers it, plus `previousOwnerUserId` and `changed`, sends the same statements however many members the workspace has, and publishes no event: an application keeping its own copy of workspace facts updates it from the answer.
|
|
7
8
|
- `createStandaloneRoleContext({ resources, config })` (`@jskit-ai/workspaces-core/server/standaloneRoleContext`) gives code outside a JSKIT server, such as a migration or seed script that owns its tables through `createStandaloneResources`, `workspaces.core`'s `roleContext`: the same function, built by the same code (`createWorkspaceDirectory`, which `createWorkspacesRuntime` now uses too) from the application's runtime config, on the handles of the script's standalone runtime, which owns `ROLE_CONTEXT_TABLES` (the workspaces and users tables, exported beside it) with its own tables: `createStandaloneResources({ knex, feature, owns: [...ROLE_CONTEXT_TABLES, ...seedTables], systemScope })`. It takes the same arguments, answers the same context and refuses the same calls, with the script's own system context; resources that lack one of those tables are a `TypeError` naming them. On a server's Knex client `createStandaloneResources` refuses those tables (`DuplicateOwnerError`): code there takes `workspaces.core`'s.
|
package/locales/en.json
CHANGED
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"contextDisabled": "Workspace context is disabled.",
|
|
13
13
|
"slugRequired": "workspaceSlug is required.",
|
|
14
14
|
"notFound": "Workspace not found.",
|
|
15
|
-
"accessDenied": "You do not have access to this workspace.",
|
|
16
15
|
"avatarUrlInvalid": "Workspace avatar URL must be a valid absolute URL (http:// or https://)."
|
|
17
16
|
},
|
|
18
17
|
"member": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/workspaces-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.58",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"./locales/en.json": "./locales/en.json"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@jskit-ai/resource-core": "0.1.
|
|
28
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
29
|
-
"@jskit-ai/users-core": "0.2.
|
|
27
|
+
"@jskit-ai/resource-core": "0.1.221",
|
|
28
|
+
"@jskit-ai/resource-crud-core": "0.1.223",
|
|
29
|
+
"@jskit-ai/users-core": "0.2.58",
|
|
30
30
|
"json-rest-schema": "^1.0.20"
|
|
31
31
|
},
|
|
32
32
|
"description": "Workspace tenancy runtime plus HTTP routes, role catalog, and workspace config scaffolding.",
|
|
@@ -216,10 +216,10 @@
|
|
|
216
216
|
}
|
|
217
217
|
},
|
|
218
218
|
"peerDependencies": {
|
|
219
|
-
"@jskit-ai/auth-core": "0.2.
|
|
220
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
221
|
-
"@jskit-ai/http-runtime": "0.2.
|
|
222
|
-
"@jskit-ai/kernel": "0.2.
|
|
223
|
-
"@jskit-ai/resource-runtime": "0.2.
|
|
219
|
+
"@jskit-ai/auth-core": "0.2.34",
|
|
220
|
+
"@jskit-ai/database-runtime": "0.1.280",
|
|
221
|
+
"@jskit-ai/http-runtime": "0.2.30",
|
|
222
|
+
"@jskit-ai/kernel": "0.2.30",
|
|
223
|
+
"@jskit-ai/resource-runtime": "0.2.44"
|
|
224
224
|
}
|
|
225
225
|
}
|
|
@@ -36,6 +36,10 @@ function buildWorkspaceBaseSlug(user) {
|
|
|
36
36
|
return "workspace";
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
function workspaceNotFound() {
|
|
40
|
+
return new AppError(404, "Workspace not found.", { code: "workspaces.workspace.notFound" });
|
|
41
|
+
}
|
|
42
|
+
|
|
39
43
|
/**
|
|
40
44
|
* The `workspaces.personal-workspace-name` default: the user's display name or
|
|
41
45
|
* email, followed by "'s Workspace".
|
|
@@ -256,7 +260,8 @@ function createService({
|
|
|
256
260
|
const requestWorkspaceContexts = new WeakMap();
|
|
257
261
|
|
|
258
262
|
/**
|
|
259
|
-
* A surface that requires membership refuses an anonymous visitor (401) and a non-member
|
|
263
|
+
* A surface that requires membership refuses an anonymous visitor (401), and a non-member as it refuses a slug no
|
|
264
|
+
* workspace has (404), so its answer never tells someone outside a workspace that it exists; one that does not (a
|
|
260
265
|
* public payment link) resolves the workspace for them with no membership and no permissions.
|
|
261
266
|
* @param {{ id?: unknown } | null} user
|
|
262
267
|
* @param {string} workspaceSlug
|
|
@@ -271,9 +276,11 @@ function createService({
|
|
|
271
276
|
return requireMembership ? requireMember(workspaceContext) : workspaceContext;
|
|
272
277
|
}
|
|
273
278
|
|
|
279
|
+
// Someone who is no active member of a workspace (removed, inactive, never one, or no user at all) is told it is not
|
|
280
|
+
// found, exactly as for a slug or id no workspace has: a refusal of its own would tell them the workspace exists.
|
|
274
281
|
function requireMember(workspaceContext) {
|
|
275
282
|
if (!workspaceContext.membership) {
|
|
276
|
-
throw
|
|
283
|
+
throw workspaceNotFound();
|
|
277
284
|
}
|
|
278
285
|
return workspaceContext;
|
|
279
286
|
}
|
|
@@ -298,9 +305,9 @@ function createService({
|
|
|
298
305
|
/**
|
|
299
306
|
* The workspace context of one member of the workspace with this id, for background work done as that member: what
|
|
300
307
|
* resolveWorkspaceContextForUserBySlug resolves for the member's request on a surface that requires membership, by
|
|
301
|
-
* the same reads and checks. A deleted or missing workspace is
|
|
302
|
-
*
|
|
303
|
-
*
|
|
308
|
+
* the same reads and checks. A deleted or missing workspace, and a user who is no active member of it (removed,
|
|
309
|
+
* inactive, never one, or no user at all), are 404 `workspaces.workspace.notFound`, as an unknown slug is; the owner's
|
|
310
|
+
* membership is ensured, as at the owner's request.
|
|
304
311
|
* @param {{ id?: unknown } | null} user
|
|
305
312
|
* @param {unknown} workspaceId
|
|
306
313
|
* @param {object} [options]
|
|
@@ -327,7 +334,7 @@ function createService({
|
|
|
327
334
|
requireWorkspaceContext();
|
|
328
335
|
const workspace = await workspacesRepository.findById(workspaceId, options);
|
|
329
336
|
if (!workspace || workspace.deletedAt) {
|
|
330
|
-
throw
|
|
337
|
+
throw workspaceNotFound();
|
|
331
338
|
}
|
|
332
339
|
return {
|
|
333
340
|
workspace,
|
|
@@ -356,7 +363,7 @@ function createService({
|
|
|
356
363
|
// with its role's permissions, and the settings: every workspace context, a request's and a member's, is this one.
|
|
357
364
|
async function readWorkspaceContextForUser(user, workspace, options) {
|
|
358
365
|
if (!workspace) {
|
|
359
|
-
throw
|
|
366
|
+
throw workspaceNotFound();
|
|
360
367
|
}
|
|
361
368
|
|
|
362
369
|
const normalizedUserId = normalizeRecordId(user?.id, { fallback: null });
|
|
@@ -68,9 +68,9 @@ function createWorkspaceMemberContexts({ workspaceService, userProfiles, roleCat
|
|
|
68
68
|
*
|
|
69
69
|
* Only a system context makes one (`{ context: systemContext(reason) }`, with `trx` to read in the caller's
|
|
70
70
|
* transaction): any other context, a forWorkspace job's too, is a TypeError, as are ids that are no record ids. A
|
|
71
|
-
* missing or deleted workspace
|
|
72
|
-
*
|
|
73
|
-
*
|
|
71
|
+
* missing or deleted workspace, and a user who is no active member of it (removed, inactive, never one, or no user at
|
|
72
|
+
* all), are 404 `workspaces.workspace.notFound`, as for the member's request; the owner's membership is ensured, as
|
|
73
|
+
* at the owner's request. It reads no sign-in state: an account its
|
|
74
74
|
* auth provider refuses at sign-in is still resolved. An action it runs names the surface the member's request
|
|
75
75
|
* would: `actions.execute({ actionId, input, context: { ...member, surface: "app" } })`.
|
|
76
76
|
* @param {{ workspaceId: unknown, userId: unknown }} member
|
|
@@ -530,7 +530,7 @@ describe(`users and workspaces repositories on migrated ${databaseLabel}`, () =>
|
|
|
530
530
|
});
|
|
531
531
|
});
|
|
532
532
|
|
|
533
|
-
test("memberContext refuses a missing or deleted workspace, a non-member, a removed or inactive membership and a user id naming no one, as the member's request does", async () => {
|
|
533
|
+
test("memberContext refuses a missing or deleted workspace, a non-member, a removed or inactive membership and a user id naming no one, as the member's request does: each as not found", async () => {
|
|
534
534
|
const { directory, memberContext } = memberDirectory();
|
|
535
535
|
const owner = await createProfile("Ada");
|
|
536
536
|
const member = await createProfile("Grace");
|
|
@@ -550,7 +550,6 @@ describe(`users and workspaces repositories on migrated ${databaseLabel}`, () =>
|
|
|
550
550
|
await workspaces.updateById(deleted.id, { deletedAt: new Date().toISOString() });
|
|
551
551
|
const system = { context: memberJobContext() };
|
|
552
552
|
const notFound = [404, "workspaces.workspace.notFound"];
|
|
553
|
-
const accessDenied = [403, "workspaces.workspace.accessDenied"];
|
|
554
553
|
const refuses = ([status, code], label) => (error) => {
|
|
555
554
|
assert.ok(error instanceof AppError, `${label}: ${error}`);
|
|
556
555
|
assert.deepEqual([error.status, error.code], [status, code], label);
|
|
@@ -561,10 +560,10 @@ describe(`users and workspaces repositories on migrated ${databaseLabel}`, () =>
|
|
|
561
560
|
["a workspace id naming no workspace", { workspaceId: "999999", userId: member.id }, notFound, [member, "no-such-workspace"]],
|
|
562
561
|
["a deleted workspace's member", { workspaceId: deleted.id, userId: member.id }, notFound, [member, "gone"]],
|
|
563
562
|
["a deleted workspace's owner", { workspaceId: deleted.id, userId: owner.id }, notFound, [owner, "gone"]],
|
|
564
|
-
["a user who was never a member", { workspaceId: workspace.id, userId: outsider.id },
|
|
565
|
-
["a removed member", { workspaceId: workspace.id, userId: removed.id },
|
|
566
|
-
["an inactive member", { workspaceId: workspace.id, userId: inactive.id },
|
|
567
|
-
["a user id naming no one", { workspaceId: workspace.id, userId: "999999" },
|
|
563
|
+
["a user who was never a member", { workspaceId: workspace.id, userId: outsider.id }, notFound, [outsider, "team"]],
|
|
564
|
+
["a removed member", { workspaceId: workspace.id, userId: removed.id }, notFound, [removed, "team"]],
|
|
565
|
+
["an inactive member", { workspaceId: workspace.id, userId: inactive.id }, notFound, [inactive, "team"]],
|
|
566
|
+
["a user id naming no one", { workspaceId: workspace.id, userId: "999999" }, notFound, [{ id: "999999" }, "team"]]
|
|
568
567
|
];
|
|
569
568
|
for (const [label, asked, refusal, [user, slug]] of refusals) {
|
|
570
569
|
await assert.rejects(memberContext(asked, system), refuses(refusal, label));
|
|
@@ -693,7 +692,7 @@ describe(`users and workspaces repositories on migrated ${databaseLabel}`, () =>
|
|
|
693
692
|
assert.equal(await memberships.findByWorkspaceIdAndUserId(workspace.id, outsider.id), null);
|
|
694
693
|
assert.equal((await memberships.findByWorkspaceIdAndUserId(workspace.id, member.id)).roleSid, "member");
|
|
695
694
|
assert.equal((await memberContext({ workspaceId: workspace.id, userId: member.id }, system)).membership.roleSid, "member");
|
|
696
|
-
await assert.rejects(memberContext({ workspaceId: workspace.id, userId: outsider.id }, system), (error) => error.status ===
|
|
695
|
+
await assert.rejects(memberContext({ workspaceId: workspace.id, userId: outsider.id }, system), (error) => error.status === 404);
|
|
697
696
|
|
|
698
697
|
// A workspace no request has opened has no settings yet, and the role context writes none, nor the owner's
|
|
699
698
|
// membership a member context ensures.
|
|
@@ -179,11 +179,12 @@ test("the workspace context answers a member's workspace, membership, permission
|
|
|
179
179
|
assert.equal(outside.membership, null);
|
|
180
180
|
assert.deepEqual(outside.permissions, []);
|
|
181
181
|
assert.equal(outside.workspace.id, workspace.id);
|
|
182
|
+
// Someone outside the workspace is told it is not found, as for a slug no workspace has.
|
|
182
183
|
await assert.rejects(directory.resolveWorkspaceContextForUserBySlug(outsider, "context-team"),
|
|
183
|
-
errorWith(
|
|
184
|
+
errorWith(404, "workspaces.workspace.notFound", "Workspace not found."));
|
|
184
185
|
await db.memberships.upsertMembership(workspace.id, member.id, { roleSid: "admin", status: "revoked" });
|
|
185
186
|
await assert.rejects(directory.resolveWorkspaceContextForUserBySlug(member, "context-team"),
|
|
186
|
-
errorWith(
|
|
187
|
+
errorWith(404, "workspaces.workspace.notFound"), "a revoked member is refused");
|
|
187
188
|
|
|
188
189
|
// The owner's missing or inactive membership is restored by reading the context.
|
|
189
190
|
await db.memberships.upsertMembership(workspace.id, owner.id, { roleSid: "owner", status: "revoked" });
|
|
@@ -253,6 +254,6 @@ test("get and update read the context first and save only the patchable fields",
|
|
|
253
254
|
{ slug: "update-team", ownerUserId: owner.id, isPersonal: false }, "fields outside the patch stay");
|
|
254
255
|
|
|
255
256
|
await assert.rejects(directory.updateWorkspaceForAuthenticatedUser(intruder, "update-team", { name: "Hijacked" }),
|
|
256
|
-
errorWith(
|
|
257
|
+
errorWith(404, "workspaces.workspace.notFound"));
|
|
257
258
|
assert.equal((await db.workspaces.findById(workspace.id)).name, "Renamed");
|
|
258
259
|
});
|
|
@@ -173,7 +173,7 @@ test("the members and invites list routes refuse as strictly as before", async (
|
|
|
173
173
|
for (const path of ["members", "invites"]) {
|
|
174
174
|
const refusals = [
|
|
175
175
|
["signed out", await get(null, path, page(20)), 401, "auth.session.required"],
|
|
176
|
-
["not a member", await get(outsider, path, page(20)),
|
|
176
|
+
["not a member", await get(outsider, path, page(20)), 404, "workspaces.workspace.notFound"],
|
|
177
177
|
["a member without workspace.members.view", await get(guest, path, page(20)), 403, "ACTION_PERMISSION_DENIED"],
|
|
178
178
|
["an unknown workspace", await get(owner, path, { ...page(20), slug: "no-such-workspace" }), 404,
|
|
179
179
|
"workspaces.workspace.notFound"],
|
|
@@ -11,7 +11,7 @@ import { jsonApiResultValue } from "@jskit-ai/http-runtime/shared/validators/jso
|
|
|
11
11
|
import { resolveActorId } from "@jskit-ai/kernel/server/actions/actionContributorHelpers";
|
|
12
12
|
import { defineFeature } from "@jskit-ai/kernel/server/features";
|
|
13
13
|
import { HttpProvider } from "@jskit-ai/kernel/server/http";
|
|
14
|
-
import {
|
|
14
|
+
import { BootstrapProvider } from "@jskit-ai/kernel/server/runtime";
|
|
15
15
|
import { defineTableResource } from "@jskit-ai/resource-core/shared/tableResource";
|
|
16
16
|
import { defineCrudContract } from "@jskit-ai/resource-crud-core/shared/crudContract";
|
|
17
17
|
import { createPackageTestKnex, startTestFeatures } from "@jskit-ai/resource-runtime/test";
|
|
@@ -184,6 +184,7 @@ async function issuesApp(t) {
|
|
|
184
184
|
createTables: true,
|
|
185
185
|
features: [
|
|
186
186
|
HttpProvider,
|
|
187
|
+
BootstrapProvider,
|
|
187
188
|
AuthExtensionsProvider,
|
|
188
189
|
AuthPolicyProvider,
|
|
189
190
|
UsersExtensionsProvider,
|
|
@@ -195,18 +196,32 @@ async function issuesApp(t) {
|
|
|
195
196
|
NoticeFeature,
|
|
196
197
|
ContextFeature
|
|
197
198
|
],
|
|
198
|
-
requires: {
|
|
199
|
+
requires: {
|
|
200
|
+
profiles: "users.profiles",
|
|
201
|
+
workspaces: "workspaces.core",
|
|
202
|
+
memberships: "workspaces.memberships",
|
|
203
|
+
actions: "runtime.actions",
|
|
204
|
+
bootstrap: "runtime.bootstrap"
|
|
205
|
+
},
|
|
199
206
|
inputs: {
|
|
200
207
|
"auth.service": headerAuthService(signedIn),
|
|
201
208
|
"runtime.app-root": process.cwd(),
|
|
202
|
-
"runtime.bootstrap": createBootstrapRuntime(),
|
|
203
209
|
"runtime.config": config,
|
|
204
210
|
"runtime.env": { APP_ENV: "test" },
|
|
205
211
|
"runtime.fastify": app
|
|
206
212
|
}
|
|
207
213
|
});
|
|
208
214
|
t.after(started.stop);
|
|
209
|
-
const { profiles, workspaces, memberships, actions } = started.capabilities;
|
|
215
|
+
const { profiles, workspaces, memberships, actions, bootstrap } = started.capabilities;
|
|
216
|
+
// The session part of the bootstrap, as users-core's contributor gives it: who the request is signed in as.
|
|
217
|
+
bootstrap.register({
|
|
218
|
+
id: "test.session",
|
|
219
|
+
order: 100,
|
|
220
|
+
contribute: ({ request }) => {
|
|
221
|
+
const profile = signedIn.get(String(request.headers["x-test-user"] || ""));
|
|
222
|
+
return { session: profile ? { authenticated: true, userId: profile.id } : { authenticated: false } };
|
|
223
|
+
}
|
|
224
|
+
});
|
|
210
225
|
const person = async (name) => {
|
|
211
226
|
const profile = await profiles.upsert({
|
|
212
227
|
authProvider: "local",
|
|
@@ -242,6 +257,12 @@ async function issuesApp(t) {
|
|
|
242
257
|
const list = (user, slug = workspace.slug) => get(user, slug, "issues");
|
|
243
258
|
const notice = (user, slug = workspace.slug) => get(user, slug, "notice");
|
|
244
259
|
const context = (user, slug = workspace.slug) => get(user, slug, "context");
|
|
260
|
+
// The browser's bootstrap for a page of a workspace.
|
|
261
|
+
const bootstrapFor = (user, slug) => app.inject({
|
|
262
|
+
method: "GET",
|
|
263
|
+
url: `/api/bootstrap?workspaceSlug=${encodeURIComponent(slug)}`,
|
|
264
|
+
headers: user ? { "x-test-user": user.id } : {}
|
|
265
|
+
});
|
|
245
266
|
// A background job of a feature with a system scope, running one action as a member of the workspace.
|
|
246
267
|
const systemContext = started.resources.declareSystemScope("test.member-jobs", "act for members of every workspace");
|
|
247
268
|
async function runAsMember(user, actionId) {
|
|
@@ -259,7 +280,7 @@ async function issuesApp(t) {
|
|
|
259
280
|
);
|
|
260
281
|
return countQueries(knex, () => actions.execute({ actionId, input: { workspaceSlug: workspace.slug }, context: { ...acting, surface: "app" } }));
|
|
261
282
|
}
|
|
262
|
-
return { list, notice, context, runAsMember, runInRole, owner, member, guest, outsider, workspace };
|
|
283
|
+
return { list, notice, context, bootstrapFor, runAsMember, runInRole, owner, member, guest, outsider, workspace };
|
|
263
284
|
}
|
|
264
285
|
|
|
265
286
|
// The statements of one read of the workspace context, whatever the database quotes its names with: the workspace by
|
|
@@ -297,7 +318,7 @@ test("a workspace CRUD list request refuses as strictly as before", async (t) =>
|
|
|
297
318
|
|
|
298
319
|
const refusals = [
|
|
299
320
|
["signed out", await list(null), 401, "auth.session.required"],
|
|
300
|
-
["not a member", await list(outsider),
|
|
321
|
+
["not a member", await list(outsider), 404, "workspaces.workspace.notFound"],
|
|
301
322
|
["a member without crud.issues.list", await list(guest), 403, "ACTION_PERMISSION_DENIED"],
|
|
302
323
|
["an unknown workspace", await list(owner, "no-such-workspace"), 404, "workspaces.workspace.notFound"]
|
|
303
324
|
];
|
|
@@ -309,6 +330,25 @@ test("a workspace CRUD list request refuses as strictly as before", async (t) =>
|
|
|
309
330
|
}
|
|
310
331
|
});
|
|
311
332
|
|
|
333
|
+
// Someone outside a workspace learns nothing of it: every workspace route and the bootstrap answer its slug exactly as
|
|
334
|
+
// they answer a slug no workspace has, so they can't tell an existing workspace from a typo.
|
|
335
|
+
test("a workspace the person isn't in is answered exactly as one that doesn't exist", async (t) => {
|
|
336
|
+
const { list, notice, context, bootstrapFor, outsider, workspace } = await issuesApp(t);
|
|
337
|
+
const unknown = "no-such-workspace";
|
|
338
|
+
|
|
339
|
+
for (const [label, read] of [["a CRUD list", list], ["an optional-context route", notice], ["a member's route", context]]) {
|
|
340
|
+
const [theirs, missing] = [(await read(outsider, workspace.slug)).response, (await read(outsider, unknown)).response];
|
|
341
|
+
assert.equal(theirs.statusCode, 404, `${label}: ${theirs.body}`);
|
|
342
|
+
assert.deepEqual([theirs.statusCode, theirs.json()], [missing.statusCode, missing.json()], label);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const [theirs, missing] = [await bootstrapFor(outsider, workspace.slug), await bootstrapFor(outsider, unknown)];
|
|
346
|
+
assert.equal(theirs.statusCode, 200, theirs.body);
|
|
347
|
+
assert.deepEqual(theirs.json().requestedWorkspace, { slug: workspace.slug, status: "not_found" });
|
|
348
|
+
const withoutSlug = (payload) => ({ ...payload, requestedWorkspace: { ...payload.requestedWorkspace, slug: "" } });
|
|
349
|
+
assert.deepEqual(withoutSlug(theirs.json()), withoutSlug(missing.json()));
|
|
350
|
+
});
|
|
351
|
+
|
|
312
352
|
test("a route whose auth policy and action context differ in requiring membership reads the context once", async (t) => {
|
|
313
353
|
const { notice, owner, member, outsider, workspace } = await issuesApp(t);
|
|
314
354
|
|
|
@@ -326,8 +366,8 @@ test("a route whose auth policy and action context differ in requiring membershi
|
|
|
326
366
|
|
|
327
367
|
// The shared read still refuses a non-member where membership is required.
|
|
328
368
|
const { response, queries } = await notice(outsider);
|
|
329
|
-
assert.equal(response.statusCode,
|
|
330
|
-
assert.equal(response.body.includes("workspaces.workspace.
|
|
369
|
+
assert.equal(response.statusCode, 404, response.body);
|
|
370
|
+
assert.equal(response.body.includes("workspaces.workspace.notFound"), true, response.body);
|
|
331
371
|
assert.equal(reading(queries, "workspace").length, 1, queries.join("\n"));
|
|
332
372
|
});
|
|
333
373
|
|
|
@@ -383,8 +423,9 @@ test("a role context runs an action as a member in that role would, for a user w
|
|
|
383
423
|
}
|
|
384
424
|
|
|
385
425
|
// The permission check passes as the role: the member role lists the workspace's issues, which the outsider's and
|
|
386
|
-
// the guest's own requests may not, and the guest role is refused as a
|
|
387
|
-
|
|
426
|
+
// the guest's own requests may not (the outsider is told it doesn't exist), and the guest role is refused as a
|
|
427
|
+
// guest's request is.
|
|
428
|
+
assert.equal((await list(outsider)).response.statusCode, 404);
|
|
388
429
|
assert.equal((await list(guest)).response.statusCode, 403);
|
|
389
430
|
const memberTitles = (await list(member)).response.json().data.map((record) => record.attributes.title).sort();
|
|
390
431
|
for (const user of [outsider, guest]) {
|
|
@@ -726,7 +726,7 @@ test("workspaceService.resolveWorkspaceContextForUserBySlug can resolve an exist
|
|
|
726
726
|
{ id: "7", email: "customer@example.com" },
|
|
727
727
|
"dog-and-groom"
|
|
728
728
|
),
|
|
729
|
-
/
|
|
729
|
+
/Workspace not found/
|
|
730
730
|
);
|
|
731
731
|
|
|
732
732
|
const context = await service.resolveWorkspaceContextForUserBySlug(
|