@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
package/test/password.test.ts
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
validatePasswordStrength,
|
|
3
|
-
hashPassword,
|
|
4
|
-
verifyPassword
|
|
5
|
-
} from "../src/auth/password";
|
|
6
|
-
|
|
7
|
-
describe("Password Utilities", () => {
|
|
8
|
-
describe("validatePasswordStrength", () => {
|
|
9
|
-
it("should accept a valid password", () => {
|
|
10
|
-
const result = validatePasswordStrength("ValidPass123");
|
|
11
|
-
expect(result.valid).toBe(true);
|
|
12
|
-
expect(result.errors).toHaveLength(0);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it("should reject password shorter than 8 characters", () => {
|
|
16
|
-
const result = validatePasswordStrength("Short1A");
|
|
17
|
-
expect(result.valid).toBe(false);
|
|
18
|
-
expect(result.errors).toContain("Password must be at least 8 characters long");
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("should reject password without uppercase letter", () => {
|
|
22
|
-
const result = validatePasswordStrength("lowercase123");
|
|
23
|
-
expect(result.valid).toBe(false);
|
|
24
|
-
expect(result.errors).toContain("Password must contain at least one uppercase letter");
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("should reject password without lowercase letter", () => {
|
|
28
|
-
const result = validatePasswordStrength("UPPERCASE123");
|
|
29
|
-
expect(result.valid).toBe(false);
|
|
30
|
-
expect(result.errors).toContain("Password must contain at least one lowercase letter");
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("should reject password without number", () => {
|
|
34
|
-
const result = validatePasswordStrength("NoNumbersHere");
|
|
35
|
-
expect(result.valid).toBe(false);
|
|
36
|
-
expect(result.errors).toContain("Password must contain at least one number");
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("should return multiple errors for multiple violations", () => {
|
|
40
|
-
const result = validatePasswordStrength("short");
|
|
41
|
-
expect(result.valid).toBe(false);
|
|
42
|
-
expect(result.errors.length).toBeGreaterThan(1);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("should accept password with special characters", () => {
|
|
46
|
-
const result = validatePasswordStrength("Valid@Pass#123!");
|
|
47
|
-
expect(result.valid).toBe(true);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("should accept password at exactly 8 characters", () => {
|
|
51
|
-
const result = validatePasswordStrength("Abcdefg1");
|
|
52
|
-
expect(result.valid).toBe(true);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe("hashPassword", () => {
|
|
57
|
-
it("should return a hash in salt:hash format", async () => {
|
|
58
|
-
const hash = await hashPassword("TestPassword123");
|
|
59
|
-
expect(hash).toContain(":");
|
|
60
|
-
const [salt, hashValue] = hash.split(":");
|
|
61
|
-
expect(salt).toBeTruthy();
|
|
62
|
-
expect(hashValue).toBeTruthy();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("should generate different hashes for the same password (due to random salt)", async () => {
|
|
66
|
-
const hash1 = await hashPassword("SamePassword123");
|
|
67
|
-
const hash2 = await hashPassword("SamePassword123");
|
|
68
|
-
expect(hash1).not.toBe(hash2);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("should generate a 32-byte salt (64 hex chars)", async () => {
|
|
72
|
-
const hash = await hashPassword("TestPassword123");
|
|
73
|
-
const [salt] = hash.split(":");
|
|
74
|
-
expect(salt).toHaveLength(64);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("should generate a 64-byte key (128 hex chars)", async () => {
|
|
78
|
-
const hash = await hashPassword("TestPassword123");
|
|
79
|
-
const [, hashValue] = hash.split(":");
|
|
80
|
-
expect(hashValue).toHaveLength(128);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
describe("verifyPassword", () => {
|
|
85
|
-
it("should verify a correct password", async () => {
|
|
86
|
-
const password = "CorrectPassword123";
|
|
87
|
-
const hash = await hashPassword(password);
|
|
88
|
-
const isValid = await verifyPassword(password, hash);
|
|
89
|
-
expect(isValid).toBe(true);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("should reject an incorrect password", async () => {
|
|
93
|
-
const hash = await hashPassword("CorrectPassword123");
|
|
94
|
-
const isValid = await verifyPassword("WrongPassword123", hash);
|
|
95
|
-
expect(isValid).toBe(false);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it("should return false for malformed hash (no colon)", async () => {
|
|
99
|
-
const isValid = await verifyPassword("AnyPassword", "malformedhash");
|
|
100
|
-
expect(isValid).toBe(false);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("should return false for empty hash parts", async () => {
|
|
104
|
-
const isValid = await verifyPassword("AnyPassword", ":");
|
|
105
|
-
expect(isValid).toBe(false);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("should be case-sensitive", async () => {
|
|
109
|
-
const hash = await hashPassword("CaseSensitive123");
|
|
110
|
-
const isValid = await verifyPassword("casesensitive123", hash);
|
|
111
|
-
expect(isValid).toBe(false);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it("should handle empty password", async () => {
|
|
115
|
-
const hash = await hashPassword("");
|
|
116
|
-
const isValid = await verifyPassword("", hash);
|
|
117
|
-
expect(isValid).toBe(true);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("should handle unicode characters", async () => {
|
|
121
|
-
const password = "Pässwörd123日本語";
|
|
122
|
-
const hash = await hashPassword(password);
|
|
123
|
-
const isValid = await verifyPassword(password, hash);
|
|
124
|
-
expect(isValid).toBe(true);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("should handle very long passwords", async () => {
|
|
128
|
-
const password = "A".repeat(1000) + "bcdefg1";
|
|
129
|
-
const hash = await hashPassword(password);
|
|
130
|
-
const isValid = await verifyPassword(password, hash);
|
|
131
|
-
expect(isValid).toBe(true);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe("timing-safe comparison", () => {
|
|
136
|
-
// This test verifies that timing attacks are mitigated
|
|
137
|
-
// by checking that verification time is relatively constant
|
|
138
|
-
it("should take similar time for correct and incorrect passwords", async () => {
|
|
139
|
-
const password = "TestPassword123";
|
|
140
|
-
const hash = await hashPassword(password);
|
|
141
|
-
|
|
142
|
-
// Run multiple iterations to average out noise
|
|
143
|
-
const iterations = 10;
|
|
144
|
-
|
|
145
|
-
// Time correct password
|
|
146
|
-
const correctStart = Date.now();
|
|
147
|
-
for (let i = 0; i < iterations; i++) {
|
|
148
|
-
await verifyPassword(password, hash);
|
|
149
|
-
}
|
|
150
|
-
const correctTime = Date.now() - correctStart;
|
|
151
|
-
|
|
152
|
-
// Time incorrect password (same length)
|
|
153
|
-
const incorrectStart = Date.now();
|
|
154
|
-
for (let i = 0; i < iterations; i++) {
|
|
155
|
-
await verifyPassword("WrongPassword12", hash);
|
|
156
|
-
}
|
|
157
|
-
const incorrectTime = Date.now() - incorrectStart;
|
|
158
|
-
|
|
159
|
-
// Times should be within 50% of each other
|
|
160
|
-
// (allowing for system variance)
|
|
161
|
-
const ratio = Math.abs(correctTime - incorrectTime) / Math.max(correctTime, incorrectTime);
|
|
162
|
-
expect(ratio).toBeLessThan(0.5);
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
});
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import { mapOperator, parseQueryOptions } from "../src/api/rest/query-parser";
|
|
2
|
-
|
|
3
|
-
// ─────────────────────────────────────────────────────────────
|
|
4
|
-
// mapOperator
|
|
5
|
-
// ─────────────────────────────────────────────────────────────
|
|
6
|
-
describe("mapOperator", () => {
|
|
7
|
-
it("maps PostgREST operators to Rebase operators", () => {
|
|
8
|
-
expect(mapOperator("eq")).toBe("==");
|
|
9
|
-
expect(mapOperator("neq")).toBe("!=");
|
|
10
|
-
expect(mapOperator("gt")).toBe(">");
|
|
11
|
-
expect(mapOperator("gte")).toBe(">=");
|
|
12
|
-
expect(mapOperator("lt")).toBe("<");
|
|
13
|
-
expect(mapOperator("lte")).toBe("<=");
|
|
14
|
-
expect(mapOperator("in")).toBe("in");
|
|
15
|
-
expect(mapOperator("nin")).toBe("not-in");
|
|
16
|
-
expect(mapOperator("cs")).toBe("array-contains");
|
|
17
|
-
expect(mapOperator("csa")).toBe("array-contains-any");
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("returns null for unknown operators", () => {
|
|
21
|
-
expect(mapOperator("like")).toBeNull();
|
|
22
|
-
expect(mapOperator("between")).toBeNull();
|
|
23
|
-
expect(mapOperator("")).toBeNull();
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// ─────────────────────────────────────────────────────────────
|
|
28
|
-
// parseQueryOptions — Pagination
|
|
29
|
-
// ─────────────────────────────────────────────────────────────
|
|
30
|
-
describe("parseQueryOptions — pagination", () => {
|
|
31
|
-
it("parses limit", () => {
|
|
32
|
-
const result = parseQueryOptions({ limit: "25" });
|
|
33
|
-
expect(result.limit).toBe(25);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("parses offset", () => {
|
|
37
|
-
const result = parseQueryOptions({ offset: "50" });
|
|
38
|
-
expect(result.offset).toBe(50);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("calculates offset from page number", () => {
|
|
42
|
-
const result = parseQueryOptions({ page: "3",
|
|
43
|
-
limit: "10" });
|
|
44
|
-
expect(result.offset).toBe(20); // (3-1) * 10
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("uses default limit of 20 for page calculation when limit not set", () => {
|
|
48
|
-
const result = parseQueryOptions({ page: "2" });
|
|
49
|
-
expect(result.offset).toBe(20); // (2-1) * 20
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("handles no pagination params", () => {
|
|
53
|
-
const result = parseQueryOptions({});
|
|
54
|
-
expect(result.limit).toBeUndefined();
|
|
55
|
-
expect(result.offset).toBeUndefined();
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// ─────────────────────────────────────────────────────────────
|
|
60
|
-
// parseQueryOptions — PostgREST Filters
|
|
61
|
-
// ─────────────────────────────────────────────────────────────
|
|
62
|
-
describe("parseQueryOptions — PostgREST filters", () => {
|
|
63
|
-
it("parses equality filter (implicit eq)", () => {
|
|
64
|
-
const result = parseQueryOptions({ status: "published" });
|
|
65
|
-
expect(result.where?.status).toEqual(["==", "published"]);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("parses eq operator explicitly", () => {
|
|
69
|
-
const result = parseQueryOptions({ status: "eq.published" });
|
|
70
|
-
expect(result.where?.status).toEqual(["==", "published"]);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("parses gt with number coercion", () => {
|
|
74
|
-
const result = parseQueryOptions({ age: "gt.18" });
|
|
75
|
-
expect(result.where?.age).toEqual([">", 18]);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("parses gte operator", () => {
|
|
79
|
-
const result = parseQueryOptions({ price: "gte.9.99" });
|
|
80
|
-
expect(result.where?.price).toEqual([">=", 9.99]);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("parses lt operator", () => {
|
|
84
|
-
const result = parseQueryOptions({ count: "lt.100" });
|
|
85
|
-
expect(result.where?.count).toEqual(["<", 100]);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("parses lte operator", () => {
|
|
89
|
-
const result = parseQueryOptions({ rating: "lte.5" });
|
|
90
|
-
expect(result.where?.rating).toEqual(["<=", 5]);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("parses neq operator", () => {
|
|
94
|
-
const result = parseQueryOptions({ status: "neq.draft" });
|
|
95
|
-
expect(result.where?.status).toEqual(["!=", "draft"]);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it("parses boolean true", () => {
|
|
99
|
-
const result = parseQueryOptions({ active: "true" });
|
|
100
|
-
expect(result.where?.active).toEqual(["==", true]);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("parses boolean false", () => {
|
|
104
|
-
const result = parseQueryOptions({ active: "false" });
|
|
105
|
-
expect(result.where?.active).toEqual(["==", false]);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("parses null", () => {
|
|
109
|
-
const result = parseQueryOptions({ deleted_at: "null" });
|
|
110
|
-
expect(result.where?.deleted_at).toEqual(["==", null]);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("parses numeric strings as numbers", () => {
|
|
114
|
-
const result = parseQueryOptions({ quantity: "42" });
|
|
115
|
-
expect(result.where?.quantity).toEqual(["==", 42]);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("parses in operator with array", () => {
|
|
119
|
-
const result = parseQueryOptions({ role: "in.(admin,editor,viewer)" });
|
|
120
|
-
expect(result.where?.role).toEqual(["in", ["admin", "editor", "viewer"]]);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("parses in operator with numeric array", () => {
|
|
124
|
-
const result = parseQueryOptions({ priority: "in.(1,2,3)" });
|
|
125
|
-
expect(result.where?.priority).toEqual(["in", [1, 2, 3]]);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it("parses array-contains operator", () => {
|
|
129
|
-
const result = parseQueryOptions({ tags: "cs.javascript" });
|
|
130
|
-
expect(result.where?.tags).toEqual(["array-contains", "javascript"]);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("skips reserved query keys", () => {
|
|
134
|
-
const result = parseQueryOptions({
|
|
135
|
-
limit: "10",
|
|
136
|
-
offset: "0",
|
|
137
|
-
orderBy: "name:asc",
|
|
138
|
-
status: "eq.active"
|
|
139
|
-
});
|
|
140
|
-
// Only status should be in where
|
|
141
|
-
expect(result.where?.status).toEqual(["==", "active"]);
|
|
142
|
-
expect(result.where?.limit).toBeUndefined();
|
|
143
|
-
expect(result.where?.offset).toBeUndefined();
|
|
144
|
-
expect(result.where?.orderBy).toBeUndefined();
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it("handles string values with dots that are not operators (fallback to eq)", () => {
|
|
148
|
-
const result = parseQueryOptions({ email: "user@example.com" });
|
|
149
|
-
// "user@example" is not a valid operator, so fallback to eq
|
|
150
|
-
expect(result.where?.email).toBeDefined();
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("removes empty where object", () => {
|
|
154
|
-
const result = parseQueryOptions({ limit: "10" });
|
|
155
|
-
expect(result.where).toBeUndefined();
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
// ─────────────────────────────────────────────────────────────
|
|
161
|
-
// parseQueryOptions — Sorting
|
|
162
|
-
// ─────────────────────────────────────────────────────────────
|
|
163
|
-
describe("parseQueryOptions — sorting", () => {
|
|
164
|
-
it("parses JSON orderBy", () => {
|
|
165
|
-
const orderBy = JSON.stringify([{ field: "name",
|
|
166
|
-
direction: "asc" }]);
|
|
167
|
-
const result = parseQueryOptions({ orderBy });
|
|
168
|
-
expect(result.orderBy).toEqual([{ field: "name",
|
|
169
|
-
direction: "asc" }]);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it("parses simple field:direction format", () => {
|
|
173
|
-
const result = parseQueryOptions({ orderBy: "created_at:desc" });
|
|
174
|
-
expect(result.orderBy).toEqual([{ field: "created_at",
|
|
175
|
-
direction: "desc" }]);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it("defaults direction to asc", () => {
|
|
179
|
-
const result = parseQueryOptions({ orderBy: "name" });
|
|
180
|
-
expect(result.orderBy).toEqual([{ field: "name",
|
|
181
|
-
direction: "asc" }]);
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it("handles no orderBy", () => {
|
|
185
|
-
const result = parseQueryOptions({});
|
|
186
|
-
expect(result.orderBy).toBeUndefined();
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
// ─────────────────────────────────────────────────────────────
|
|
191
|
-
// parseQueryOptions — Relation includes
|
|
192
|
-
// ─────────────────────────────────────────────────────────────
|
|
193
|
-
describe("parseQueryOptions — includes", () => {
|
|
194
|
-
it("parses wildcard include", () => {
|
|
195
|
-
const result = parseQueryOptions({ include: "*" });
|
|
196
|
-
expect(result.include).toEqual(["*"]);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it("parses comma-separated includes", () => {
|
|
200
|
-
const result = parseQueryOptions({ include: "author,tags,category" });
|
|
201
|
-
expect(result.include).toEqual(["author", "tags", "category"]);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it("trims whitespace in includes", () => {
|
|
205
|
-
const result = parseQueryOptions({ include: " author , tags " });
|
|
206
|
-
expect(result.include).toEqual(["author", "tags"]);
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it("handles no include", () => {
|
|
210
|
-
const result = parseQueryOptions({});
|
|
211
|
-
expect(result.include).toBeUndefined();
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
// ─────────────────────────────────────────────────────────────
|
|
216
|
-
// parseQueryOptions — Field selection
|
|
217
|
-
// ─────────────────────────────────────────────────────────────
|
|
218
|
-
describe("parseQueryOptions — fields", () => {
|
|
219
|
-
it("parses comma-separated fields", () => {
|
|
220
|
-
const result = parseQueryOptions({ fields: "id,name,email" });
|
|
221
|
-
expect(result.fields).toEqual(["id", "name", "email"]);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it("trims whitespace", () => {
|
|
225
|
-
const result = parseQueryOptions({ fields: " id , name " });
|
|
226
|
-
expect(result.fields).toEqual(["id", "name"]);
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
it("handles no fields", () => {
|
|
230
|
-
const result = parseQueryOptions({});
|
|
231
|
-
expect(result.fields).toBeUndefined();
|
|
232
|
-
});
|
|
233
|
-
});
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { createRateLimiter } from "../src/auth/rate-limiter";
|
|
2
|
-
import { Hono } from "hono";
|
|
3
|
-
import { HonoEnv } from "../src/api/types";
|
|
4
|
-
|
|
5
|
-
describe("Rate Limiter", () => {
|
|
6
|
-
|
|
7
|
-
function createTestApp(options: { windowMs?: number; limit?: number } = {}) {
|
|
8
|
-
const app = new Hono<HonoEnv>();
|
|
9
|
-
const limiter = createRateLimiter({
|
|
10
|
-
windowMs: options.windowMs ?? 60 * 1000, // 1 minute
|
|
11
|
-
limit: options.limit ?? 3,
|
|
12
|
-
keyGenerator: (c) => c.req.header("x-forwarded-for") || "test-ip"
|
|
13
|
-
});
|
|
14
|
-
app.use("/api/*", limiter);
|
|
15
|
-
app.get("/api/test", (c) => c.json({ ok: true }));
|
|
16
|
-
return app;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
it("allows requests under the limit", async () => {
|
|
20
|
-
const app = createTestApp({ limit: 5 });
|
|
21
|
-
|
|
22
|
-
const res = await app.request("/api/test", {
|
|
23
|
-
headers: { "x-forwarded-for": "1.2.3.4" }
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
expect(res.status).toBe(200);
|
|
27
|
-
expect(res.headers.get("X-RateLimit-Limit")).toBe("5");
|
|
28
|
-
expect(res.headers.get("X-RateLimit-Remaining")).toBe("4");
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("returns 429 when limit is exceeded", async () => {
|
|
32
|
-
const app = createTestApp({ limit: 2 });
|
|
33
|
-
|
|
34
|
-
// First two should pass
|
|
35
|
-
await app.request("/api/test", { headers: { "x-forwarded-for": "10.0.0.1" } });
|
|
36
|
-
await app.request("/api/test", { headers: { "x-forwarded-for": "10.0.0.1" } });
|
|
37
|
-
|
|
38
|
-
// Third should be rate limited
|
|
39
|
-
const res = await app.request("/api/test", {
|
|
40
|
-
headers: { "x-forwarded-for": "10.0.0.1" }
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
expect(res.status).toBe(429);
|
|
44
|
-
const body = await res.json() as any;
|
|
45
|
-
expect(body.error.code).toBe("RATE_LIMITED");
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("includes Retry-After header when rate limited", async () => {
|
|
49
|
-
const app = createTestApp({ limit: 1 });
|
|
50
|
-
|
|
51
|
-
await app.request("/api/test", { headers: { "x-forwarded-for": "10.0.0.2" } });
|
|
52
|
-
const res = await app.request("/api/test", {
|
|
53
|
-
headers: { "x-forwarded-for": "10.0.0.2" }
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
expect(res.headers.get("Retry-After")).toBeDefined();
|
|
57
|
-
expect(res.headers.get("X-RateLimit-Remaining")).toBe("0");
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("tracks different IPs separately", async () => {
|
|
61
|
-
const app = createTestApp({ limit: 1 });
|
|
62
|
-
|
|
63
|
-
const res1 = await app.request("/api/test", {
|
|
64
|
-
headers: { "x-forwarded-for": "ip-a" }
|
|
65
|
-
});
|
|
66
|
-
const res2 = await app.request("/api/test", {
|
|
67
|
-
headers: { "x-forwarded-for": "ip-b" }
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
expect(res1.status).toBe(200);
|
|
71
|
-
expect(res2.status).toBe(200);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("decrements remaining count with each request", async () => {
|
|
75
|
-
const app = createTestApp({ limit: 3 });
|
|
76
|
-
const ip = "counter-ip";
|
|
77
|
-
|
|
78
|
-
const r1 = await app.request("/api/test", { headers: { "x-forwarded-for": ip } });
|
|
79
|
-
expect(r1.headers.get("X-RateLimit-Remaining")).toBe("2");
|
|
80
|
-
|
|
81
|
-
const r2 = await app.request("/api/test", { headers: { "x-forwarded-for": ip } });
|
|
82
|
-
expect(r2.headers.get("X-RateLimit-Remaining")).toBe("1");
|
|
83
|
-
|
|
84
|
-
const r3 = await app.request("/api/test", { headers: { "x-forwarded-for": ip } });
|
|
85
|
-
expect(r3.headers.get("X-RateLimit-Remaining")).toBe("0");
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("uses custom message", async () => {
|
|
89
|
-
const app = new Hono<HonoEnv>();
|
|
90
|
-
const limiter = createRateLimiter({
|
|
91
|
-
limit: 0,
|
|
92
|
-
message: "Slow down!",
|
|
93
|
-
keyGenerator: () => "always-same"
|
|
94
|
-
});
|
|
95
|
-
app.use("/api/*", limiter);
|
|
96
|
-
app.get("/api/test", (c) => c.json({ ok: true }));
|
|
97
|
-
|
|
98
|
-
const res = await app.request("/api/test");
|
|
99
|
-
const body = await res.json() as any;
|
|
100
|
-
expect(body.error.message).toBe("Slow down!");
|
|
101
|
-
});
|
|
102
|
-
});
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { Hono } from "hono";
|
|
2
|
-
import { createResetPasswordRoute } from "../src/auth/reset-password-admin";
|
|
3
|
-
import type { AuthRepository } from "../src/auth/interfaces";
|
|
4
|
-
import { configureJwt, generateAccessToken } from "../src/auth/jwt";
|
|
5
|
-
import { errorHandler } from "../src/api/errors";
|
|
6
|
-
|
|
7
|
-
const TEST_SECRET = "integration-test-secret-key-that-is-definitely-32-chars-long!!";
|
|
8
|
-
|
|
9
|
-
describe("createResetPasswordRoute & onAdminResetPassword", () => {
|
|
10
|
-
let mockAuthRepo: jest.Mocked<AuthRepository>;
|
|
11
|
-
let mockEmailService: { send: jest.Mock; isConfigured: jest.Mock };
|
|
12
|
-
|
|
13
|
-
beforeAll(() => {
|
|
14
|
-
configureJwt({ secret: TEST_SECRET,
|
|
15
|
-
accessExpiresIn: "1h" });
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
mockAuthRepo = {
|
|
20
|
-
getUserById: jest.fn(),
|
|
21
|
-
getUserRoleIds: jest.fn().mockResolvedValue(["admin"]),
|
|
22
|
-
updatePassword: jest.fn().mockResolvedValue(undefined),
|
|
23
|
-
createPasswordResetToken: jest.fn().mockResolvedValue(undefined)
|
|
24
|
-
} as unknown as jest.Mocked<AuthRepository>;
|
|
25
|
-
|
|
26
|
-
mockEmailService = {
|
|
27
|
-
send: jest.fn().mockResolvedValue(undefined),
|
|
28
|
-
isConfigured: jest.fn().mockReturnValue(true)
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
function createApp(authHooks?: any) {
|
|
33
|
-
const app = new Hono();
|
|
34
|
-
app.onError(errorHandler);
|
|
35
|
-
const adminRoutes = createResetPasswordRoute({
|
|
36
|
-
authRepo: mockAuthRepo,
|
|
37
|
-
emailService: mockEmailService as any,
|
|
38
|
-
emailConfig: {
|
|
39
|
-
from: "test@example.com",
|
|
40
|
-
resetPasswordUrl: "https://reset.com"
|
|
41
|
-
},
|
|
42
|
-
authHooks
|
|
43
|
-
});
|
|
44
|
-
app.route("/api/admin", adminRoutes);
|
|
45
|
-
return app;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
it("falls back to default password reset logic when no hook is provided", async () => {
|
|
49
|
-
mockAuthRepo.getUserById.mockResolvedValue({
|
|
50
|
-
id: "user-123",
|
|
51
|
-
email: "user@example.com",
|
|
52
|
-
displayName: "User One"
|
|
53
|
-
} as any);
|
|
54
|
-
|
|
55
|
-
const app = createApp();
|
|
56
|
-
const adminToken = generateAccessToken("admin-user", ["admin"]);
|
|
57
|
-
|
|
58
|
-
const res = await app.request("/api/admin/users/user-123/reset-password", {
|
|
59
|
-
method: "POST",
|
|
60
|
-
headers: {
|
|
61
|
-
"Authorization": `Bearer ${adminToken}`
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
expect(res.status).toBe(200);
|
|
66
|
-
const body = await res.json() as any;
|
|
67
|
-
expect(body.invitationSent).toBe(true);
|
|
68
|
-
expect(body.user.uid).toBe("user-123");
|
|
69
|
-
expect(mockAuthRepo.createPasswordResetToken).toHaveBeenCalled();
|
|
70
|
-
expect(mockEmailService.send).toHaveBeenCalled();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("calls onAdminResetPassword hook when provided", async () => {
|
|
74
|
-
mockAuthRepo.getUserById.mockResolvedValue({
|
|
75
|
-
id: "user-123",
|
|
76
|
-
email: "user@example.com",
|
|
77
|
-
displayName: "User One"
|
|
78
|
-
} as any);
|
|
79
|
-
|
|
80
|
-
const onAdminResetPasswordMock = jest.fn().mockResolvedValue({
|
|
81
|
-
temporaryPassword: "hook-temp-password",
|
|
82
|
-
invitationSent: false
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const app = createApp({
|
|
86
|
-
onAdminResetPassword: onAdminResetPasswordMock
|
|
87
|
-
});
|
|
88
|
-
const adminToken = generateAccessToken("admin-user", ["admin"]);
|
|
89
|
-
|
|
90
|
-
const res = await app.request("/api/admin/users/user-123/reset-password", {
|
|
91
|
-
method: "POST",
|
|
92
|
-
headers: {
|
|
93
|
-
"Authorization": `Bearer ${adminToken}`
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
expect(res.status).toBe(200);
|
|
98
|
-
const body = await res.json() as any;
|
|
99
|
-
expect(body.invitationSent).toBe(false);
|
|
100
|
-
expect(body.temporaryPassword).toBe("hook-temp-password");
|
|
101
|
-
expect(body.user.uid).toBe("user-123");
|
|
102
|
-
|
|
103
|
-
expect(onAdminResetPasswordMock).toHaveBeenCalledWith(
|
|
104
|
-
"user-123",
|
|
105
|
-
expect.objectContaining({
|
|
106
|
-
authRepo: mockAuthRepo,
|
|
107
|
-
emailService: mockEmailService
|
|
108
|
-
})
|
|
109
|
-
);
|
|
110
|
-
expect(mockAuthRepo.createPasswordResetToken).not.toHaveBeenCalled();
|
|
111
|
-
expect(mockEmailService.send).not.toHaveBeenCalled();
|
|
112
|
-
});
|
|
113
|
-
});
|