@terreno/api 57.1.0 → 57.3.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/README.md +17 -7
- package/dist/actions.js +19 -7
- package/dist/adminTypes.d.ts +26 -0
- package/dist/api.d.ts +4 -0
- package/dist/api.js +12 -24
- package/dist/auth.d.ts +23 -10
- package/dist/auth.js +97 -32
- package/dist/authRecovery.d.ts +5 -0
- package/dist/authRecovery.js +350 -0
- package/dist/authTokens.d.ts +8 -0
- package/dist/authTokens.js +162 -0
- package/dist/betterAuth.d.ts +33 -0
- package/dist/betterAuthApp.d.ts +4 -0
- package/dist/betterAuthApp.js +26 -8
- package/dist/betterAuthSetup.d.ts +44 -2
- package/dist/betterAuthSetup.js +288 -18
- package/dist/collectionRegistry.d.ts +38 -0
- package/dist/collectionRegistry.js +72 -0
- package/dist/configurationApp.d.ts +11 -2
- package/dist/configurationApp.js +2 -4
- package/dist/docLoader.js +35 -6
- package/dist/expressServer.d.ts +26 -3
- package/dist/expressServer.js +79 -11
- package/dist/index.d.ts +16 -0
- package/dist/index.js +38 -2
- package/dist/mcp/auth.d.ts +1 -0
- package/dist/mcp/auth.js +47 -25
- package/dist/mcp/handlers.d.ts +1 -1
- package/dist/mcp/handlers.js +67 -233
- package/dist/mcp/query.d.ts +2 -2
- package/dist/mcp/registry.d.ts +1 -5
- package/dist/mcp/registry.js +31 -20
- package/dist/mcp/schemaGenerator.d.ts +2 -7
- package/dist/mcp/schemaGenerator.js +41 -116
- package/dist/mcp/server.d.ts +1 -0
- package/dist/mcp/server.js +1 -0
- package/dist/mcp/serviceTokens.d.ts +16 -0
- package/dist/mcp/serviceTokens.js +345 -0
- package/dist/mcp/types.d.ts +2 -2
- package/dist/models/mcpServiceToken.d.ts +3 -0
- package/dist/models/mcpServiceToken.js +208 -0
- package/dist/openApiBuilder.d.ts +5 -4
- package/dist/openApiBuilder.js +61 -8
- package/dist/openApiCompat.js +1 -1
- package/dist/openApiValidator.js +0 -2
- package/dist/plugins.d.ts +14 -1
- package/dist/plugins.js +17 -6
- package/dist/populate.d.ts +2 -2
- package/dist/populate.js +47 -42
- package/dist/rateLimit/applyTrustProxy.d.ts +3 -0
- package/dist/rateLimit/applyTrustProxy.js +17 -0
- package/dist/rateLimit/createStore.d.ts +2 -0
- package/dist/rateLimit/createStore.js +28 -0
- package/dist/rateLimit/memoryStore.d.ts +2 -0
- package/dist/rateLimit/memoryStore.js +108 -0
- package/dist/rateLimit/middleware.d.ts +11 -0
- package/dist/rateLimit/middleware.js +110 -0
- package/dist/rateLimit/mongoStore.d.ts +3 -0
- package/dist/rateLimit/mongoStore.js +122 -0
- package/dist/rateLimit/policies.d.ts +14 -0
- package/dist/rateLimit/policies.js +151 -0
- package/dist/rateLimit/redisStore.d.ts +3 -0
- package/dist/rateLimit/redisStore.js +155 -0
- package/dist/rateLimit/types.d.ts +54 -0
- package/dist/rateLimit/types.js +9 -0
- package/dist/rbac/access.js +5 -1
- package/dist/rbac/assertAllowed.d.ts +9 -0
- package/dist/rbac/assertAllowed.js +182 -0
- package/dist/rbac/modelRouterAccess.d.ts +1 -0
- package/dist/rbac/modelRouterAccess.js +8 -4
- package/dist/rbac/permissionUtils.js +3 -2
- package/dist/rbac/resolve.js +5 -4
- package/dist/rbac/routes.js +15 -6
- package/dist/rbac/statements.d.ts +10 -0
- package/dist/rbac/statements.js +13 -2
- package/dist/realtime/deprecation.d.ts +12 -0
- package/dist/realtime/deprecation.js +32 -0
- package/dist/realtime/realtimeApp.d.ts +1 -1
- package/dist/realtime/realtimeApp.js +10 -11
- package/dist/realtime/registry.d.ts +0 -31
- package/dist/realtime/registry.js +44 -31
- package/dist/realtime/socketAuth.d.ts +5 -5
- package/dist/realtime/socketAuth.js +11 -1
- package/dist/realtime/socketUser.d.ts +5 -1
- package/dist/realtime/types.d.ts +14 -4
- package/dist/schemaMetadata.d.ts +56 -0
- package/dist/schemaMetadata.js +513 -0
- package/dist/seedRunner.d.ts +88 -0
- package/dist/seedRunner.js +627 -0
- package/dist/sync/executors.d.ts +12 -2
- package/dist/sync/executors.js +8 -10
- package/dist/sync/loadHarness.js +28 -19
- package/dist/sync/models.js +26 -24
- package/dist/sync/mutationHandler.d.ts +9 -0
- package/dist/sync/mutationHandler.js +11 -6
- package/dist/sync/registrationSideEffects.d.ts +35 -0
- package/dist/sync/registrationSideEffects.js +151 -0
- package/dist/sync/registry.d.ts +2 -52
- package/dist/sync/registry.js +38 -187
- package/dist/sync/routes.js +3 -2
- package/dist/sync/scripts/compactTombstones.js +0 -2
- package/dist/sync/syncApp.d.ts +3 -3
- package/dist/sync/syncApp.js +4 -4
- package/dist/sync/syncBatch.js +3 -2
- package/dist/sync/syncSeqPlugin.d.ts +1 -1
- package/dist/sync/syncSeqPlugin.js +20 -16
- package/dist/terrenoApp.d.ts +19 -5
- package/dist/terrenoApp.js +66 -18
- package/dist/tests/models.d.ts +2 -0
- package/dist/tests/models.js +6 -0
- package/dist/types/authToken.d.ts +33 -0
- package/dist/types/authToken.js +2 -0
- package/dist/types/mcpServiceToken.d.ts +41 -0
- package/dist/types/mcpServiceToken.js +2 -0
- package/dist/webhooks/headerValue.d.ts +2 -0
- package/dist/webhooks/headerValue.js +14 -0
- package/dist/webhooks/idempotency/memoryStore.d.ts +10 -0
- package/dist/webhooks/idempotency/memoryStore.js +65 -0
- package/dist/webhooks/idempotency/mongoStore.d.ts +4 -0
- package/dist/webhooks/idempotency/mongoStore.js +150 -0
- package/dist/webhooks/idempotency/webhookReceipt.d.ts +62 -0
- package/dist/webhooks/idempotency/webhookReceipt.js +39 -0
- package/dist/webhooks/rawBody.d.ts +14 -0
- package/dist/webhooks/rawBody.js +22 -0
- package/dist/webhooks/timingSafeEqual.d.ts +4 -0
- package/dist/webhooks/timingSafeEqual.js +17 -0
- package/dist/webhooks/verifiers/hmac.d.ts +15 -0
- package/dist/webhooks/verifiers/hmac.js +49 -0
- package/dist/webhooks/verifiers/sendgrid.d.ts +10 -0
- package/dist/webhooks/verifiers/sendgrid.js +56 -0
- package/dist/webhooks/verifiers/stripe.d.ts +9 -0
- package/dist/webhooks/verifiers/stripe.js +99 -0
- package/dist/webhooks/verifiers/twilio.d.ts +9 -0
- package/dist/webhooks/verifiers/twilio.js +112 -0
- package/dist/webhooks/webhooksApp.d.ts +33 -0
- package/dist/webhooks/webhooksApp.js +195 -0
- package/package.json +5 -6
- package/src/__snapshots__/openApi.test.ts.snap +270 -0
- package/src/__snapshots__/openApiBuilder.test.ts.snap +30 -12
- package/src/__snapshots__/schemaMetadata.test.ts.snap +197 -0
- package/src/actions.ts +20 -13
- package/src/adminModelRouter.test.ts +133 -0
- package/src/adminTypes.ts +23 -0
- package/src/api.arrayOperations.test.ts +43 -31
- package/src/api.hooks.test.ts +38 -29
- package/src/api.query.test.ts +31 -31
- package/src/api.test.ts +95 -96
- package/src/api.ts +16 -27
- package/src/auth.test.ts +107 -51
- package/src/auth.ts +98 -29
- package/src/authRecovery.test.ts +281 -0
- package/src/authRecovery.ts +279 -0
- package/src/authTokens.test.ts +94 -0
- package/src/authTokens.ts +118 -0
- package/src/authVerification.test.ts +293 -0
- package/src/betterAuth.ts +24 -0
- package/src/betterAuthApp.test.ts +1 -0
- package/src/betterAuthApp.ts +27 -9
- package/src/betterAuthSetup.test.ts +568 -38
- package/src/betterAuthSetup.ts +260 -5
- package/src/collectionRegistry.test.ts +165 -0
- package/src/collectionRegistry.ts +115 -0
- package/src/configurationApp.ts +13 -7
- package/src/docLoader.test.ts +45 -1
- package/src/docLoader.ts +37 -6
- package/src/express.d.ts +1 -0
- package/src/expressServer.test.ts +130 -66
- package/src/expressServer.ts +75 -19
- package/src/githubAuth.test.ts +60 -55
- package/src/index.ts +58 -0
- package/src/mcp/auth.test.ts +47 -0
- package/src/mcp/auth.ts +32 -11
- package/src/mcp/handlers.ts +45 -172
- package/src/mcp/integration.test.ts +59 -9
- package/src/mcp/query.ts +2 -4
- package/src/mcp/registry.ts +29 -20
- package/src/mcp/schemaGenerator.test.ts +8 -0
- package/src/mcp/schemaGenerator.ts +49 -131
- package/src/mcp/server.ts +2 -0
- package/src/mcp/serviceTokens.test.ts +330 -0
- package/src/mcp/serviceTokens.ts +307 -0
- package/src/mcp/toolGenerator.test.ts +1 -1
- package/src/mcp/types.ts +2 -6
- package/src/models/mcpServiceToken.test.ts +129 -0
- package/src/models/mcpServiceToken.ts +158 -0
- package/src/openApi.test.ts +80 -64
- package/src/openApiBuilder.test.ts +95 -7
- package/src/openApiBuilder.ts +46 -9
- package/src/openApiCompat.ts +1 -1
- package/src/openApiValidator.test.ts +49 -54
- package/src/openApiValidator.ts +1 -3
- package/src/plugins.test.ts +14 -0
- package/src/plugins.ts +34 -9
- package/src/populate.test.ts +34 -0
- package/src/populate.ts +40 -29
- package/src/rateLimit/applyTrustProxy.ts +17 -0
- package/src/rateLimit/createStore.ts +25 -0
- package/src/rateLimit/memoryStore.ts +40 -0
- package/src/rateLimit/middleware.ts +79 -0
- package/src/rateLimit/mongoStore.test.ts +80 -0
- package/src/rateLimit/mongoStore.ts +76 -0
- package/src/rateLimit/policies.ts +130 -0
- package/src/rateLimit/rateLimit.test.ts +328 -0
- package/src/rateLimit/redisStore.ioredis.test.ts +29 -0
- package/src/rateLimit/redisStore.test.ts +114 -0
- package/src/rateLimit/redisStore.ts +85 -0
- package/src/rateLimit/types.ts +64 -0
- package/src/rbac/access.ts +5 -1
- package/src/rbac/assertAllowed.test.ts +325 -0
- package/src/rbac/assertAllowed.ts +157 -0
- package/src/rbac/backfillAdmins.test.ts +124 -0
- package/src/rbac/fieldViews.test.ts +89 -0
- package/src/rbac/modelRouterAccess.test.ts +126 -0
- package/src/rbac/modelRouterAccess.ts +5 -2
- package/src/rbac/permissionUtils.ts +3 -2
- package/src/rbac/realtimeAccess.test.ts +109 -1
- package/src/rbac/resolve.ts +5 -4
- package/src/rbac/roleManager.test.ts +169 -0
- package/src/rbac/routes.test.ts +233 -0
- package/src/rbac/routes.ts +16 -6
- package/src/rbac/statements.test.ts +2 -0
- package/src/rbac/statements.ts +12 -1
- package/src/realtime/deprecation.test.ts +60 -0
- package/src/realtime/deprecation.ts +32 -0
- package/src/realtime/realtime.test.ts +8 -4
- package/src/realtime/realtimeApp.ts +10 -11
- package/src/realtime/realtimeAppSetup.test.ts +32 -5
- package/src/realtime/registry.ts +48 -42
- package/src/realtime/sessionRevalidation.test.ts +57 -44
- package/src/realtime/socketAuth.test.ts +75 -23
- package/src/realtime/socketAuth.ts +17 -6
- package/src/realtime/socketUser.ts +5 -3
- package/src/realtime/types.ts +14 -4
- package/src/schemaMetadata.test.ts +405 -0
- package/src/schemaMetadata.ts +593 -0
- package/src/scrubAdminFields.test.ts +105 -0
- package/src/seedRunner.test.ts +591 -0
- package/src/seedRunner.ts +464 -0
- package/src/sync/docMatchesMutationData.test.ts +16 -0
- package/src/sync/ensureSyncIndexes.test.ts +54 -15
- package/src/sync/executors.test.ts +40 -0
- package/src/sync/executors.ts +24 -12
- package/src/sync/integration.test.ts +15 -7
- package/src/sync/loadHarness.ts +28 -19
- package/src/sync/models.ts +32 -18
- package/src/sync/mutationHandler.test.ts +16 -16
- package/src/sync/mutationHandler.ts +9 -7
- package/src/sync/registrationSideEffects.test.ts +126 -0
- package/src/sync/registrationSideEffects.ts +131 -0
- package/src/sync/registry.ts +45 -171
- package/src/sync/routes.ts +3 -2
- package/src/sync/scripts/compactTombstones.ts +0 -2
- package/src/sync/sessionRevalidationIntegration.test.ts +12 -11
- package/src/sync/sync.test.ts +25 -23
- package/src/sync/syncApp.ts +4 -4
- package/src/sync/syncBatch.ts +3 -2
- package/src/sync/syncFrontier.test.ts +17 -15
- package/src/sync/syncPhaseC.test.ts +54 -43
- package/src/sync/syncRoutes.test.ts +51 -36
- package/src/sync/syncSeqPlugin.ts +66 -44
- package/src/sync/syncSocket.test.ts +112 -81
- package/src/terrenoApp.mcpServiceTokens.test.ts +173 -0
- package/src/terrenoApp.ts +87 -15
- package/src/tests/models.ts +14 -1
- package/src/types/authToken.ts +43 -0
- package/src/types/mcpServiceToken.ts +54 -0
- package/src/webhooks/headerValue.test.ts +22 -0
- package/src/webhooks/headerValue.ts +12 -0
- package/src/webhooks/idempotency/memoryStore.ts +34 -0
- package/src/webhooks/idempotency/mongoStore.test.ts +274 -0
- package/src/webhooks/idempotency/mongoStore.ts +83 -0
- package/src/webhooks/idempotency/webhookReceipt.ts +70 -0
- package/src/webhooks/rawBody.test.ts +74 -0
- package/src/webhooks/rawBody.ts +23 -0
- package/src/webhooks/timingSafeEqual.ts +16 -0
- package/src/webhooks/verifiers/hmac.test.ts +110 -0
- package/src/webhooks/verifiers/hmac.ts +54 -0
- package/src/webhooks/verifiers/providerVerifiers.test.ts +388 -0
- package/src/webhooks/verifiers/sendgrid.ts +59 -0
- package/src/webhooks/verifiers/stripe.ts +67 -0
- package/src/webhooks/verifiers/twilio.ts +69 -0
- package/src/webhooks/webhooksApp.test.ts +221 -0
- package/src/webhooks/webhooksApp.ts +144 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import {beforeEach, describe, expect, it} from "bun:test";
|
|
2
|
+
import type express from "express";
|
|
3
|
+
import mongoose, {type Model, model, Schema} from "mongoose";
|
|
4
|
+
import type TestAgent from "supertest/lib/agent";
|
|
5
|
+
|
|
6
|
+
import {type UserModel as AuthUserModel, addAuthRoutes, setupAuth} from "../auth";
|
|
7
|
+
import {apiErrorMiddleware} from "../errors";
|
|
8
|
+
import {authAsUser, getBaseServer, setupDb, UserModel} from "../tests";
|
|
9
|
+
import {createAccess} from "./access";
|
|
10
|
+
import {rbacRouter} from "./routes";
|
|
11
|
+
import {type PermissionSet, terrenoStatements} from "./statements";
|
|
12
|
+
import type {AnyTerrenoAccess} from "./types";
|
|
13
|
+
|
|
14
|
+
interface RouteUser {
|
|
15
|
+
admin: boolean;
|
|
16
|
+
email: string;
|
|
17
|
+
roles: string[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const appStatements = {
|
|
21
|
+
...terrenoStatements,
|
|
22
|
+
todo: ["create", "read", "update", "delete", "list"],
|
|
23
|
+
} as const;
|
|
24
|
+
|
|
25
|
+
const allPermissions: PermissionSet = Object.fromEntries(
|
|
26
|
+
Object.entries(appStatements).map(([resource, actions]) => [resource, [...actions]])
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const getRouteUserModel = (): Model<RouteUser> => {
|
|
30
|
+
const modelName = "RbacRoutesTestUser";
|
|
31
|
+
if (mongoose.models[modelName]) {
|
|
32
|
+
return mongoose.models[modelName] as Model<RouteUser>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const schema = new Schema<RouteUser>({
|
|
36
|
+
admin: {default: false, description: "Whether the user is an administrator", type: Boolean},
|
|
37
|
+
email: {description: "The user's email address", required: true, type: String},
|
|
38
|
+
roles: {default: [], description: "The user's RBAC roles", type: [String]},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return model<RouteUser>(modelName, schema);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const authUserModel = UserModel as unknown as AuthUserModel;
|
|
45
|
+
|
|
46
|
+
const createRequestMutationAccess = (
|
|
47
|
+
access: AnyTerrenoAccess,
|
|
48
|
+
mutate: (request: express.Request) => void
|
|
49
|
+
): AnyTerrenoAccess => ({
|
|
50
|
+
...access,
|
|
51
|
+
middleware: (permissions, options) => {
|
|
52
|
+
const accessMiddleware = access.middleware(permissions, options);
|
|
53
|
+
return (request, response, next) => {
|
|
54
|
+
accessMiddleware(request, response, (error?: unknown) => {
|
|
55
|
+
if (error) {
|
|
56
|
+
next(error);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
mutate(request);
|
|
60
|
+
next();
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("rbacRouter", () => {
|
|
67
|
+
let app: express.Application;
|
|
68
|
+
let adminAgent: TestAgent;
|
|
69
|
+
let routeUserModel: Model<RouteUser>;
|
|
70
|
+
let targetUserId: string;
|
|
71
|
+
|
|
72
|
+
beforeEach(async () => {
|
|
73
|
+
await setupDb();
|
|
74
|
+
routeUserModel = getRouteUserModel();
|
|
75
|
+
await routeUserModel.deleteMany({});
|
|
76
|
+
const targetUser = await routeUserModel.create({
|
|
77
|
+
email: "target@example.com",
|
|
78
|
+
roles: ["member"],
|
|
79
|
+
});
|
|
80
|
+
targetUserId = targetUser.id;
|
|
81
|
+
|
|
82
|
+
const access = createAccess({
|
|
83
|
+
connection: mongoose.connection,
|
|
84
|
+
resolvePermissions: async ({user}) => (user.admin ? allPermissions : {}),
|
|
85
|
+
statements: appStatements,
|
|
86
|
+
userModel: routeUserModel as unknown as AuthUserModel,
|
|
87
|
+
});
|
|
88
|
+
await access.roles.seedDefaults();
|
|
89
|
+
|
|
90
|
+
app = getBaseServer();
|
|
91
|
+
setupAuth(app, authUserModel);
|
|
92
|
+
addAuthRoutes(app, authUserModel);
|
|
93
|
+
rbacRouter({
|
|
94
|
+
access,
|
|
95
|
+
basePath: "/rbac",
|
|
96
|
+
userModel: routeUserModel as unknown as AuthUserModel,
|
|
97
|
+
}).register(app);
|
|
98
|
+
rbacRouter({
|
|
99
|
+
access: createRequestMutationAccess(access, (request) => {
|
|
100
|
+
request.user = undefined;
|
|
101
|
+
}),
|
|
102
|
+
basePath: "/rbac-unauthorized",
|
|
103
|
+
userModel: routeUserModel as unknown as AuthUserModel,
|
|
104
|
+
}).register(app);
|
|
105
|
+
rbacRouter({
|
|
106
|
+
access: createRequestMutationAccess(access, (request) => {
|
|
107
|
+
Reflect.deleteProperty(request.params, "id");
|
|
108
|
+
Reflect.deleteProperty(request.params, "name");
|
|
109
|
+
}),
|
|
110
|
+
basePath: "/rbac-invalid-params",
|
|
111
|
+
userModel: routeUserModel as unknown as AuthUserModel,
|
|
112
|
+
}).register(app);
|
|
113
|
+
app.use(apiErrorMiddleware);
|
|
114
|
+
|
|
115
|
+
adminAgent = await authAsUser(app, "admin");
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("serves statements and supports role and user operations", async () => {
|
|
119
|
+
const statementsResponse = await adminAgent.get("/rbac/statements").expect(200);
|
|
120
|
+
expect(statementsResponse.body.data.statements.rbac).toEqual([
|
|
121
|
+
"read",
|
|
122
|
+
"manageRoles",
|
|
123
|
+
"assignRoles",
|
|
124
|
+
]);
|
|
125
|
+
|
|
126
|
+
const rolesResponse = await adminAgent.get("/rbac/roles").expect(200);
|
|
127
|
+
expect(rolesResponse.body.data.map((role: {name: string}) => role.name)).toEqual(
|
|
128
|
+
expect.arrayContaining(["superadmin", "member"])
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const createResponse = await adminAgent
|
|
132
|
+
.post("/rbac/roles")
|
|
133
|
+
.send({
|
|
134
|
+
displayName: "Route Editor",
|
|
135
|
+
name: "route-editor",
|
|
136
|
+
permissions: {todo: ["read"]},
|
|
137
|
+
})
|
|
138
|
+
.expect(201);
|
|
139
|
+
expect(createResponse.body.data.name).toBe("route-editor");
|
|
140
|
+
|
|
141
|
+
const updateResponse = await adminAgent
|
|
142
|
+
.patch("/rbac/roles/route-editor")
|
|
143
|
+
.send({displayName: "Updated Route Editor"})
|
|
144
|
+
.expect(200);
|
|
145
|
+
expect(updateResponse.body.data.displayName).toBe("Updated Route Editor");
|
|
146
|
+
|
|
147
|
+
const rolePreviewResponse = await adminAgent
|
|
148
|
+
.post("/rbac/roles/route-editor/preview")
|
|
149
|
+
.send({permissions: {todo: ["read", "update"]}})
|
|
150
|
+
.expect(200);
|
|
151
|
+
expect(rolePreviewResponse.body.data.gained.todo).toEqual(["update"]);
|
|
152
|
+
|
|
153
|
+
const permissionsResponse = await adminAgent
|
|
154
|
+
.get(`/rbac/users/${targetUserId}/permissions`)
|
|
155
|
+
.expect(200);
|
|
156
|
+
expect(permissionsResponse.body.data.roles).toEqual(["member"]);
|
|
157
|
+
|
|
158
|
+
await adminAgent
|
|
159
|
+
.put(`/rbac/users/${targetUserId}/roles`)
|
|
160
|
+
.send({roleNames: ["auditor"]})
|
|
161
|
+
.expect(200);
|
|
162
|
+
const assignedUser = await routeUserModel.findById(targetUserId);
|
|
163
|
+
expect(assignedUser?.roles).toEqual(["auditor"]);
|
|
164
|
+
|
|
165
|
+
const assignmentPreviewResponse = await adminAgent
|
|
166
|
+
.post(`/rbac/users/${targetUserId}/roles/preview`)
|
|
167
|
+
.send({roleNames: ["member"]})
|
|
168
|
+
.expect(200);
|
|
169
|
+
expect(assignmentPreviewResponse.body.data).toHaveProperty("gained");
|
|
170
|
+
|
|
171
|
+
await adminAgent.delete("/rbac/roles/route-editor").expect(204);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("returns unauthorized when a handler has no actor", async () => {
|
|
175
|
+
const actorlessRoutes = [
|
|
176
|
+
{body: {}, method: "post", path: "/rbac-unauthorized/roles"},
|
|
177
|
+
{body: {}, method: "patch", path: "/rbac-unauthorized/roles/member"},
|
|
178
|
+
{method: "delete", path: "/rbac-unauthorized/roles/member"},
|
|
179
|
+
{
|
|
180
|
+
body: {roleNames: ["member"]},
|
|
181
|
+
method: "put",
|
|
182
|
+
path: `/rbac-unauthorized/users/${targetUserId}/roles`,
|
|
183
|
+
},
|
|
184
|
+
] as const;
|
|
185
|
+
|
|
186
|
+
for (const route of actorlessRoutes) {
|
|
187
|
+
const response =
|
|
188
|
+
route.method === "post"
|
|
189
|
+
? await adminAgent.post(route.path).send(route.body)
|
|
190
|
+
: route.method === "patch"
|
|
191
|
+
? await adminAgent.patch(route.path).send(route.body)
|
|
192
|
+
: route.method === "put"
|
|
193
|
+
? await adminAgent.put(route.path).send(route.body)
|
|
194
|
+
: await adminAgent.delete(route.path);
|
|
195
|
+
expect(response.status).toBe(401);
|
|
196
|
+
expect(response.body.title).toBe("Unauthorized");
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("validates missing route parameters", async () => {
|
|
201
|
+
const roleResponse = await adminAgent
|
|
202
|
+
.patch("/rbac-invalid-params/roles/member")
|
|
203
|
+
.send({displayName: "Missing Name"});
|
|
204
|
+
expect(roleResponse.status).toBe(400);
|
|
205
|
+
expect(roleResponse.body.title).toBe("Role name is required");
|
|
206
|
+
|
|
207
|
+
const userResponse = await adminAgent.get(
|
|
208
|
+
`/rbac-invalid-params/users/${targetUserId}/permissions`
|
|
209
|
+
);
|
|
210
|
+
expect(userResponse.status).toBe(400);
|
|
211
|
+
expect(userResponse.body.title).toBe("User id is required");
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("validates role assignment bodies and missing users", async () => {
|
|
215
|
+
const missingRoleNamesResponse = await adminAgent
|
|
216
|
+
.put(`/rbac/users/${targetUserId}/roles`)
|
|
217
|
+
.send({});
|
|
218
|
+
expect(missingRoleNamesResponse.status).toBe(400);
|
|
219
|
+
expect(missingRoleNamesResponse.body.title).toBe("roleNames is required");
|
|
220
|
+
|
|
221
|
+
const missingPreviewRoleNamesResponse = await adminAgent
|
|
222
|
+
.post(`/rbac/users/${targetUserId}/roles/preview`)
|
|
223
|
+
.send({});
|
|
224
|
+
expect(missingPreviewRoleNamesResponse.status).toBe(400);
|
|
225
|
+
expect(missingPreviewRoleNamesResponse.body.title).toBe("roleNames is required");
|
|
226
|
+
|
|
227
|
+
const missingUserResponse = await adminAgent.get(
|
|
228
|
+
`/rbac/users/${new mongoose.Types.ObjectId()}/permissions`
|
|
229
|
+
);
|
|
230
|
+
expect(missingUserResponse.status).toBe(404);
|
|
231
|
+
expect(missingUserResponse.body.title).toBe("User not found");
|
|
232
|
+
});
|
|
233
|
+
});
|
package/src/rbac/routes.ts
CHANGED
|
@@ -6,6 +6,13 @@ import {APIError} from "../errors";
|
|
|
6
6
|
import type {TerrenoPlugin} from "../terrenoPlugin";
|
|
7
7
|
import type {AnyTerrenoAccess} from "./types";
|
|
8
8
|
|
|
9
|
+
const pathParam = (value: string | string[] | undefined, title: string): string => {
|
|
10
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
11
|
+
throw new APIError({status: 400, title});
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
};
|
|
15
|
+
|
|
9
16
|
export interface RbacRouterOptions {
|
|
10
17
|
access: AnyTerrenoAccess;
|
|
11
18
|
userModel: UserModel;
|
|
@@ -70,7 +77,7 @@ export const rbacRouter = ({
|
|
|
70
77
|
const role = await access.roles.update({
|
|
71
78
|
actor,
|
|
72
79
|
changes: req.body,
|
|
73
|
-
roleName: req.params.name,
|
|
80
|
+
roleName: pathParam(req.params.name, "Role name is required"),
|
|
74
81
|
});
|
|
75
82
|
return res.json({data: role});
|
|
76
83
|
})
|
|
@@ -85,7 +92,10 @@ export const rbacRouter = ({
|
|
|
85
92
|
if (!actor) {
|
|
86
93
|
throw new APIError({status: 401, title: "Unauthorized"});
|
|
87
94
|
}
|
|
88
|
-
await access.roles.remove({
|
|
95
|
+
await access.roles.remove({
|
|
96
|
+
actor,
|
|
97
|
+
roleName: pathParam(req.params.name, "Role name is required"),
|
|
98
|
+
});
|
|
89
99
|
return res.status(204).send();
|
|
90
100
|
})
|
|
91
101
|
);
|
|
@@ -97,7 +107,7 @@ export const rbacRouter = ({
|
|
|
97
107
|
asyncHandler(async (req, res) => {
|
|
98
108
|
const diff = await access.roles.previewRoleChange({
|
|
99
109
|
permissions: req.body.permissions,
|
|
100
|
-
roleName: req.params.name,
|
|
110
|
+
roleName: pathParam(req.params.name, "Role name is required"),
|
|
101
111
|
});
|
|
102
112
|
return res.json({data: diff});
|
|
103
113
|
})
|
|
@@ -108,7 +118,7 @@ export const rbacRouter = ({
|
|
|
108
118
|
authenticateMiddleware(),
|
|
109
119
|
access.middleware({rbac: ["read"]}),
|
|
110
120
|
asyncHandler(async (req, res) => {
|
|
111
|
-
const user = await userModel.findById(req.params.id);
|
|
121
|
+
const user = await userModel.findById(pathParam(req.params.id, "User id is required"));
|
|
112
122
|
if (!user) {
|
|
113
123
|
throw new APIError({status: 404, title: "User not found"});
|
|
114
124
|
}
|
|
@@ -140,7 +150,7 @@ export const rbacRouter = ({
|
|
|
140
150
|
await access.roles.assign({
|
|
141
151
|
actor,
|
|
142
152
|
roleNames: req.body.roleNames,
|
|
143
|
-
userId: req.params.id,
|
|
153
|
+
userId: pathParam(req.params.id, "User id is required"),
|
|
144
154
|
});
|
|
145
155
|
return res.json({data: {success: true}});
|
|
146
156
|
})
|
|
@@ -158,7 +168,7 @@ export const rbacRouter = ({
|
|
|
158
168
|
const diff = await access.roles.previewAssignment({
|
|
159
169
|
actor,
|
|
160
170
|
roleNames: req.body.roleNames,
|
|
161
|
-
userId: req.params.id,
|
|
171
|
+
userId: pathParam(req.params.id, "User id is required"),
|
|
162
172
|
});
|
|
163
173
|
return res.json({data: diff});
|
|
164
174
|
})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {describe, expect, it} from "bun:test";
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
+
ADMIN_PAGE_PERMISSION,
|
|
4
5
|
expandRolePermissions,
|
|
5
6
|
mergeStatements,
|
|
6
7
|
READ_ACTIONS,
|
|
@@ -11,6 +12,7 @@ import {
|
|
|
11
12
|
describe("rbac statements", () => {
|
|
12
13
|
it("exports terreno default vocabulary", () => {
|
|
13
14
|
expect(terrenoStatements.admin).toContain("access");
|
|
15
|
+
expect(ADMIN_PAGE_PERMISSION).toEqual({admin: ["access"]});
|
|
14
16
|
expect(terrenoStatements.rbac).toContain("manageRoles");
|
|
15
17
|
expect(terrenoStatements.user).toContain("read");
|
|
16
18
|
expect(terrenoStatements.configuration).toContain("update");
|
package/src/rbac/statements.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
const MODEL_CRUD = ["create", "list", "read", "update", "delete"] as const;
|
|
2
|
+
export const ADMIN_MODEL_ACCESS = ["read", "write", "writeOwned"] as const;
|
|
3
|
+
|
|
4
|
+
/** Resource/action that opens the admin panel. Other admin permissions do not grant entry. */
|
|
5
|
+
export const ADMIN_PAGE_RESOURCE = "admin" as const;
|
|
6
|
+
export const ADMIN_PAGE_ACTION = "access" as const;
|
|
7
|
+
export const ADMIN_PAGE_PERMISSION = {
|
|
8
|
+
[ADMIN_PAGE_RESOURCE]: [ADMIN_PAGE_ACTION],
|
|
9
|
+
} as const;
|
|
2
10
|
|
|
3
11
|
export const terrenoStatements = {
|
|
4
|
-
admin: [
|
|
12
|
+
admin: [ADMIN_PAGE_ACTION, "runScripts", "viewBackgroundTasks"],
|
|
13
|
+
adminConsentForm: ADMIN_MODEL_ACCESS,
|
|
14
|
+
adminConsentResponse: ADMIN_MODEL_ACCESS,
|
|
15
|
+
adminFeatureFlag: ADMIN_MODEL_ACCESS,
|
|
5
16
|
configuration: ["read", "update"],
|
|
6
17
|
consentForm: MODEL_CRUD,
|
|
7
18
|
consentResponse: ["list", "read"],
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {afterEach, describe, expect, it, spyOn} from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {modelRouter} from "../api";
|
|
4
|
+
import {logger} from "../logger";
|
|
5
|
+
import {Permissions} from "../permissions";
|
|
6
|
+
import {FoodModel} from "../tests";
|
|
7
|
+
import {
|
|
8
|
+
REALTIME_DEPRECATION_MESSAGE,
|
|
9
|
+
resetRealtimeDeprecationWarningsForTests,
|
|
10
|
+
} from "./deprecation";
|
|
11
|
+
import {clearRealtimeRegistry} from "./registry";
|
|
12
|
+
|
|
13
|
+
const realtimeConfig = {
|
|
14
|
+
methods: ["create", "update", "delete"] as Array<"create" | "update" | "delete">,
|
|
15
|
+
roomStrategy: "model" as const,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const permissions = {
|
|
19
|
+
create: [Permissions.IsAny],
|
|
20
|
+
delete: [Permissions.IsAny],
|
|
21
|
+
list: [Permissions.IsAny],
|
|
22
|
+
read: [Permissions.IsAny],
|
|
23
|
+
update: [Permissions.IsAny],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
describe("modelRouter realtime deprecation", () => {
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
resetRealtimeDeprecationWarningsForTests();
|
|
29
|
+
clearRealtimeRegistry();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("warns once per model and path when realtime is configured", () => {
|
|
33
|
+
const warnSpy = spyOn(logger, "warn").mockImplementation(() => logger);
|
|
34
|
+
|
|
35
|
+
modelRouter("/foods", FoodModel, {permissions, realtime: realtimeConfig});
|
|
36
|
+
modelRouter("/foods", FoodModel, {permissions, realtime: realtimeConfig});
|
|
37
|
+
|
|
38
|
+
const deprecationCalls = warnSpy.mock.calls.filter((args) =>
|
|
39
|
+
String(args[0]).includes(REALTIME_DEPRECATION_MESSAGE)
|
|
40
|
+
);
|
|
41
|
+
expect(deprecationCalls).toHaveLength(1);
|
|
42
|
+
expect(String(deprecationCalls[0]?.[0])).toContain("Food at /foods");
|
|
43
|
+
|
|
44
|
+
warnSpy.mockRestore();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("warns when realtime is used without the path form", () => {
|
|
48
|
+
const warnSpy = spyOn(logger, "warn").mockImplementation(() => logger);
|
|
49
|
+
|
|
50
|
+
modelRouter(FoodModel, {permissions, realtime: realtimeConfig});
|
|
51
|
+
|
|
52
|
+
const deprecationCalls = warnSpy.mock.calls.filter((args) =>
|
|
53
|
+
String(args[0]).includes(REALTIME_DEPRECATION_MESSAGE)
|
|
54
|
+
);
|
|
55
|
+
expect(deprecationCalls).toHaveLength(1);
|
|
56
|
+
expect(String(deprecationCalls[0]?.[0])).toContain("(Food)");
|
|
57
|
+
|
|
58
|
+
warnSpy.mockRestore();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {logger} from "../logger";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One-line warning for modelRouter `realtime`. Keep in sync with the
|
|
5
|
+
* `@terreno/rtk` helpers and `docs/implementationPlans/remove-legacy-realtime.md`.
|
|
6
|
+
*/
|
|
7
|
+
export const REALTIME_DEPRECATION_MESSAGE =
|
|
8
|
+
"modelRouter `realtime` is deprecated and will be removed in Terreno 58. Use `sync` with `@terreno/syncdb` instead. See docs/how-to/migrate-rtk-to-syncdb.md. RealtimeApp remains required for sync sockets.";
|
|
9
|
+
|
|
10
|
+
const warnedKeys = new Set<string>();
|
|
11
|
+
|
|
12
|
+
const warningKey = (modelName: string, routePath?: string): string =>
|
|
13
|
+
`${modelName}:${routePath ?? ""}`;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Emits a one-time deprecation warning per model/routePath per process when a
|
|
17
|
+
* consumer enables the legacy RTK cache-patching `realtime` option.
|
|
18
|
+
*/
|
|
19
|
+
export const warnRealtimeDeprecated = (modelName: string, routePath?: string): void => {
|
|
20
|
+
const key = warningKey(modelName, routePath);
|
|
21
|
+
if (warnedKeys.has(key)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
warnedKeys.add(key);
|
|
25
|
+
const location = routePath ? `${modelName} at ${routePath}` : modelName;
|
|
26
|
+
logger.warn(`[realtime] ${REALTIME_DEPRECATION_MESSAGE} (${location})`);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** @internal Test helper — clears one-time realtime deprecation warnings. */
|
|
30
|
+
export const resetRealtimeDeprecationWarningsForTests = (): void => {
|
|
31
|
+
warnedKeys.clear();
|
|
32
|
+
};
|
|
@@ -2779,14 +2779,16 @@ describe("RealtimeApp.onServerCreated", () => {
|
|
|
2779
2779
|
return server;
|
|
2780
2780
|
};
|
|
2781
2781
|
|
|
2782
|
-
it("throws when
|
|
2782
|
+
it("throws when no socket authentication method is configured", () => {
|
|
2783
2783
|
const originalSecret = process.env.TOKEN_SECRET;
|
|
2784
2784
|
process.env.TOKEN_SECRET = "";
|
|
2785
2785
|
|
|
2786
2786
|
const app = new RealtimeApp({tokenSecret: undefined});
|
|
2787
2787
|
const server = makeServer();
|
|
2788
2788
|
|
|
2789
|
-
expect(() => app.onServerCreated(server)).toThrow(
|
|
2789
|
+
expect(() => app.onServerCreated(server)).toThrow(
|
|
2790
|
+
"Socket authentication requires TOKEN_SECRET or Better Auth"
|
|
2791
|
+
);
|
|
2790
2792
|
|
|
2791
2793
|
process.env.TOKEN_SECRET = originalSecret;
|
|
2792
2794
|
});
|
|
@@ -3440,7 +3442,7 @@ describe("RealtimeApp — onServerCreated and setupAdapter", () => {
|
|
|
3440
3442
|
server.close();
|
|
3441
3443
|
});
|
|
3442
3444
|
|
|
3443
|
-
it("onServerCreated throws when
|
|
3445
|
+
it("onServerCreated throws when no socket authentication method is configured", () => {
|
|
3444
3446
|
const http = require("node:http");
|
|
3445
3447
|
const origSecret = process.env.TOKEN_SECRET;
|
|
3446
3448
|
process.env.TOKEN_SECRET = "";
|
|
@@ -3449,7 +3451,9 @@ describe("RealtimeApp — onServerCreated and setupAdapter", () => {
|
|
|
3449
3451
|
app.register(expressApp);
|
|
3450
3452
|
const server = http.createServer(expressApp);
|
|
3451
3453
|
|
|
3452
|
-
expect(() => app.onServerCreated(server)).toThrow(
|
|
3454
|
+
expect(() => app.onServerCreated(server)).toThrow(
|
|
3455
|
+
"Socket authentication requires TOKEN_SECRET or Better Auth"
|
|
3456
|
+
);
|
|
3453
3457
|
process.env.TOKEN_SECRET = origSecret;
|
|
3454
3458
|
server.close();
|
|
3455
3459
|
});
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// noExplicitAny: Socket.io handler signatures require dynamic args
|
|
2
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: Socket.io handler signatures require dynamic args
|
|
3
1
|
import type http from "node:http";
|
|
4
2
|
import * as Sentry from "@sentry/bun";
|
|
5
3
|
import type express from "express";
|
|
@@ -323,7 +321,7 @@ export const installRealtimeSocketHandlers = (
|
|
|
323
321
|
* TerrenoPlugin that provides real-time sync via Socket.io and MongoDB change streams.
|
|
324
322
|
*
|
|
325
323
|
* Attaches a Socket.io server to the HTTP server created by TerrenoApp.start(),
|
|
326
|
-
* sets up JWT authentication for socket connections, manages room subscriptions
|
|
324
|
+
* sets up JWT and/or Better Auth authentication for socket connections, manages room subscriptions
|
|
327
325
|
* (model, document, and query rooms), and starts a change stream watcher that
|
|
328
326
|
* emits events to connected clients.
|
|
329
327
|
*
|
|
@@ -394,14 +392,14 @@ export class RealtimeApp implements TerrenoPlugin {
|
|
|
394
392
|
},
|
|
395
393
|
});
|
|
396
394
|
|
|
397
|
-
// Authentication middleware: legacy JWT first, optionally Better Auth sessions.
|
|
395
|
+
// Authentication middleware: legacy JWT first when configured, optionally Better Auth sessions.
|
|
398
396
|
const tokenSecret = this.config.tokenSecret ?? process.env.TOKEN_SECRET;
|
|
399
|
-
if (!tokenSecret) {
|
|
397
|
+
if (!tokenSecret && !this.config.betterAuth) {
|
|
400
398
|
throw new APIError({
|
|
401
399
|
status: 500,
|
|
402
400
|
title:
|
|
403
|
-
"[realtime]
|
|
404
|
-
"Set process.env.TOKEN_SECRET
|
|
401
|
+
"[realtime] Socket authentication requires TOKEN_SECRET or Better Auth. " +
|
|
402
|
+
"Set process.env.TOKEN_SECRET, pass tokenSecret, or configure betterAuth.",
|
|
405
403
|
});
|
|
406
404
|
}
|
|
407
405
|
|
|
@@ -418,13 +416,14 @@ export class RealtimeApp implements TerrenoPlugin {
|
|
|
418
416
|
createSocketAuthMiddleware({
|
|
419
417
|
betterAuth: this.config.betterAuth,
|
|
420
418
|
issuer: resolveTokenIssuer,
|
|
421
|
-
tokenSecret,
|
|
419
|
+
...(tokenSecret ? {tokenSecret} : {}),
|
|
422
420
|
})
|
|
423
421
|
);
|
|
424
422
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
423
|
+
const authKinds = [tokenSecret ? "JWT" : null, this.config.betterAuth ? "Better Auth" : null]
|
|
424
|
+
.filter(Boolean)
|
|
425
|
+
.join(" + ");
|
|
426
|
+
logInfo(`[realtime] Socket auth middleware added (${authKinds})`);
|
|
428
427
|
|
|
429
428
|
// Task 9.21: tenant/custom sync scopes can only be resolved from the full user
|
|
430
429
|
// document, so warn loudly here (once, at startup) rather than silently serving
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* are process-wide and would break later files that need the real implementations).
|
|
6
6
|
*/
|
|
7
7
|
import {afterEach, beforeEach, describe, expect, it} from "bun:test";
|
|
8
|
-
|
|
9
8
|
import type http from "node:http";
|
|
9
|
+
import {assert} from "chai";
|
|
10
10
|
|
|
11
11
|
import {RealtimeApp} from "./realtimeApp";
|
|
12
12
|
|
|
@@ -100,7 +100,7 @@ describe("RealtimeApp.onServerCreated", () => {
|
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
afterEach(() => {
|
|
103
|
-
|
|
103
|
+
Reflect.deleteProperty(process.env, "TOKEN_SECRET");
|
|
104
104
|
});
|
|
105
105
|
|
|
106
106
|
it("wires up auth middleware, connection handlers, and the change-stream watcher", () => {
|
|
@@ -151,9 +151,36 @@ describe("RealtimeApp.onServerCreated", () => {
|
|
|
151
151
|
expect(lastIo().handlers.has("connection")).toBe(true);
|
|
152
152
|
});
|
|
153
153
|
|
|
154
|
-
it("
|
|
155
|
-
|
|
154
|
+
it("starts with Better Auth when no token secret is available", () => {
|
|
155
|
+
Reflect.deleteProperty(process.env, "TOKEN_SECRET");
|
|
156
|
+
const app = new RealtimeApp(
|
|
157
|
+
testRealtimeOptions({
|
|
158
|
+
betterAuth: {
|
|
159
|
+
auth: {
|
|
160
|
+
api: {
|
|
161
|
+
getSession: async () => ({
|
|
162
|
+
session: {id: "session-1"},
|
|
163
|
+
user: {id: "better-auth-user"},
|
|
164
|
+
}),
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
} as unknown as NonNullable<
|
|
168
|
+
NonNullable<ConstructorParameters<typeof RealtimeApp>[0]>["betterAuth"]
|
|
169
|
+
>,
|
|
170
|
+
})
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
assert.doesNotThrow(() => app.onServerCreated(fakeServer));
|
|
174
|
+
assert.lengthOf(lastIo().middleware, 1);
|
|
175
|
+
assert.isTrue(lastIo().handlers.has("connection"));
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("throws when no socket authentication method is available", () => {
|
|
179
|
+
Reflect.deleteProperty(process.env, "TOKEN_SECRET");
|
|
156
180
|
const app = new RealtimeApp(testRealtimeOptions());
|
|
157
|
-
|
|
181
|
+
assert.throws(
|
|
182
|
+
() => app.onServerCreated(fakeServer),
|
|
183
|
+
"Socket authentication requires TOKEN_SECRET or Better Auth"
|
|
184
|
+
);
|
|
158
185
|
});
|
|
159
186
|
});
|