@terreno/api 57.20.0 → 57.21.0
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 +50 -0
- package/biome.jsonc +1 -0
- package/dist/api.d.ts +3 -3
- package/dist/frameworkModelNames.d.ts +4 -0
- package/dist/frameworkModelNames.js +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +9 -3
- package/dist/mcp/adminTracking.d.ts +28 -0
- package/dist/mcp/adminTracking.js +80 -0
- package/dist/mcp/auth.d.ts +6 -0
- package/dist/mcp/auth.js +12 -2
- package/dist/mcp/server.d.ts +8 -0
- package/dist/mcp/server.js +48 -4
- package/dist/models/mcpOAuthToken.js +27 -0
- package/dist/models/mcpRequestLog.d.ts +2 -0
- package/dist/models/mcpRequestLog.js +73 -0
- package/dist/models/mcpServiceToken.js +4 -0
- package/dist/models/mcpToolSetting.d.ts +2 -0
- package/dist/models/mcpToolSetting.js +119 -0
- package/dist/models/versionConfig.d.ts +2 -0
- package/dist/rbac/auditModel.d.ts +2 -1
- package/dist/terrenoApp.d.ts +12 -0
- package/dist/terrenoApp.js +3 -0
- package/dist/tests/models.d.ts +17 -22
- package/dist/tests/models.js +7 -1
- package/dist/tests/testHelper.d.ts +6 -12
- package/dist/tests.d.ts +1 -0
- package/dist/tests.js +3 -1
- package/dist/types/mcpAdmin.d.ts +58 -0
- package/dist/types/mcpAdmin.js +2 -0
- package/dist/types/mcpOAuth.d.ts +2 -0
- package/dist/types/mcpServiceToken.d.ts +2 -0
- package/e2e/smoke.ts +193 -0
- package/package.json +7 -5
- package/src/adminModelRouter.test.ts +8 -6
- package/src/api.arrayOperations.test.ts +31 -22
- package/src/api.hooks.test.ts +12 -11
- package/src/api.query.test.ts +2 -2
- package/src/api.test.ts +8 -7
- package/src/api.ts +3 -3
- package/src/audit/auditApp.test.ts +1 -1
- package/src/audit/cloudTasksEnqueue.test.ts +19 -14
- package/src/auth.test.ts +21 -7
- package/src/authRecovery.test.ts +10 -10
- package/src/authVerification.test.ts +7 -7
- package/src/betterAuthFeatures.test.ts +3 -2
- package/src/betterAuthLinking.test.ts +3 -1
- package/src/betterAuthSetup.test.ts +77 -51
- package/src/collectionRegistry.test.ts +4 -4
- package/src/frameworkModelNames.test.ts +8 -0
- package/src/frameworkModelNames.ts +4 -0
- package/src/githubAuth.test.ts +11 -11
- package/src/index.ts +8 -0
- package/src/isolated/migrateCliConnect.isolated.ts +3 -2
- package/src/mcp/actionTools.test.ts +11 -5
- package/src/mcp/adminTracking.test.ts +272 -0
- package/src/mcp/adminTracking.ts +104 -0
- package/src/mcp/auth.ts +18 -2
- package/src/mcp/oauth.test.ts +1 -1
- package/src/mcp/server.ts +67 -4
- package/src/mcp/serviceTokens.test.ts +2 -1
- package/src/mcp/toolGenerator.test.ts +9 -5
- package/src/migrations/cli.test.ts +15 -14
- package/src/migrations/cli.ts +1 -1
- package/src/migrations/generate.test.ts +2 -2
- package/src/migrations/load.test.ts +1 -1
- package/src/migrations/lock.test.ts +8 -3
- package/src/migrations/runner.test.ts +16 -5
- package/src/migrations/schemaCatalog.test.ts +4 -1
- package/src/models/mcpOAuthToken.test.ts +42 -0
- package/src/models/mcpOAuthToken.ts +32 -0
- package/src/models/mcpRequestLog.ts +81 -0
- package/src/models/mcpServiceToken.test.ts +23 -0
- package/src/models/mcpServiceToken.ts +10 -0
- package/src/models/mcpToolSetting.test.ts +69 -0
- package/src/models/mcpToolSetting.ts +138 -0
- package/src/models/versionConfig.ts +2 -0
- package/src/notifications/notificationsApp.test.ts +5 -8
- package/src/notifiers/slackWebApi.test.ts +30 -8
- package/src/openApi.test.ts +4 -4
- package/src/openApiValidator.test.ts +3 -3
- package/src/orgs/orgPermissions.test.ts +2 -2
- package/src/orgs/orgPlugin.test.ts +4 -3
- package/src/orgs/orgSecurityDefects.test.ts +3 -1
- package/src/orgs/organizationSettings.test.ts +1 -1
- package/src/orgs/orgsApp.test.ts +5 -3
- package/src/permissions.test.ts +2 -2
- package/src/rateLimit/redisStore.ioredis.test.ts +3 -2
- package/src/rbac/assertAllowed.test.ts +1 -1
- package/src/rbac/auditModel.ts +10 -2
- package/src/rbac/realtimeAccess.test.ts +3 -2
- package/src/rbac/routes.test.ts +1 -1
- package/src/rbac/userWriteGuards.test.ts +8 -5
- package/src/realtime/realtime.test.ts +35 -31
- package/src/scrubAdminFields.test.ts +1 -1
- package/src/sync/adminWindowMutation.test.ts +4 -3
- package/src/sync/executors.test.ts +1 -1
- package/src/sync/scripts/compactTombstones.test.ts +4 -3
- package/src/sync/sync.test.ts +1 -1
- package/src/sync/syncPhaseC.test.ts +14 -11
- package/src/sync/syncRoutes.test.ts +8 -8
- package/src/sync/syncSeqPlugin.test.ts +1 -2
- package/src/sync/syncSocket.test.ts +5 -4
- package/src/terrenoApp.mcpServiceTokens.test.ts +2 -2
- package/src/terrenoApp.migrations.test.ts +8 -7
- package/src/terrenoApp.ts +14 -0
- package/src/tests/betterAuthStubs.ts +3 -2
- package/src/tests/bunSetup.ts +1 -1
- package/src/tests/models.ts +10 -0
- package/src/tests/testEnv.ts +7 -0
- package/src/tests.ts +1 -0
- package/src/types/mcpAdmin.ts +80 -0
- package/src/types/mcpOAuth.ts +5 -0
- package/src/types/mcpServiceToken.ts +5 -0
- package/src/webhooks/verifiers/hmac.test.ts +1 -1
- package/tsconfig.typecheck.json +14 -0
|
@@ -12,7 +12,7 @@ import {NotificationPreference} from "../models/notificationPreference";
|
|
|
12
12
|
import {clearSyncRegistry} from "../sync/registry";
|
|
13
13
|
import {SyncApp} from "../sync/syncApp";
|
|
14
14
|
import {TerrenoApp} from "../terrenoApp";
|
|
15
|
-
import {authAsUser, setupDb, UserModel} from "../tests";
|
|
15
|
+
import {authAsUser, authUserModel, setupDb, UserModel} from "../tests";
|
|
16
16
|
import {configureNotificationService, getNotificationService} from "./notificationService";
|
|
17
17
|
import {NotificationsApp} from "./notificationsApp";
|
|
18
18
|
import {
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
interface FakeComms {
|
|
24
24
|
mailCalls: Array<{html?: string; subject: string; to: string}>;
|
|
25
25
|
mailUserIds: Array<string | undefined>;
|
|
26
|
-
pushCalls: Array<{title: string; userId: string}>;
|
|
26
|
+
pushCalls: Array<{body: string; title: string; userId: string}>;
|
|
27
27
|
smsCalls: Array<{body: string; to: string}>;
|
|
28
28
|
smsUserIds: Array<string | undefined>;
|
|
29
29
|
}
|
|
@@ -37,7 +37,7 @@ const buildFakeComms = (
|
|
|
37
37
|
message: {html?: string; subject: string; to: string},
|
|
38
38
|
options?: {userId?: string}
|
|
39
39
|
) => Promise<{accepted: boolean}>;
|
|
40
|
-
sendPushToUser: (message: {title: string; userId: string}) => Promise<unknown[]>;
|
|
40
|
+
sendPushToUser: (message: {body: string; title: string; userId: string}) => Promise<unknown[]>;
|
|
41
41
|
sendSms: (
|
|
42
42
|
message: {body: string; to: string},
|
|
43
43
|
options?: {userId?: string}
|
|
@@ -77,10 +77,7 @@ const buildFakeComms = (
|
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
const buildApp = (
|
|
80
|
-
options: {
|
|
81
|
-
getComms?: () => ReturnType<typeof buildFakeComms>["getComms"];
|
|
82
|
-
retainDays?: number;
|
|
83
|
-
} = {}
|
|
80
|
+
options: {getComms?: ReturnType<typeof buildFakeComms>["getComms"]; retainDays?: number} = {}
|
|
84
81
|
): express.Application => {
|
|
85
82
|
clearSyncRegistry();
|
|
86
83
|
return new TerrenoApp({
|
|
@@ -114,7 +111,7 @@ describe("NotificationsApp", () => {
|
|
|
114
111
|
const app = buildApp();
|
|
115
112
|
userAgent = await authAsUser(app, "notAdmin");
|
|
116
113
|
await UserModel.deleteOne({email: "other-user@example.com"});
|
|
117
|
-
await signupUser(
|
|
114
|
+
await signupUser(authUserModel, "other-user@example.com", "password");
|
|
118
115
|
otherUserAgent = await authWithCredentials(app, {
|
|
119
116
|
email: "other-user@example.com",
|
|
120
117
|
password: "password",
|
|
@@ -22,13 +22,35 @@ describe("normalizeSlackChannelName", () => {
|
|
|
22
22
|
});
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
+
/** The request body fields the Slack helpers send. */
|
|
26
|
+
interface SlackRequestBody {
|
|
27
|
+
blocks?: unknown[];
|
|
28
|
+
channel?: string;
|
|
29
|
+
force?: boolean;
|
|
30
|
+
name?: string;
|
|
31
|
+
text?: string;
|
|
32
|
+
users?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Slack doubles return `data`, `status`, and sometimes `headers`, not a whole AxiosResponse. */
|
|
36
|
+
interface SlackResponseDouble {
|
|
37
|
+
data: unknown;
|
|
38
|
+
headers?: {get: (name: string) => string | undefined};
|
|
39
|
+
status: number;
|
|
40
|
+
}
|
|
41
|
+
type AxiosPostDouble = (url: string, body: SlackRequestBody) => Promise<SlackResponseDouble>;
|
|
42
|
+
type AxiosGetDouble = (
|
|
43
|
+
url: string,
|
|
44
|
+
config?: {params?: {types?: string}}
|
|
45
|
+
) => Promise<SlackResponseDouble>;
|
|
46
|
+
|
|
25
47
|
describe("Slack Web API", () => {
|
|
26
|
-
let mockAxiosPost: Mock<
|
|
27
|
-
let mockAxiosGet: Mock<
|
|
48
|
+
let mockAxiosPost: Mock<AxiosPostDouble>;
|
|
49
|
+
let mockAxiosGet: Mock<AxiosGetDouble>;
|
|
28
50
|
|
|
29
51
|
beforeEach(() => {
|
|
30
|
-
mockAxiosPost = spyOn(axios, "post")
|
|
31
|
-
mockAxiosGet = spyOn(axios, "get")
|
|
52
|
+
mockAxiosPost = spyOn(axios, "post") as unknown as Mock<AxiosPostDouble>;
|
|
53
|
+
mockAxiosGet = spyOn(axios, "get") as unknown as Mock<AxiosGetDouble>;
|
|
32
54
|
process.env.SLACK_BOT_TOKEN = "xoxb-test";
|
|
33
55
|
(Sentry.captureException as Mock<typeof Sentry.captureException>).mockClear();
|
|
34
56
|
});
|
|
@@ -40,7 +62,7 @@ describe("Slack Web API", () => {
|
|
|
40
62
|
});
|
|
41
63
|
|
|
42
64
|
it("creates a private channel, invites members, and posts the first message", async () => {
|
|
43
|
-
mockAxiosPost.mockImplementation(async (url: string, body:
|
|
65
|
+
mockAxiosPost.mockImplementation(async (url: string, body: SlackRequestBody) => {
|
|
44
66
|
if (String(url).endsWith("conversations.create")) {
|
|
45
67
|
return {
|
|
46
68
|
data: {channel: {id: "C012345678", is_private: true, name: body.name}, ok: true},
|
|
@@ -120,7 +142,7 @@ describe("Slack Web API", () => {
|
|
|
120
142
|
|
|
121
143
|
expect(result.alreadyMemberUserIds).toEqual(["U012ABCDEF"]);
|
|
122
144
|
expect(result.invitedUserIds).toEqual([]);
|
|
123
|
-
const body = mockAxiosPost.mock.calls[0]?.[1]
|
|
145
|
+
const body = mockAxiosPost.mock.calls[0]?.[1];
|
|
124
146
|
expect(body).toEqual({channel: "C012345678", force: true, users: "U012ABCDEF"});
|
|
125
147
|
});
|
|
126
148
|
|
|
@@ -211,8 +233,8 @@ describe("Slack Web API", () => {
|
|
|
211
233
|
|
|
212
234
|
const found = await findSlackChannelByName({name: "case-123"});
|
|
213
235
|
expect(found).toEqual({channelId: "C012345678", isPrivate: true, name: "case-123"});
|
|
214
|
-
const firstParams = mockAxiosGet.mock.calls[0]?.[1]
|
|
215
|
-
expect(firstParams
|
|
236
|
+
const firstParams = mockAxiosGet.mock.calls[0]?.[1];
|
|
237
|
+
expect(firstParams?.params?.types).toBe("public_channel,private_channel");
|
|
216
238
|
});
|
|
217
239
|
|
|
218
240
|
it("returns undefined when no visible channel has that name", async () => {
|
package/src/openApi.test.ts
CHANGED
|
@@ -461,7 +461,7 @@ describe("openApi middleware no-op paths", () => {
|
|
|
461
461
|
listOpenApiMiddleware(
|
|
462
462
|
FoodModel,
|
|
463
463
|
{
|
|
464
|
-
openApi: createOpenApiStub((spec
|
|
464
|
+
openApi: createOpenApiStub((spec?: Record<string, unknown>) => {
|
|
465
465
|
captured = spec;
|
|
466
466
|
return createPassThroughMiddleware();
|
|
467
467
|
}),
|
|
@@ -482,7 +482,7 @@ describe("openApi middleware no-op paths", () => {
|
|
|
482
482
|
it("listOpenApiMiddleware omits x-terreno-sync when sync is not configured", () => {
|
|
483
483
|
let captured: Record<string, unknown> | undefined;
|
|
484
484
|
listOpenApiMiddleware(FoodModel, {
|
|
485
|
-
openApi: createOpenApiStub((spec
|
|
485
|
+
openApi: createOpenApiStub((spec?: Record<string, unknown>) => {
|
|
486
486
|
captured = spec;
|
|
487
487
|
return createPassThroughMiddleware();
|
|
488
488
|
}),
|
|
@@ -500,7 +500,7 @@ describe("openApi middleware no-op paths", () => {
|
|
|
500
500
|
it("listOpenApiMiddleware falls back to the model collection name without routePath", () => {
|
|
501
501
|
let captured: Record<string, unknown> | undefined;
|
|
502
502
|
listOpenApiMiddleware(FoodModel, {
|
|
503
|
-
openApi: createOpenApiStub((spec
|
|
503
|
+
openApi: createOpenApiStub((spec?: Record<string, unknown>) => {
|
|
504
504
|
captured = spec;
|
|
505
505
|
return createPassThroughMiddleware();
|
|
506
506
|
}),
|
|
@@ -521,7 +521,7 @@ describe("openApi middleware no-op paths", () => {
|
|
|
521
521
|
|
|
522
522
|
it("listOpenApiMiddleware maps tenant and custom sync scopes", () => {
|
|
523
523
|
let captured: Record<string, unknown> | undefined;
|
|
524
|
-
const capturePath = (spec
|
|
524
|
+
const capturePath = (spec?: Record<string, unknown>): express.RequestHandler => {
|
|
525
525
|
captured = spec;
|
|
526
526
|
return createPassThroughMiddleware();
|
|
527
527
|
};
|
|
@@ -557,7 +557,7 @@ describe("openApiValidator", () => {
|
|
|
557
557
|
const res = {} as Response;
|
|
558
558
|
middleware(req, res, () => {});
|
|
559
559
|
|
|
560
|
-
expect(req.query.page).toBe(3);
|
|
560
|
+
expect<unknown>(req.query.page).toBe(3);
|
|
561
561
|
});
|
|
562
562
|
|
|
563
563
|
it("throws validation error when query does not match", () => {
|
|
@@ -665,7 +665,7 @@ describe("openApiValidator", () => {
|
|
|
665
665
|
});
|
|
666
666
|
|
|
667
667
|
expect(nextCalled).toBe(true);
|
|
668
|
-
expect(req.query.page).toBe(2);
|
|
668
|
+
expect<unknown>(req.query.page).toBe(2);
|
|
669
669
|
});
|
|
670
670
|
|
|
671
671
|
it("skips when neither body nor query schemas are provided", () => {
|
|
@@ -698,7 +698,7 @@ describe("openApiValidator", () => {
|
|
|
698
698
|
});
|
|
699
699
|
|
|
700
700
|
expect(nextCalled).toBe(true);
|
|
701
|
-
expect(req.query.page).toBe(5);
|
|
701
|
+
expect<unknown>(req.query.page).toBe(5);
|
|
702
702
|
});
|
|
703
703
|
|
|
704
704
|
it("runs only body validation when no query schema is provided", () => {
|
|
@@ -11,14 +11,14 @@ const platformUser = (roles: string[]): User =>
|
|
|
11
11
|
admin: false,
|
|
12
12
|
id: new mongoose.Types.ObjectId().toString(),
|
|
13
13
|
roles,
|
|
14
|
-
}) as User;
|
|
14
|
+
}) as unknown as User;
|
|
15
15
|
|
|
16
16
|
const memberUser = (): User =>
|
|
17
17
|
({
|
|
18
18
|
admin: false,
|
|
19
19
|
id: new mongoose.Types.ObjectId().toString(),
|
|
20
20
|
roles: [],
|
|
21
|
-
}) as User;
|
|
21
|
+
}) as unknown as User;
|
|
22
22
|
|
|
23
23
|
describe("OrgQueryFilter", () => {
|
|
24
24
|
it("throws when organization context is missing", () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {beforeEach, describe, it} from "bun:test";
|
|
2
2
|
import {assert} from "chai";
|
|
3
|
-
import mongoose, {model, Schema} from "mongoose";
|
|
3
|
+
import mongoose, {model, Schema, type UpdateQuery} from "mongoose";
|
|
4
4
|
|
|
5
5
|
import {orgScopedPlugin} from "./orgPlugin";
|
|
6
6
|
|
|
@@ -106,11 +106,12 @@ describe("orgScopedPlugin", () => {
|
|
|
106
106
|
title: "Pinned",
|
|
107
107
|
});
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
const updates: UpdateQuery<OrgScopedWidget>[] = [
|
|
110
110
|
{$unset: {organizationId: 1}},
|
|
111
111
|
{$rename: {organizationId: "formerOrganizationId"}},
|
|
112
112
|
{$rename: {formerOrganizationId: "organizationId"}},
|
|
113
|
-
]
|
|
113
|
+
];
|
|
114
|
+
for (const update of updates) {
|
|
114
115
|
let error: unknown;
|
|
115
116
|
try {
|
|
116
117
|
await OrgScopedWidgetModel.updateOne({_id: widget._id}, update);
|
|
@@ -18,6 +18,7 @@ import {createAccess} from "../rbac/access";
|
|
|
18
18
|
import {terrenoStatements} from "../rbac/statements";
|
|
19
19
|
import {getBaseServer} from "../tests";
|
|
20
20
|
import {type User, UserModel} from "../tests/models";
|
|
21
|
+
import type {OrganizationDocument} from "../types/organization";
|
|
21
22
|
import {Membership, Organization} from "./organizationModel";
|
|
22
23
|
import {ORGANIZATION_DISABLED_TITLE, orgContextMiddleware, resolveOrgContext} from "./orgContext";
|
|
23
24
|
import {isOrgMemberPermission, OrgQueryFilter} from "./orgPermissions";
|
|
@@ -96,7 +97,8 @@ describe("org security regressions", () => {
|
|
|
96
97
|
update: [Permissions.IsAuthenticated, isOrgMemberPermission],
|
|
97
98
|
},
|
|
98
99
|
preCreate: async (body, req) => {
|
|
99
|
-
|
|
100
|
+
// orgContextMiddleware sets req.organization; the Express typing leaves it unknown.
|
|
101
|
+
const organizationId = (req.organization as OrganizationDocument | undefined)?._id;
|
|
100
102
|
if (!organizationId) {
|
|
101
103
|
throw new Error("organization context required");
|
|
102
104
|
}
|
|
@@ -56,7 +56,7 @@ describe("organization settings schema", () => {
|
|
|
56
56
|
assert.instanceOf(extraKeyError, ValidationError);
|
|
57
57
|
assert.equal((extraKeyError as ValidationError).title, "Organization settings are invalid");
|
|
58
58
|
assert.match(
|
|
59
|
-
String((extraKeyError as ValidationError).meta?.fields?.settings),
|
|
59
|
+
String(((extraKeyError as ValidationError).meta?.fields as {settings?: unknown})?.settings),
|
|
60
60
|
/Unknown settings field: plan/
|
|
61
61
|
);
|
|
62
62
|
|
package/src/orgs/orgsApp.test.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {afterEach, beforeEach, describe, it} from "bun:test";
|
|
|
2
2
|
import {authAsUser as loginWithPassword} from "@terreno/test";
|
|
3
3
|
import {assert} from "chai";
|
|
4
4
|
import type {Application} from "express";
|
|
5
|
-
import mongoose from "mongoose";
|
|
5
|
+
import mongoose, {type HydratedDocument} from "mongoose";
|
|
6
6
|
import type {PassportLocalMongooseDocument} from "passport-local-mongoose";
|
|
7
7
|
|
|
8
8
|
import {
|
|
@@ -16,6 +16,8 @@ import {createAccess} from "../rbac/access";
|
|
|
16
16
|
import {terrenoStatements} from "../rbac/statements";
|
|
17
17
|
import {getBaseServer} from "../tests";
|
|
18
18
|
import {type User, UserModel} from "../tests/models";
|
|
19
|
+
import type {MembershipDocument} from "../types/membership";
|
|
20
|
+
import type {OrganizationDocument} from "../types/organization";
|
|
19
21
|
import {Membership, Organization} from "./organizationModel";
|
|
20
22
|
import {
|
|
21
23
|
createOrganizationSettingsSchema,
|
|
@@ -287,9 +289,9 @@ describe("OrgsApp", () => {
|
|
|
287
289
|
describe("permission cache", () => {
|
|
288
290
|
const setUpOrgAdmins = async (): Promise<{
|
|
289
291
|
operatorAgent: Awaited<ReturnType<typeof loginWithPassword>>;
|
|
290
|
-
org:
|
|
292
|
+
org: HydratedDocument<OrganizationDocument>;
|
|
291
293
|
orgAdmins: AuthUser[];
|
|
292
|
-
removable:
|
|
294
|
+
removable: HydratedDocument<MembershipDocument>;
|
|
293
295
|
}> => {
|
|
294
296
|
const operator = await createUser({email: "operator@example.com", roles: ["operator"]});
|
|
295
297
|
const first = await createUser({email: "first-org-admin@example.com"});
|
package/src/permissions.test.ts
CHANGED
|
@@ -287,7 +287,7 @@ describe("permissions module", () => {
|
|
|
287
287
|
|
|
288
288
|
it("returns false for user.admin without platform org roles", async () => {
|
|
289
289
|
const user = testUser({
|
|
290
|
-
_id: new mongoose.Types.ObjectId(),
|
|
290
|
+
_id: new mongoose.Types.ObjectId() as unknown as AuthUser["_id"],
|
|
291
291
|
admin: true,
|
|
292
292
|
id: new mongoose.Types.ObjectId().toString(),
|
|
293
293
|
});
|
|
@@ -309,7 +309,7 @@ describe("permissions module", () => {
|
|
|
309
309
|
roleName: "member",
|
|
310
310
|
userId,
|
|
311
311
|
});
|
|
312
|
-
const user = testUser({_id: userId, id: userId.toString()});
|
|
312
|
+
const user = testUser({_id: userId as unknown as AuthUser["_id"], id: userId.toString()});
|
|
313
313
|
const allowed = await runWithOrgContext({organization: org}, () =>
|
|
314
314
|
Permissions.IsOrganizationMember("update", user, {organizationId: org._id})
|
|
315
315
|
);
|
|
@@ -10,10 +10,11 @@ mock.module("ioredis", () => {
|
|
|
10
10
|
return {default: Redis};
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
let createRedisRateLimitStore: typeof import("./redisStore.js").createRedisRateLimitStore;
|
|
14
14
|
|
|
15
15
|
describe("redis rate limit store ioredis loader", () => {
|
|
16
|
-
beforeAll(() => {
|
|
16
|
+
beforeAll(async () => {
|
|
17
|
+
({createRedisRateLimitStore} = await import("./redisStore.js"));
|
|
17
18
|
process.env.REDIS_URL = "redis://127.0.0.1:6379";
|
|
18
19
|
Reflect.deleteProperty(process.env, "VALKEY_URL");
|
|
19
20
|
});
|
package/src/rbac/auditModel.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
createdUpdatedPlugin,
|
|
5
|
+
type FindExactlyOnePlugin,
|
|
6
|
+
type FindOneOrNonePlugin,
|
|
7
|
+
findExactlyOne,
|
|
8
|
+
findOneOrNone,
|
|
9
|
+
} from "../plugins";
|
|
4
10
|
import type {PermissionSet} from "./statements";
|
|
5
11
|
|
|
6
12
|
export interface RbacAuditDocument {
|
|
@@ -18,7 +24,9 @@ export interface RbacAuditDocument {
|
|
|
18
24
|
updated: Date;
|
|
19
25
|
}
|
|
20
26
|
|
|
21
|
-
export type RbacAuditModel = mongoose.Model<RbacAuditDocument
|
|
27
|
+
export type RbacAuditModel = mongoose.Model<RbacAuditDocument> &
|
|
28
|
+
FindExactlyOnePlugin<RbacAuditDocument> &
|
|
29
|
+
FindOneOrNonePlugin<RbacAuditDocument>;
|
|
22
30
|
|
|
23
31
|
const rbacAuditSchema = new mongoose.Schema<RbacAuditDocument, RbacAuditModel>(
|
|
24
32
|
{
|
|
@@ -39,11 +39,12 @@ const createTestUser = (
|
|
|
39
39
|
};
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
// Realtime access reads only access/permissions; tests omit the rest of ModelRouterOptions.
|
|
43
|
+
const makeEntry = (options: Partial<RealtimeRegistryEntry["options"]>): RealtimeRegistryEntry => ({
|
|
43
44
|
collectionName: "todos",
|
|
44
45
|
config: {methods: ["create", "update", "delete"], roomStrategy: "owner"},
|
|
45
46
|
modelName: "Todo",
|
|
46
|
-
options,
|
|
47
|
+
options: options as RealtimeRegistryEntry["options"],
|
|
47
48
|
routePath: "/todos",
|
|
48
49
|
});
|
|
49
50
|
|
package/src/rbac/routes.test.ts
CHANGED
|
@@ -242,7 +242,7 @@ describe("rbacRouter role assignment against a partially resolved target", () =>
|
|
|
242
242
|
const access = createAccess({
|
|
243
243
|
connection: mongoose.connection,
|
|
244
244
|
// The signed-in actor may assign roles but does not hold user:delete.
|
|
245
|
-
resolvePermissions: async ({user}) =>
|
|
245
|
+
resolvePermissions: async ({user}): Promise<PermissionSet> =>
|
|
246
246
|
String(user.id) === target.id ? {} : {rbac: ["read", "assignRoles"]},
|
|
247
247
|
sources: [
|
|
248
248
|
{
|
|
@@ -3,11 +3,11 @@ import type express from "express";
|
|
|
3
3
|
import mongoose from "mongoose";
|
|
4
4
|
|
|
5
5
|
import {modelRouter} from "../api";
|
|
6
|
-
import {addAuthRoutes, setupAuth, type UserModel as UserMongooseModel} from "../auth";
|
|
6
|
+
import {addAuthRoutes, setupAuth, type User, type UserModel as UserMongooseModel} from "../auth";
|
|
7
7
|
import {apiErrorMiddleware, apiUnauthorizedMiddleware} from "../errors";
|
|
8
8
|
import {Permissions} from "../permissions";
|
|
9
9
|
import {executeCreate, executeDelete, executeUpdate} from "../sync/executors";
|
|
10
|
-
import {authAsUser, getBaseServer, setupDb,
|
|
10
|
+
import {authAsUser, getBaseServer, setupDb, UserModel} from "../tests";
|
|
11
11
|
import {createAccess} from "./access";
|
|
12
12
|
import {terrenoStatements} from "./statements";
|
|
13
13
|
import type {AnyTerrenoAccess} from "./types";
|
|
@@ -37,7 +37,7 @@ const buildAccess = async (): Promise<AnyTerrenoAccess> => {
|
|
|
37
37
|
return access as unknown as AnyTerrenoAccess;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
const setRoles = async (userId:
|
|
40
|
+
const setRoles = async (userId: mongoose.Types.ObjectId, roles: string[]): Promise<void> => {
|
|
41
41
|
await UserModel.updateOne({_id: userId}, {$set: {roles}});
|
|
42
42
|
};
|
|
43
43
|
|
|
@@ -240,7 +240,10 @@ describe("RBAC target-privilege check over modelRouter HTTP", () => {
|
|
|
240
240
|
instanceActions: {
|
|
241
241
|
rename: {
|
|
242
242
|
handler: async ({doc}) => {
|
|
243
|
-
await UserModel.updateOne(
|
|
243
|
+
await UserModel.updateOne(
|
|
244
|
+
{_id: (doc as {_id: mongoose.Types.ObjectId})._id},
|
|
245
|
+
{name: "Action"}
|
|
246
|
+
);
|
|
244
247
|
return {ok: true};
|
|
245
248
|
},
|
|
246
249
|
method: "POST",
|
|
@@ -421,7 +424,7 @@ describe("user:updateIdentity over modelRouter HTTP", () => {
|
|
|
421
424
|
changeEmail: {
|
|
422
425
|
handler: async ({body, doc}) => {
|
|
423
426
|
await UserModel.updateOne(
|
|
424
|
-
{_id: (doc as {_id:
|
|
427
|
+
{_id: (doc as {_id: mongoose.Types.ObjectId})._id},
|
|
425
428
|
{email: (body as {email: string}).email}
|
|
426
429
|
);
|
|
427
430
|
return {ok: true};
|