@rebasepro/server-core 0.7.0 → 0.9.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 +2 -2
- package/dist/api/ast-schema-editor.d.ts +21 -0
- package/dist/api/collections_for_test/callbacks_test_collection.d.ts +2 -0
- package/dist/api/errors.d.ts +53 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/logs-routes.d.ts +37 -0
- package/dist/api/openapi-generator.d.ts +16 -0
- package/dist/api/rest/api-generator.d.ts +68 -0
- package/{src/api/rest/index.ts → dist/api/rest/index.d.ts} +0 -1
- package/dist/api/rest/query-parser.d.ts +6 -0
- package/dist/api/schema-editor-routes.d.ts +3 -0
- package/dist/api/types.d.ts +56 -0
- package/dist/auth/adapter-middleware.d.ts +43 -0
- package/dist/auth/admin-roles-route.d.ts +18 -0
- package/dist/auth/admin-user-ops.d.ts +79 -0
- package/dist/auth/admin-users-route.d.ts +28 -0
- package/dist/auth/api-keys/api-key-middleware.d.ts +39 -0
- package/{src/auth/api-keys/api-key-permission-guard.ts → dist/auth/api-keys/api-key-permission-guard.d.ts} +2 -34
- package/dist/auth/api-keys/api-key-routes.d.ts +20 -0
- package/dist/auth/api-keys/api-key-store.d.ts +35 -0
- package/{src/auth/api-keys/api-key-types.ts → dist/auth/api-keys/api-key-types.d.ts} +0 -6
- package/{src/auth/api-keys/index.ts → dist/auth/api-keys/index.d.ts} +2 -22
- package/dist/auth/apple-oauth.d.ts +30 -0
- package/{src/auth/auth-hooks.ts → dist/auth/auth-hooks.d.ts} +15 -73
- package/dist/auth/bitbucket-oauth.d.ts +11 -0
- package/dist/auth/builtin-auth-adapter.d.ts +55 -0
- package/dist/auth/cookie-utils.d.ts +32 -0
- package/{src/auth/crypto-utils.ts → dist/auth/crypto-utils.d.ts} +1 -16
- package/dist/auth/custom-auth-adapter.d.ts +39 -0
- package/dist/auth/discord-oauth.d.ts +14 -0
- package/dist/auth/facebook-oauth.d.ts +14 -0
- package/dist/auth/github-oauth.d.ts +15 -0
- package/dist/auth/gitlab-oauth.d.ts +13 -0
- package/dist/auth/google-oauth.d.ts +47 -0
- package/{src/auth/index.ts → dist/auth/index.d.ts} +4 -22
- package/{src/auth/interfaces.ts → dist/auth/interfaces.d.ts} +20 -89
- package/dist/auth/jwt.d.ts +67 -0
- package/dist/auth/linkedin-oauth.d.ts +18 -0
- package/dist/auth/magic-link-routes.d.ts +32 -0
- package/dist/auth/mfa-crypto.d.ts +23 -0
- package/dist/auth/mfa-routes.d.ts +7 -0
- package/dist/auth/mfa.d.ts +49 -0
- package/dist/auth/microsoft-oauth.d.ts +16 -0
- package/dist/auth/middleware.d.ts +158 -0
- package/dist/auth/password.d.ts +22 -0
- package/dist/auth/rate-limiter.d.ts +50 -0
- package/dist/auth/reset-password-admin.d.ts +29 -0
- package/dist/auth/rls-scope.d.ts +31 -0
- package/dist/auth/routes.d.ts +66 -0
- package/dist/auth/session-routes.d.ts +29 -0
- package/dist/auth/slack-oauth.d.ts +12 -0
- package/dist/auth/spotify-oauth.d.ts +12 -0
- package/dist/auth/twitter-oauth.d.ts +18 -0
- package/dist/collections/BackendCollectionRegistry.d.ts +13 -0
- package/dist/collections/loader.d.ts +5 -0
- package/dist/cron/cron-loader.d.ts +18 -0
- package/dist/cron/cron-routes.d.ts +14 -0
- package/dist/cron/cron-scheduler.d.ts +106 -0
- package/dist/cron/cron-store.d.ts +32 -0
- package/dist/cron/define-cron.d.ts +28 -0
- package/{src/cron/index.ts → dist/cron/index.d.ts} +1 -0
- package/dist/db/interfaces.d.ts +18 -0
- package/dist/dynamic-import-Dvh-K5fl.js +22 -0
- package/dist/dynamic-import-Dvh-K5fl.js.map +1 -0
- package/dist/email/index.d.ts +6 -0
- package/dist/email/smtp-email-service.d.ts +30 -0
- package/dist/email/templates.d.ts +50 -0
- package/{src/email/types.ts → dist/email/types.d.ts} +40 -36
- package/dist/env.d.ts +102 -0
- package/dist/functions/define-function.d.ts +55 -0
- package/dist/functions/function-loader.d.ts +18 -0
- package/dist/functions/function-routes.d.ts +10 -0
- package/{src/functions/index.ts → dist/functions/index.d.ts} +2 -0
- package/dist/history/history-routes.d.ts +23 -0
- package/{src/history/index.ts → dist/history/index.d.ts} +0 -1
- package/dist/index.d.ts +35 -0
- package/dist/index.es.js +18184 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +48629 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/init/docs.d.ts +4 -0
- package/dist/init/health.d.ts +2 -0
- package/dist/init/middlewares.d.ts +10 -0
- package/dist/init/shutdown.d.ts +65 -0
- package/dist/init/storage.d.ts +5 -0
- package/dist/init.d.ts +344 -0
- package/dist/jwt-BwIn8xmk.js +4200 -0
- package/dist/jwt-BwIn8xmk.js.map +1 -0
- package/dist/logger-BYU66ENZ.js +94 -0
- package/dist/logger-BYU66ENZ.js.map +1 -0
- package/dist/ms-DnYXB-Wd.js +162 -0
- package/dist/ms-DnYXB-Wd.js.map +1 -0
- package/dist/openapi-generator-Z9oYWLf_.js +586 -0
- package/dist/openapi-generator-Z9oYWLf_.js.map +1 -0
- package/dist/schema-editor-routes-D3ef8zu1.js +219 -0
- package/dist/schema-editor-routes-D3ef8zu1.js.map +1 -0
- package/dist/serve-spa.d.ts +36 -0
- package/dist/services/driver-registry.d.ts +78 -0
- package/dist/services/routed-realtime-service.d.ts +43 -0
- package/dist/services/webhook-service.d.ts +29 -0
- package/dist/singleton.d.ts +51 -0
- package/dist/src-B4OLmNVa.js +437 -0
- package/dist/src-B4OLmNVa.js.map +1 -0
- package/dist/src-B5WkP1Rv.js +24778 -0
- package/dist/src-B5WkP1Rv.js.map +1 -0
- package/dist/storage/GCSStorageController.d.ts +43 -0
- package/dist/storage/LocalStorageController.d.ts +46 -0
- package/dist/storage/S3StorageController.d.ts +40 -0
- package/dist/storage/image-transform.d.ts +50 -0
- package/{src/storage/index.ts → dist/storage/index.d.ts} +6 -21
- package/dist/storage/routes.d.ts +70 -0
- package/dist/storage/storage-registry.d.ts +78 -0
- package/dist/storage/tus-handler.d.ts +53 -0
- package/{src/storage/types.ts → dist/storage/types.d.ts} +32 -38
- package/dist/types/index.d.ts +11 -0
- package/dist/utils/dev-port.d.ts +45 -0
- package/dist/utils/dynamic-import.d.ts +25 -0
- package/dist/utils/logger.d.ts +31 -0
- package/dist/utils/logging.d.ts +9 -0
- package/dist/utils/request-id.d.ts +4 -0
- package/dist/utils/request-logger.d.ts +19 -0
- package/{src/utils/sql.ts → dist/utils/sql.d.ts} +5 -16
- package/package.json +49 -22
- package/coverage/clover.xml +0 -3739
- package/coverage/coverage-final.json +0 -31
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -266
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/src/api/ast-schema-editor.ts.html +0 -952
- package/coverage/lcov-report/src/api/errors.ts.html +0 -472
- package/coverage/lcov-report/src/api/graphql/graphql-schema-generator.ts.html +0 -1069
- package/coverage/lcov-report/src/api/graphql/index.html +0 -116
- package/coverage/lcov-report/src/api/index.html +0 -176
- package/coverage/lcov-report/src/api/openapi-generator.ts.html +0 -565
- package/coverage/lcov-report/src/api/rest/api-generator.ts.html +0 -994
- package/coverage/lcov-report/src/api/rest/index.html +0 -131
- package/coverage/lcov-report/src/api/rest/query-parser.ts.html +0 -550
- package/coverage/lcov-report/src/api/schema-editor-routes.ts.html +0 -202
- package/coverage/lcov-report/src/api/server.ts.html +0 -823
- package/coverage/lcov-report/src/auth/admin-routes.ts.html +0 -973
- package/coverage/lcov-report/src/auth/index.html +0 -176
- package/coverage/lcov-report/src/auth/jwt.ts.html +0 -574
- package/coverage/lcov-report/src/auth/middleware.ts.html +0 -745
- package/coverage/lcov-report/src/auth/password.ts.html +0 -310
- package/coverage/lcov-report/src/auth/services.ts.html +0 -2074
- package/coverage/lcov-report/src/collections/index.html +0 -116
- package/coverage/lcov-report/src/collections/loader.ts.html +0 -232
- package/coverage/lcov-report/src/db/auth-schema.ts.html +0 -523
- package/coverage/lcov-report/src/db/data-transformer.ts.html +0 -1753
- package/coverage/lcov-report/src/db/entityService.ts.html +0 -700
- package/coverage/lcov-report/src/db/index.html +0 -146
- package/coverage/lcov-report/src/db/services/EntityFetchService.ts.html +0 -4048
- package/coverage/lcov-report/src/db/services/EntityPersistService.ts.html +0 -883
- package/coverage/lcov-report/src/db/services/RelationService.ts.html +0 -3121
- package/coverage/lcov-report/src/db/services/entity-helpers.ts.html +0 -442
- package/coverage/lcov-report/src/db/services/index.html +0 -176
- package/coverage/lcov-report/src/db/services/index.ts.html +0 -124
- package/coverage/lcov-report/src/generate-drizzle-schema-logic.ts.html +0 -1960
- package/coverage/lcov-report/src/index.html +0 -116
- package/coverage/lcov-report/src/services/driver-registry.ts.html +0 -631
- package/coverage/lcov-report/src/services/index.html +0 -131
- package/coverage/lcov-report/src/services/postgresDataDriver.ts.html +0 -3025
- package/coverage/lcov-report/src/storage/LocalStorageController.ts.html +0 -1189
- package/coverage/lcov-report/src/storage/S3StorageController.ts.html +0 -970
- package/coverage/lcov-report/src/storage/index.html +0 -161
- package/coverage/lcov-report/src/storage/storage-registry.ts.html +0 -646
- package/coverage/lcov-report/src/storage/types.ts.html +0 -451
- package/coverage/lcov-report/src/utils/drizzle-conditions.ts.html +0 -3082
- package/coverage/lcov-report/src/utils/index.html +0 -116
- package/coverage/lcov.info +0 -7179
- package/jest.config.cjs +0 -19
- package/src/api/ast-schema-editor.ts +0 -289
- package/src/api/collections_for_test/callbacks_test_collection.ts +0 -61
- package/src/api/errors.ts +0 -278
- package/src/api/graphql/graphql-schema-generator.ts +0 -383
- package/src/api/graphql/index.ts +0 -2
- package/src/api/index.ts +0 -11
- package/src/api/logs-routes.ts +0 -132
- package/src/api/openapi-generator.ts +0 -727
- package/src/api/rest/api-generator-count.test.ts +0 -126
- package/src/api/rest/api-generator.ts +0 -747
- package/src/api/rest/query-parser.ts +0 -300
- package/src/api/schema-editor-routes.ts +0 -41
- package/src/api/server.ts +0 -271
- package/src/api/types.ts +0 -104
- package/src/auth/adapter-middleware.ts +0 -114
- package/src/auth/admin-roles-route.ts +0 -36
- package/src/auth/admin-user-ops.ts +0 -236
- package/src/auth/admin-users-route.ts +0 -302
- package/src/auth/api-keys/api-key-middleware.ts +0 -133
- package/src/auth/api-keys/api-key-routes.ts +0 -193
- package/src/auth/api-keys/api-key-store.ts +0 -340
- package/src/auth/apple-oauth.ts +0 -122
- package/src/auth/bitbucket-oauth.ts +0 -84
- package/src/auth/builtin-auth-adapter.ts +0 -380
- package/src/auth/custom-auth-adapter.ts +0 -86
- package/src/auth/discord-oauth.ts +0 -85
- package/src/auth/facebook-oauth.ts +0 -74
- package/src/auth/github-oauth.ts +0 -112
- package/src/auth/gitlab-oauth.ts +0 -72
- package/src/auth/google-oauth.ts +0 -223
- package/src/auth/jwt.ts +0 -208
- package/src/auth/linkedin-oauth.ts +0 -83
- package/src/auth/magic-link-routes.ts +0 -167
- package/src/auth/mfa-crypto.ts +0 -91
- package/src/auth/mfa-routes.ts +0 -323
- package/src/auth/mfa.ts +0 -161
- package/src/auth/microsoft-oauth.ts +0 -90
- package/src/auth/middleware.ts +0 -369
- package/src/auth/password.ts +0 -77
- package/src/auth/rate-limiter.ts +0 -225
- package/src/auth/reset-password-admin.ts +0 -160
- package/src/auth/rls-scope.ts +0 -58
- package/src/auth/routes.ts +0 -802
- package/src/auth/session-routes.ts +0 -353
- package/src/auth/slack-oauth.ts +0 -73
- package/src/auth/spotify-oauth.ts +0 -69
- package/src/auth/twitter-oauth.ts +0 -128
- package/src/collections/BackendCollectionRegistry.ts +0 -20
- package/src/collections/loader.ts +0 -50
- package/src/cron/cron-loader.ts +0 -84
- package/src/cron/cron-routes.test.ts +0 -265
- package/src/cron/cron-routes.ts +0 -85
- package/src/cron/cron-scheduler.test.ts +0 -559
- package/src/cron/cron-scheduler.ts +0 -581
- package/src/cron/cron-store.ts +0 -166
- package/src/db/interfaces.ts +0 -60
- package/src/email/index.ts +0 -19
- package/src/email/smtp-email-service.ts +0 -123
- package/src/email/templates.ts +0 -470
- package/src/env.ts +0 -227
- package/src/functions/function-loader.ts +0 -116
- package/src/functions/function-routes.ts +0 -31
- package/src/history/history-routes.ts +0 -129
- package/src/index.ts +0 -70
- package/src/init/docs.ts +0 -47
- package/src/init/health.ts +0 -37
- package/src/init/middlewares.ts +0 -61
- package/src/init/shutdown.ts +0 -56
- package/src/init/storage.ts +0 -57
- package/src/init.ts +0 -1041
- package/src/serve-spa.ts +0 -89
- package/src/services/driver-registry.ts +0 -183
- package/src/services/routed-realtime-service.ts +0 -113
- package/src/services/webhook-service.ts +0 -155
- package/src/singleton.ts +0 -70
- package/src/storage/LocalStorageController.ts +0 -389
- package/src/storage/S3StorageController.ts +0 -300
- package/src/storage/image-transform.ts +0 -218
- package/src/storage/routes.ts +0 -368
- package/src/storage/storage-registry.ts +0 -188
- package/src/storage/tus-handler.ts +0 -315
- package/src/types/index.ts +0 -27
- package/src/utils/dev-port.ts +0 -196
- package/src/utils/logger.ts +0 -143
- package/src/utils/logging.ts +0 -40
- package/src/utils/request-id.ts +0 -40
- package/src/utils/request-logger.ts +0 -72
- package/test/api-generator.test.ts +0 -588
- package/test/api-key-permission-guard.test.ts +0 -144
- package/test/ast-schema-editor.test.ts +0 -89
- package/test/auth-middleware-hono.test.ts +0 -556
- package/test/auth-routes.test.ts +0 -1098
- package/test/backend-hooks-data.test.ts +0 -477
- package/test/custom-auth-adapter.test.ts +0 -189
- package/test/driver-registry.test.ts +0 -282
- package/test/email-templates.test.ts +0 -174
- package/test/env.test.ts +0 -128
- package/test/error-propagation.test.ts +0 -226
- package/test/errors-hono.test.ts +0 -133
- package/test/errors.test.ts +0 -155
- package/test/function-loader.test.ts +0 -127
- package/test/graphql-schema-generator.test.ts +0 -554
- package/test/jwt-security.test.ts +0 -182
- package/test/jwt.test.ts +0 -326
- package/test/mfa.test.ts +0 -197
- package/test/middleware.test.ts +0 -305
- package/test/multi-datasource-routing.test.ts +0 -113
- package/test/password.test.ts +0 -165
- package/test/query-parser.test.ts +0 -233
- package/test/rate-limiter.test.ts +0 -102
- package/test/reset-password-admin.test.ts +0 -113
- package/test/routed-realtime-service.test.ts +0 -86
- package/test/safe-compare.test.ts +0 -66
- package/test/singleton.test.ts +0 -59
- package/test/smtp-email-service.test.ts +0 -169
- package/test/storage-local.test.ts +0 -271
- package/test/storage-registry.test.ts +0 -282
- package/test/storage-routes.test.ts +0 -222
- package/test/storage-s3.test.ts +0 -304
- package/test/transform-auth-response.test.ts +0 -305
- package/test/webhook-service.test.ts +0 -260
- package/tsconfig.json +0 -54
- package/tsconfig.prod.json +0 -23
- package/vite.config.ts +0 -86
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, jest, beforeEach } from "@jest/globals";
|
|
2
|
-
import { createRoutedRealtimeService } from "../src/services/routed-realtime-service";
|
|
3
|
-
import type { RealtimeProvider } from "@rebasepro/types";
|
|
4
|
-
|
|
5
|
-
function mockProvider() {
|
|
6
|
-
return {
|
|
7
|
-
addClient: jest.fn(),
|
|
8
|
-
handleClientMessage: jest.fn(async () => {}),
|
|
9
|
-
subscribeToCollection: jest.fn(),
|
|
10
|
-
subscribeToEntity: jest.fn(),
|
|
11
|
-
unsubscribe: jest.fn(),
|
|
12
|
-
notifyEntityUpdate: jest.fn(async () => {}),
|
|
13
|
-
onServerReady: jest.fn(),
|
|
14
|
-
destroy: jest.fn(async () => {}),
|
|
15
|
-
stopListening: jest.fn(async () => {})
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
describe("createRoutedRealtimeService", () => {
|
|
20
|
-
let pg: ReturnType<typeof mockProvider>;
|
|
21
|
-
let mongo: ReturnType<typeof mockProvider>;
|
|
22
|
-
let routed: ReturnType<typeof createRoutedRealtimeService>;
|
|
23
|
-
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
pg = mockProvider();
|
|
26
|
-
mongo = mockProvider();
|
|
27
|
-
routed = createRoutedRealtimeService({
|
|
28
|
-
providers: { "(default)": pg as unknown as RealtimeProvider, mongo: mongo as unknown as RealtimeProvider },
|
|
29
|
-
defaultKey: "(default)",
|
|
30
|
-
resolveKey: (path) => (path.split("/")[0] === "events" ? "mongo" : "(default)")
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("routes subscribe_collection to the provider owning the collection", async () => {
|
|
35
|
-
await routed.handleClientMessage("c1", { type: "subscribe_collection", payload: { path: "events", subscriptionId: "s1" } });
|
|
36
|
-
expect(mongo.handleClientMessage).toHaveBeenCalledTimes(1);
|
|
37
|
-
expect(pg.handleClientMessage).not.toHaveBeenCalled();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("routes subscribe_entity by path", async () => {
|
|
41
|
-
await routed.handleClientMessage("c1", { type: "subscribe_entity", payload: { path: "products", subscriptionId: "s2" } });
|
|
42
|
-
expect(pg.handleClientMessage).toHaveBeenCalledTimes(1);
|
|
43
|
-
expect(mongo.handleClientMessage).not.toHaveBeenCalled();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("forwards unsubscribe to all providers (owner acts, others no-op)", async () => {
|
|
47
|
-
await routed.handleClientMessage("c1", { type: "unsubscribe", subscriptionId: "s1" });
|
|
48
|
-
expect(pg.handleClientMessage).toHaveBeenCalledTimes(1);
|
|
49
|
-
expect(mongo.handleClientMessage).toHaveBeenCalledTimes(1);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("sends channel/presence/broadcast to the default provider only", async () => {
|
|
53
|
-
await routed.handleClientMessage("c1", { type: "broadcast", payload: { channel: "room", event: "x" } });
|
|
54
|
-
await routed.handleClientMessage("c1", { type: "join_channel", payload: { channel: "room" } });
|
|
55
|
-
await routed.handleClientMessage("c1", { type: "presence_track", payload: { channel: "room" } });
|
|
56
|
-
expect(pg.handleClientMessage).toHaveBeenCalledTimes(3);
|
|
57
|
-
expect(mongo.handleClientMessage).not.toHaveBeenCalled();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("addClient is forwarded to every provider", () => {
|
|
61
|
-
const ws = {};
|
|
62
|
-
routed.addClient("c1", ws);
|
|
63
|
-
expect(pg.addClient).toHaveBeenCalledWith("c1", ws);
|
|
64
|
-
expect(mongo.addClient).toHaveBeenCalledWith("c1", ws);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("notifyEntityUpdate routes by path", async () => {
|
|
68
|
-
await routed.notifyEntityUpdate("events", "e1", null);
|
|
69
|
-
expect(mongo.notifyEntityUpdate).toHaveBeenCalledTimes(1);
|
|
70
|
-
expect(pg.notifyEntityUpdate).not.toHaveBeenCalled();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("unknown path falls back to the default provider", async () => {
|
|
74
|
-
await routed.handleClientMessage("c1", { type: "subscribe_collection", payload: { path: "mystery", subscriptionId: "s9" } });
|
|
75
|
-
expect(pg.handleClientMessage).toHaveBeenCalledTimes(1);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("lifecycle methods fan out to all providers", async () => {
|
|
79
|
-
routed.onServerReady?.({ port: 3000 });
|
|
80
|
-
await routed.destroy?.();
|
|
81
|
-
expect(pg.onServerReady).toHaveBeenCalledTimes(1);
|
|
82
|
-
expect(mongo.onServerReady).toHaveBeenCalledTimes(1);
|
|
83
|
-
expect(pg.destroy).toHaveBeenCalledTimes(1);
|
|
84
|
-
expect(mongo.destroy).toHaveBeenCalledTimes(1);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the safeCompare function used in auth middleware.
|
|
3
|
-
*
|
|
4
|
-
* Since safeCompare is not exported, we test it indirectly through
|
|
5
|
-
* the createAuthMiddleware behavior with service keys. However, for
|
|
6
|
-
* unit-level verification we replicate the logic here.
|
|
7
|
-
*/
|
|
8
|
-
import { timingSafeEqual } from "crypto";
|
|
9
|
-
|
|
10
|
-
// Replicate the safeCompare implementation to test in isolation
|
|
11
|
-
function safeCompare(a: string, b: string): boolean {
|
|
12
|
-
const maxLen = Math.max(a.length, b.length);
|
|
13
|
-
const bufA = Buffer.alloc(maxLen);
|
|
14
|
-
const bufB = Buffer.alloc(maxLen);
|
|
15
|
-
bufA.write(a);
|
|
16
|
-
bufB.write(b);
|
|
17
|
-
try {
|
|
18
|
-
const isEqual = timingSafeEqual(bufA, bufB);
|
|
19
|
-
return isEqual && a.length === b.length;
|
|
20
|
-
} catch {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
describe("safeCompare", () => {
|
|
26
|
-
it("should return true for identical strings", () => {
|
|
27
|
-
expect(safeCompare("my-secret-key-12345678901234567890", "my-secret-key-12345678901234567890")).toBe(true);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("should return false for different strings of same length", () => {
|
|
31
|
-
expect(safeCompare("aaaa", "bbbb")).toBe(false);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("should return false for different length strings", () => {
|
|
35
|
-
expect(safeCompare("short", "a-much-longer-string")).toBe(false);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("should return false when one string is a prefix of the other", () => {
|
|
39
|
-
// This is the critical case: "abc" vs "abc\0\0\0" would match
|
|
40
|
-
// without the length check, since Buffer.alloc zero-fills
|
|
41
|
-
expect(safeCompare("abc", "abc\0\0\0")).toBe(false);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("should return false for empty string vs non-empty", () => {
|
|
45
|
-
expect(safeCompare("", "something")).toBe(false);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("should return true for two empty strings", () => {
|
|
49
|
-
expect(safeCompare("", "")).toBe(true);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("should handle unicode strings", () => {
|
|
53
|
-
expect(safeCompare("café", "café")).toBe(true);
|
|
54
|
-
expect(safeCompare("café", "cafe")).toBe(false);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("should not leak length information via early return", () => {
|
|
58
|
-
// Both comparisons should take similar time (constant-time)
|
|
59
|
-
// We can't easily assert timing, but we verify they both
|
|
60
|
-
// go through the same code path
|
|
61
|
-
const result1 = safeCompare("a", "bb");
|
|
62
|
-
const result2 = safeCompare("aa", "bb");
|
|
63
|
-
expect(result1).toBe(false);
|
|
64
|
-
expect(result2).toBe(false);
|
|
65
|
-
});
|
|
66
|
-
});
|
package/test/singleton.test.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { rebase, _initRebase, _setRebaseMock, _resetRebaseMock } from "../src/singleton";
|
|
2
|
-
import type { RebaseClient } from "@rebasepro/types";
|
|
3
|
-
|
|
4
|
-
describe("rebase singleton", () => {
|
|
5
|
-
afterEach(() => {
|
|
6
|
-
// Reset after each test to avoid interference
|
|
7
|
-
process.env.NODE_ENV = "test";
|
|
8
|
-
_resetRebaseMock();
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it("should throw when accessing properties before initialization", () => {
|
|
12
|
-
expect(() => rebase.data).toThrow(/server not initialized yet/);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it("should allow property access after initialization", () => {
|
|
16
|
-
const mockData = { find: jest.fn() };
|
|
17
|
-
_setRebaseMock({ data: mockData } as Partial<RebaseClient>);
|
|
18
|
-
|
|
19
|
-
expect(rebase.data).toBe(mockData);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("should throw on property assignment (set trap)", () => {
|
|
23
|
-
_setRebaseMock({ data: {} } as Partial<RebaseClient>);
|
|
24
|
-
|
|
25
|
-
expect(() => {
|
|
26
|
-
(rebase as Record<string, unknown>).data = "overwritten";
|
|
27
|
-
}).toThrow(/Cannot set rebase\.data directly/);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("should reset properly with _resetRebaseMock", () => {
|
|
31
|
-
_setRebaseMock({ data: {} } as Partial<RebaseClient>);
|
|
32
|
-
expect(() => rebase.data).not.toThrow();
|
|
33
|
-
|
|
34
|
-
_resetRebaseMock();
|
|
35
|
-
expect(() => rebase.data).toThrow(/server not initialized yet/);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("should throw if _setRebaseMock is called outside test env", () => {
|
|
39
|
-
const originalEnv = process.env.NODE_ENV;
|
|
40
|
-
process.env.NODE_ENV = "production";
|
|
41
|
-
|
|
42
|
-
expect(() => _setRebaseMock({} as Partial<RebaseClient>)).toThrow(
|
|
43
|
-
/can only be called in a test environment/
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
process.env.NODE_ENV = originalEnv;
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("should throw if _resetRebaseMock is called outside test env", () => {
|
|
50
|
-
const originalEnv = process.env.NODE_ENV;
|
|
51
|
-
process.env.NODE_ENV = "production";
|
|
52
|
-
|
|
53
|
-
expect(() => _resetRebaseMock()).toThrow(
|
|
54
|
-
/can only be called in a test environment/
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
process.env.NODE_ENV = originalEnv;
|
|
58
|
-
});
|
|
59
|
-
});
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { SMTPEmailService } from "../src/email/smtp-email-service";
|
|
2
|
-
import nodemailer from "nodemailer";
|
|
3
|
-
|
|
4
|
-
jest.mock("nodemailer", () => {
|
|
5
|
-
const mockTransporter = {
|
|
6
|
-
verify: jest.fn().mockResolvedValue(true),
|
|
7
|
-
sendMail: jest.fn().mockResolvedValue(true)
|
|
8
|
-
};
|
|
9
|
-
return {
|
|
10
|
-
createTransport: jest.fn().mockReturnValue(mockTransporter)
|
|
11
|
-
};
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe("SMTPEmailService", () => {
|
|
15
|
-
let mockCreateTransport: jest.Mock;
|
|
16
|
-
let mockTransporter: any;
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
jest.clearAllMocks();
|
|
20
|
-
mockCreateTransport = nodemailer.createTransport as jest.Mock;
|
|
21
|
-
mockTransporter = mockCreateTransport({} as any); // gets the mocked object
|
|
22
|
-
mockCreateTransport.mockClear();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("should create transport with explicit name", () => {
|
|
26
|
-
new SMTPEmailService({
|
|
27
|
-
from: "test@example.com",
|
|
28
|
-
smtp: {
|
|
29
|
-
host: "smtp.example.com",
|
|
30
|
-
port: 587,
|
|
31
|
-
name: "explicit-hostname"
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
expect(mockCreateTransport).toHaveBeenCalledWith(
|
|
36
|
-
expect.objectContaining({
|
|
37
|
-
name: "explicit-hostname",
|
|
38
|
-
host: "smtp.example.com",
|
|
39
|
-
port: 587
|
|
40
|
-
})
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("should infer name from FRONTEND_URL if smtp.name is undefined", () => {
|
|
45
|
-
const originalFrontendUrl = process.env.FRONTEND_URL;
|
|
46
|
-
process.env.FRONTEND_URL = "https://frontend-url.com/some-path";
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
new SMTPEmailService({
|
|
50
|
-
from: "test@example.com",
|
|
51
|
-
smtp: {
|
|
52
|
-
host: "smtp.example.com",
|
|
53
|
-
port: 587
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
expect(mockCreateTransport).toHaveBeenCalledWith(
|
|
58
|
-
expect.objectContaining({
|
|
59
|
-
name: "frontend-url.com"
|
|
60
|
-
})
|
|
61
|
-
);
|
|
62
|
-
} finally {
|
|
63
|
-
process.env.FRONTEND_URL = originalFrontendUrl;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("should infer name from resetPasswordUrl if FRONTEND_URL and smtp.name are undefined", () => {
|
|
68
|
-
const originalFrontendUrl = process.env.FRONTEND_URL;
|
|
69
|
-
delete process.env.FRONTEND_URL;
|
|
70
|
-
|
|
71
|
-
try {
|
|
72
|
-
new SMTPEmailService({
|
|
73
|
-
from: "test@example.com",
|
|
74
|
-
smtp: {
|
|
75
|
-
host: "smtp.example.com",
|
|
76
|
-
port: 587
|
|
77
|
-
},
|
|
78
|
-
resetPasswordUrl: "http://reset-password-url.org"
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
expect(mockCreateTransport).toHaveBeenCalledWith(
|
|
82
|
-
expect.objectContaining({
|
|
83
|
-
name: "reset-password-url.org"
|
|
84
|
-
})
|
|
85
|
-
);
|
|
86
|
-
} finally {
|
|
87
|
-
process.env.FRONTEND_URL = originalFrontendUrl;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("should infer name from verifyEmailUrl if FRONTEND_URL, resetPasswordUrl and smtp.name are undefined", () => {
|
|
92
|
-
const originalFrontendUrl = process.env.FRONTEND_URL;
|
|
93
|
-
delete process.env.FRONTEND_URL;
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
new SMTPEmailService({
|
|
97
|
-
from: "test@example.com",
|
|
98
|
-
smtp: {
|
|
99
|
-
host: "smtp.example.com",
|
|
100
|
-
port: 587
|
|
101
|
-
},
|
|
102
|
-
verifyEmailUrl: "verify-email-url.net/auth"
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
expect(mockCreateTransport).toHaveBeenCalledWith(
|
|
106
|
-
expect.objectContaining({
|
|
107
|
-
name: "verify-email-url.net"
|
|
108
|
-
})
|
|
109
|
-
);
|
|
110
|
-
} finally {
|
|
111
|
-
process.env.FRONTEND_URL = originalFrontendUrl;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it("should leave name undefined if no URLs are provided", () => {
|
|
116
|
-
const originalFrontendUrl = process.env.FRONTEND_URL;
|
|
117
|
-
delete process.env.FRONTEND_URL;
|
|
118
|
-
|
|
119
|
-
try {
|
|
120
|
-
new SMTPEmailService({
|
|
121
|
-
from: "test@example.com",
|
|
122
|
-
smtp: {
|
|
123
|
-
host: "smtp.example.com",
|
|
124
|
-
port: 587
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
expect(mockCreateTransport).toHaveBeenCalledWith(
|
|
129
|
-
expect.objectContaining({
|
|
130
|
-
name: undefined
|
|
131
|
-
})
|
|
132
|
-
);
|
|
133
|
-
} finally {
|
|
134
|
-
process.env.FRONTEND_URL = originalFrontendUrl;
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it("should successfully verify SMTP connection", async () => {
|
|
139
|
-
mockTransporter.verify.mockResolvedValueOnce(true);
|
|
140
|
-
|
|
141
|
-
const service = new SMTPEmailService({
|
|
142
|
-
from: "test@example.com",
|
|
143
|
-
smtp: {
|
|
144
|
-
host: "smtp.example.com",
|
|
145
|
-
port: 587
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
const verified = await service.verifyConnection();
|
|
150
|
-
expect(verified).toBe(true);
|
|
151
|
-
expect(mockTransporter.verify).toHaveBeenCalled();
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("should return false if SMTP connection verification fails", async () => {
|
|
155
|
-
mockTransporter.verify.mockRejectedValueOnce(new Error("Connection timeout"));
|
|
156
|
-
|
|
157
|
-
const service = new SMTPEmailService({
|
|
158
|
-
from: "test@example.com",
|
|
159
|
-
smtp: {
|
|
160
|
-
host: "smtp.example.com",
|
|
161
|
-
port: 587
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
const verified = await service.verifyConnection();
|
|
166
|
-
expect(verified).toBe(false);
|
|
167
|
-
expect(mockTransporter.verify).toHaveBeenCalled();
|
|
168
|
-
});
|
|
169
|
-
});
|
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach, jest as vi } from "@jest/globals";
|
|
2
|
-
import * as fs from "fs";
|
|
3
|
-
import * as path from "path";
|
|
4
|
-
import * as os from "os";
|
|
5
|
-
import { LocalStorageController } from "../src/storage/LocalStorageController";
|
|
6
|
-
|
|
7
|
-
describe("LocalStorageController", () => {
|
|
8
|
-
let controller: LocalStorageController;
|
|
9
|
-
let tempDir: string;
|
|
10
|
-
|
|
11
|
-
beforeEach(async () => {
|
|
12
|
-
// Create a temporary directory for tests
|
|
13
|
-
tempDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "rebase-storage-test-"));
|
|
14
|
-
controller = new LocalStorageController({
|
|
15
|
-
basePath: tempDir
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
afterEach(async () => {
|
|
20
|
-
// Clean up temporary directory
|
|
21
|
-
await fs.promises.rm(tempDir, { recursive: true,
|
|
22
|
-
force: true });
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
describe("constructor", () => {
|
|
26
|
-
it("should initialize with basePath", () => {
|
|
27
|
-
expect(controller.getBasePath()).toBe(tempDir);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("should return 'local' as type", () => {
|
|
31
|
-
expect(controller.getType()).toBe("local");
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe("putObject", () => {
|
|
36
|
-
it("should upload a file and return metadata", async () => {
|
|
37
|
-
const content = Buffer.from("Hello, World!");
|
|
38
|
-
const file = new File([content], "test.txt", { type: "text/plain" });
|
|
39
|
-
|
|
40
|
-
const result = await controller.putObject({
|
|
41
|
-
file,
|
|
42
|
-
key: "uploads/test.txt"
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
expect(result.key).toContain("uploads");
|
|
46
|
-
expect(result.key).toContain("test.txt");
|
|
47
|
-
|
|
48
|
-
// Verify file exists on disk (uses default bucket)
|
|
49
|
-
const filePath = path.join(tempDir, "default", "uploads", "test.txt");
|
|
50
|
-
const exists = await fs.promises.access(filePath).then(() => true).catch(() => false);
|
|
51
|
-
expect(exists).toBe(true);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("should create nested directories", async () => {
|
|
55
|
-
const content = Buffer.from("Nested content");
|
|
56
|
-
const file = new File([content], "nested.txt", { type: "text/plain" });
|
|
57
|
-
|
|
58
|
-
await controller.putObject({
|
|
59
|
-
file,
|
|
60
|
-
key: "level1/level2/level3/nested.txt"
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const filePath = path.join(tempDir, "default", "level1", "level2", "level3", "nested.txt");
|
|
64
|
-
const exists = await fs.promises.access(filePath).then(() => true).catch(() => false);
|
|
65
|
-
expect(exists).toBe(true);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("should handle custom bucket", async () => {
|
|
69
|
-
const content = Buffer.from("Bucket content");
|
|
70
|
-
const file = new File([content], "bucket.txt", { type: "text/plain" });
|
|
71
|
-
|
|
72
|
-
await controller.putObject({
|
|
73
|
-
file,
|
|
74
|
-
key: "files/bucket.txt",
|
|
75
|
-
bucket: "custom-bucket"
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const filePath = path.join(tempDir, "custom-bucket", "files", "bucket.txt");
|
|
79
|
-
const exists = await fs.promises.access(filePath).then(() => true).catch(() => false);
|
|
80
|
-
expect(exists).toBe(true);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("should store metadata alongside file", async () => {
|
|
84
|
-
const content = Buffer.from("With metadata");
|
|
85
|
-
const file = new File([content], "meta.txt", { type: "text/plain" });
|
|
86
|
-
|
|
87
|
-
await controller.putObject({
|
|
88
|
-
file,
|
|
89
|
-
key: "uploads/meta.txt",
|
|
90
|
-
metadata: { customField: "customValue" }
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// Implementation uses .metadata.json extension
|
|
94
|
-
const metadataPath = path.join(tempDir, "default", "uploads", "meta.txt.metadata.json");
|
|
95
|
-
const exists = await fs.promises.access(metadataPath).then(() => true).catch(() => false);
|
|
96
|
-
expect(exists).toBe(true);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe("getObject", () => {
|
|
101
|
-
it("should retrieve an uploaded file using local:// URL format", async () => {
|
|
102
|
-
const content = Buffer.from("Retrieve me");
|
|
103
|
-
const file = new File([content], "retrieve.txt", { type: "text/plain" });
|
|
104
|
-
|
|
105
|
-
const uploadResult = await controller.putObject({
|
|
106
|
-
file,
|
|
107
|
-
key: "uploads/retrieve.txt"
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// Use the storageUrl from upload result (local:// format)
|
|
111
|
-
const retrieved = await controller.getObject(uploadResult.storageUrl!);
|
|
112
|
-
|
|
113
|
-
expect(retrieved).not.toBeNull();
|
|
114
|
-
expect(retrieved?.name).toBe("retrieve.txt");
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("should return null for non-existent file", async () => {
|
|
118
|
-
const result = await controller.getObject("local://default/nonexistent/file.txt");
|
|
119
|
-
expect(result).toBeNull();
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
describe("deleteObject", () => {
|
|
124
|
-
it("should delete an uploaded file using local:// URL format", async () => {
|
|
125
|
-
const content = Buffer.from("Delete me");
|
|
126
|
-
const file = new File([content], "delete.txt", { type: "text/plain" });
|
|
127
|
-
|
|
128
|
-
const uploadResult = await controller.putObject({
|
|
129
|
-
file,
|
|
130
|
-
key: "uploads/delete.txt"
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
// Verify file exists
|
|
134
|
-
const filePath = path.join(tempDir, "default", "uploads", "delete.txt");
|
|
135
|
-
let exists = await fs.promises.access(filePath).then(() => true).catch(() => false);
|
|
136
|
-
expect(exists).toBe(true);
|
|
137
|
-
|
|
138
|
-
// Delete the file using local:// URL format
|
|
139
|
-
await controller.deleteObject(uploadResult.storageUrl!);
|
|
140
|
-
|
|
141
|
-
// Verify file no longer exists
|
|
142
|
-
exists = await fs.promises.access(filePath).then(() => true).catch(() => false);
|
|
143
|
-
expect(exists).toBe(false);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("should not throw when deleting non-existent file", async () => {
|
|
147
|
-
await expect(controller.deleteObject("local://default/nonexistent/file.txt")).resolves.not.toThrow();
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it("should also delete metadata file", async () => {
|
|
151
|
-
const content = Buffer.from("Delete with metadata");
|
|
152
|
-
const file = new File([content], "withmeta.txt", { type: "text/plain" });
|
|
153
|
-
|
|
154
|
-
const uploadResult = await controller.putObject({
|
|
155
|
-
file,
|
|
156
|
-
key: "uploads/withmeta.txt",
|
|
157
|
-
metadata: { key: "value" }
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
await controller.deleteObject(uploadResult.storageUrl!);
|
|
161
|
-
|
|
162
|
-
const metadataPath = path.join(tempDir, "default", "uploads", "withmeta.txt.metadata.json");
|
|
163
|
-
const exists = await fs.promises.access(metadataPath).then(() => true).catch(() => false);
|
|
164
|
-
expect(exists).toBe(false);
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
describe("list", () => {
|
|
169
|
-
beforeEach(async () => {
|
|
170
|
-
// Upload some test files
|
|
171
|
-
for (let i = 1; i <= 5; i++) {
|
|
172
|
-
const file = new File([`Content ${i}`], `file${i}.txt`, { type: "text/plain" });
|
|
173
|
-
await controller.putObject({
|
|
174
|
-
file,
|
|
175
|
-
key: `listtest/file${i}.txt`
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it("should list files in a directory", async () => {
|
|
181
|
-
const result = await controller.listObjects("listtest", { bucket: "default" });
|
|
182
|
-
|
|
183
|
-
// Items should be the actual files (not metadata files)
|
|
184
|
-
expect(result.items.length).toBeGreaterThanOrEqual(5);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it("should return empty list for non-existent directory", async () => {
|
|
188
|
-
const result = await controller.listObjects("nonexistent", { bucket: "default" });
|
|
189
|
-
|
|
190
|
-
expect(result.items).toHaveLength(0);
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
describe("getSignedUrl", () => {
|
|
195
|
-
it("should return download URL for existing file", async () => {
|
|
196
|
-
const content = Buffer.from("Download me");
|
|
197
|
-
const file = new File([content], "download.txt", { type: "text/plain" });
|
|
198
|
-
|
|
199
|
-
const uploadResult = await controller.putObject({
|
|
200
|
-
file,
|
|
201
|
-
key: "uploads/download.txt"
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
// Use the storageUrl from upload result
|
|
205
|
-
const result = await controller.getSignedUrl(uploadResult.storageUrl!);
|
|
206
|
-
|
|
207
|
-
expect(result.url).toBeTruthy();
|
|
208
|
-
expect(result.fileNotFound).toBeFalsy();
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it("should return fileNotFound for non-existent file", async () => {
|
|
212
|
-
const result = await controller.getSignedUrl("local://default/nonexistent/file.txt");
|
|
213
|
-
|
|
214
|
-
expect(result.fileNotFound).toBe(true);
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
describe("getAbsolutePath", () => {
|
|
219
|
-
it("should return absolute filesystem path without bucket", () => {
|
|
220
|
-
const absPath = controller.getAbsolutePath("uploads/test.txt");
|
|
221
|
-
|
|
222
|
-
// getAbsolutePath uses getFullPath which doesn't include bucket unless specified
|
|
223
|
-
expect(absPath).toBe(path.join(tempDir, "uploads", "test.txt"));
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it("should handle custom bucket", () => {
|
|
227
|
-
const absPath = controller.getAbsolutePath("uploads/test.txt", "custom");
|
|
228
|
-
|
|
229
|
-
expect(absPath).toBe(path.join(tempDir, "custom", "uploads", "test.txt"));
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
describe("validateFile", () => {
|
|
234
|
-
it("should accept valid file", () => {
|
|
235
|
-
const file = new File(["content"], "valid.txt", { type: "text/plain" });
|
|
236
|
-
|
|
237
|
-
// Should not throw
|
|
238
|
-
expect(() => {
|
|
239
|
-
(controller as {validateFile: (f: File) => void}).validateFile(file);
|
|
240
|
-
}).not.toThrow();
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it("should reject file exceeding max size", () => {
|
|
244
|
-
// Create a controller with small max size
|
|
245
|
-
const smallController = new LocalStorageController({
|
|
246
|
-
basePath: tempDir,
|
|
247
|
-
maxFileSize: 10 // 10 bytes
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
const largeContent = Buffer.alloc(100);
|
|
251
|
-
const file = new File([largeContent], "large.txt", { type: "text/plain" });
|
|
252
|
-
|
|
253
|
-
expect(() => {
|
|
254
|
-
(smallController as {validateFile: (f: File) => void}).validateFile(file);
|
|
255
|
-
}).toThrow(/exceeds/i);
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
it("should reject disallowed file types", () => {
|
|
259
|
-
const controllerWithTypes = new LocalStorageController({
|
|
260
|
-
basePath: tempDir,
|
|
261
|
-
allowedMimeTypes: ["image/png", "image/jpeg"]
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
const file = new File(["content"], "script.js", { type: "application/javascript" });
|
|
265
|
-
|
|
266
|
-
expect(() => {
|
|
267
|
-
(controllerWithTypes as {validateFile: (f: File) => void}).validateFile(file);
|
|
268
|
-
}).toThrow(/not allowed/i);
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
});
|