@actuate-media/cms-core 0.12.0 → 0.14.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/LICENSE +21 -21
- package/dist/__tests__/api/api-key-auth.test.d.ts +2 -0
- package/dist/__tests__/api/api-key-auth.test.d.ts.map +1 -0
- package/dist/__tests__/api/api-key-auth.test.js +217 -0
- package/dist/__tests__/api/api-key-auth.test.js.map +1 -0
- package/dist/__tests__/api/health.test.d.ts +2 -0
- package/dist/__tests__/api/health.test.d.ts.map +1 -0
- package/dist/__tests__/api/health.test.js +140 -0
- package/dist/__tests__/api/health.test.js.map +1 -0
- package/dist/__tests__/auth/oauth.test.d.ts +2 -0
- package/dist/__tests__/auth/oauth.test.d.ts.map +1 -0
- package/dist/__tests__/auth/oauth.test.js +406 -0
- package/dist/__tests__/auth/oauth.test.js.map +1 -0
- package/dist/__tests__/auth/reset.test.d.ts +2 -0
- package/dist/__tests__/auth/reset.test.d.ts.map +1 -0
- package/dist/__tests__/auth/reset.test.js +303 -0
- package/dist/__tests__/auth/reset.test.js.map +1 -0
- package/dist/__tests__/diagnostics/env.test.d.ts +2 -0
- package/dist/__tests__/diagnostics/env.test.d.ts.map +1 -0
- package/dist/__tests__/diagnostics/env.test.js +119 -0
- package/dist/__tests__/diagnostics/env.test.js.map +1 -0
- package/dist/__tests__/diagnostics/logger.test.d.ts +2 -0
- package/dist/__tests__/diagnostics/logger.test.d.ts.map +1 -0
- package/dist/__tests__/diagnostics/logger.test.js +111 -0
- package/dist/__tests__/diagnostics/logger.test.js.map +1 -0
- package/dist/__tests__/security/api-key-enhanced.test.d.ts +2 -0
- package/dist/__tests__/security/api-key-enhanced.test.d.ts.map +1 -0
- package/dist/__tests__/security/api-key-enhanced.test.js +110 -0
- package/dist/__tests__/security/api-key-enhanced.test.js.map +1 -0
- package/dist/__tests__/security/rate-limit.test.js +42 -0
- package/dist/__tests__/security/rate-limit.test.js.map +1 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +7 -6
- package/dist/actions.js.map +1 -1
- package/dist/api/handler-factory.d.ts.map +1 -1
- package/dist/api/handler-factory.js +31 -8
- package/dist/api/handler-factory.js.map +1 -1
- package/dist/api/handlers.d.ts.map +1 -1
- package/dist/api/handlers.js +508 -55
- package/dist/api/handlers.js.map +1 -1
- package/dist/auth/oauth.d.ts.map +1 -1
- package/dist/auth/oauth.js +5 -1
- package/dist/auth/oauth.js.map +1 -1
- package/dist/auth/reset.d.ts.map +1 -1
- package/dist/auth/reset.js +2 -1
- package/dist/auth/reset.js.map +1 -1
- package/dist/config/runtime.d.ts +99 -0
- package/dist/config/runtime.d.ts.map +1 -0
- package/dist/config/runtime.js +43 -0
- package/dist/config/runtime.js.map +1 -0
- package/dist/config/types.d.ts +21 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/diagnostics/env.d.ts +44 -0
- package/dist/diagnostics/env.d.ts.map +1 -0
- package/dist/diagnostics/env.js +293 -0
- package/dist/diagnostics/env.js.map +1 -0
- package/dist/diagnostics/logger.d.ts +38 -0
- package/dist/diagnostics/logger.d.ts.map +1 -0
- package/dist/diagnostics/logger.js +89 -0
- package/dist/diagnostics/logger.js.map +1 -0
- package/dist/page-builder/blocks.d.ts.map +1 -1
- package/dist/page-builder/blocks.js +6 -1
- package/dist/page-builder/blocks.js.map +1 -1
- package/dist/security/api-key-enhanced.d.ts +48 -5
- package/dist/security/api-key-enhanced.d.ts.map +1 -1
- package/dist/security/api-key-enhanced.js +60 -9
- package/dist/security/api-key-enhanced.js.map +1 -1
- package/dist/security/audit.d.ts.map +1 -1
- package/dist/security/audit.js +3 -1
- package/dist/security/audit.js.map +1 -1
- package/dist/security/rate-limit.d.ts +8 -0
- package/dist/security/rate-limit.d.ts.map +1 -1
- package/dist/security/rate-limit.js +81 -3
- package/dist/security/rate-limit.js.map +1 -1
- package/generated/browser.ts +109 -0
- package/generated/client.ts +133 -0
- package/generated/commonInputTypes.ts +709 -0
- package/generated/enums.ts +125 -0
- package/generated/internal/class.ts +376 -0
- package/generated/internal/prismaNamespace.ts +2617 -0
- package/generated/internal/prismaNamespaceBrowser.ts +611 -0
- package/generated/models/ApiKey.ts +1550 -0
- package/generated/models/AuditLog.ts +1206 -0
- package/generated/models/BackupRecord.ts +1250 -0
- package/generated/models/ContentLock.ts +1472 -0
- package/generated/models/ContentTemplate.ts +1416 -0
- package/generated/models/Document.ts +3005 -0
- package/generated/models/Folder.ts +1904 -0
- package/generated/models/FormSubmission.ts +1200 -0
- package/generated/models/InAppNotification.ts +1457 -0
- package/generated/models/Media.ts +2340 -0
- package/generated/models/MediaUsage.ts +1472 -0
- package/generated/models/OAuthAccount.ts +1463 -0
- package/generated/models/Redirect.ts +1284 -0
- package/generated/models/Session.ts +1492 -0
- package/generated/models/Site.ts +1206 -0
- package/generated/models/User.ts +3513 -0
- package/generated/models/Version.ts +1511 -0
- package/generated/models/WorkflowState.ts +1514 -0
- package/generated/models.ts +29 -0
- package/package.json +1 -1
- package/prisma/cms-schema.prisma +306 -306
- package/prisma/migrations/0001_init/migration.sql +384 -384
- package/prisma/migrations/0002_folders/migration.sql +39 -39
- package/prisma/migrations/0003_search_and_webhooks/migration.sql +50 -50
- package/prisma/migrations/0004_script_tags/migration.sql +21 -21
- package/prisma/migrations/0005_password_reset_tokens/migration.sql +20 -20
- package/prisma/migrations/0006_page_builder/migration.sql +38 -38
- package/prisma/migrations/migration_lock.toml +3 -3
- package/prisma/schema.prisma +549 -549
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Actuate Media
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Actuate Media
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key-auth.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/api/api-key-auth.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import { handleActuateAPI } from '../../api/index.js';
|
|
3
|
+
import { initDB } from '../../db.js';
|
|
4
|
+
import { generateApiKey } from '../../security/api-key-enhanced.js';
|
|
5
|
+
// Make sure the API surface that authenticates via API keys actually:
|
|
6
|
+
// 1. accepts an `Authorization: Bearer act_sk_*` token without CSRF,
|
|
7
|
+
// 2. enforces the key's scopes (collection + action),
|
|
8
|
+
// 3. rejects revoked/expired keys.
|
|
9
|
+
//
|
|
10
|
+
// We don't spin up the real database for these — a mock Prisma client that
|
|
11
|
+
// answers `apiKey.findUnique` and a minimal `document` interface is enough
|
|
12
|
+
// to exercise the auth + CSRF skip + scope check paths.
|
|
13
|
+
const VALID_SECRET = 'a'.repeat(48);
|
|
14
|
+
function createMockDB(opts) {
|
|
15
|
+
const apiKey = opts.apiKey;
|
|
16
|
+
return {
|
|
17
|
+
apiKey: {
|
|
18
|
+
// `hasModel` probes for `findMany` to decide whether the model exists
|
|
19
|
+
// on the Prisma client. Including a stub here is enough to clear the
|
|
20
|
+
// check even though our tests only exercise findUnique/update.
|
|
21
|
+
findMany: async () => (apiKey ? [apiKey] : []),
|
|
22
|
+
findUnique: async ({ where }) => {
|
|
23
|
+
if (!apiKey)
|
|
24
|
+
return null;
|
|
25
|
+
if (apiKey.keyHash !== where.keyHash)
|
|
26
|
+
return null;
|
|
27
|
+
return apiKey;
|
|
28
|
+
},
|
|
29
|
+
update: async () => apiKey,
|
|
30
|
+
},
|
|
31
|
+
document: {
|
|
32
|
+
findMany: async () => [],
|
|
33
|
+
count: async () => 0,
|
|
34
|
+
create: async ({ data }) => ({ ...data, id: 'doc-1', createdAt: new Date(), updatedAt: new Date() }),
|
|
35
|
+
},
|
|
36
|
+
user: {},
|
|
37
|
+
session: {},
|
|
38
|
+
media: {},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async function makeKey(scopes) {
|
|
42
|
+
const { key, keyHash, keyPrefix } = await generateApiKey({ prefix: 'act_sk', scopes });
|
|
43
|
+
return {
|
|
44
|
+
key,
|
|
45
|
+
record: {
|
|
46
|
+
id: 'apikey-1',
|
|
47
|
+
keyHash,
|
|
48
|
+
keyPrefix,
|
|
49
|
+
userId: 'user-1',
|
|
50
|
+
scopes,
|
|
51
|
+
ipRestrictions: null,
|
|
52
|
+
expiresAt: null,
|
|
53
|
+
lastUsedAt: null,
|
|
54
|
+
revokedAt: null,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
describe('API key authentication', () => {
|
|
59
|
+
beforeEach(() => {
|
|
60
|
+
delete globalThis.__actuateConfig;
|
|
61
|
+
process.env.CMS_SECRET = VALID_SECRET;
|
|
62
|
+
});
|
|
63
|
+
it('allows a request authenticated by a valid API key (no CSRF token)', async () => {
|
|
64
|
+
const { key, record } = await makeKey({ collections: ['posts'], actions: ['read'] });
|
|
65
|
+
const db = createMockDB({ apiKey: record });
|
|
66
|
+
initDB(db);
|
|
67
|
+
const handler = handleActuateAPI({
|
|
68
|
+
prismaClient: db,
|
|
69
|
+
config: { collections: { posts: { slug: 'posts', labels: { singular: 'Post', plural: 'Posts' }, fields: {} } } },
|
|
70
|
+
});
|
|
71
|
+
const response = await handler(new Request('https://example.com/api/cms/collections/posts', {
|
|
72
|
+
headers: { Authorization: `Bearer ${key}` },
|
|
73
|
+
}));
|
|
74
|
+
expect(response.status).toBe(200);
|
|
75
|
+
});
|
|
76
|
+
it('rejects with 401 when bearer token does not match any API key in the DB', async () => {
|
|
77
|
+
const { record } = await makeKey({ admin: true });
|
|
78
|
+
const db = createMockDB({ apiKey: record });
|
|
79
|
+
initDB(db);
|
|
80
|
+
const handler = handleActuateAPI({
|
|
81
|
+
prismaClient: db,
|
|
82
|
+
config: { collections: { posts: { slug: 'posts', labels: { singular: 'Post', plural: 'Posts' }, fields: {} } } },
|
|
83
|
+
});
|
|
84
|
+
const fakeKey = 'act_sk_' + 'f'.repeat(64);
|
|
85
|
+
const response = await handler(new Request('https://example.com/api/cms/collections/posts', {
|
|
86
|
+
headers: { Authorization: `Bearer ${fakeKey}` },
|
|
87
|
+
}));
|
|
88
|
+
expect(response.status).toBe(401);
|
|
89
|
+
});
|
|
90
|
+
it('rejects revoked API keys', async () => {
|
|
91
|
+
const { key, record } = await makeKey({ admin: true });
|
|
92
|
+
record.revokedAt = new Date();
|
|
93
|
+
const db = createMockDB({ apiKey: record });
|
|
94
|
+
initDB(db);
|
|
95
|
+
const handler = handleActuateAPI({
|
|
96
|
+
prismaClient: db,
|
|
97
|
+
config: { collections: { posts: { slug: 'posts', labels: { singular: 'Post', plural: 'Posts' }, fields: {} } } },
|
|
98
|
+
});
|
|
99
|
+
const response = await handler(new Request('https://example.com/api/cms/collections/posts', {
|
|
100
|
+
headers: { Authorization: `Bearer ${key}` },
|
|
101
|
+
}));
|
|
102
|
+
expect(response.status).toBe(401);
|
|
103
|
+
});
|
|
104
|
+
it('rejects expired API keys', async () => {
|
|
105
|
+
const { key, record } = await makeKey({ admin: true });
|
|
106
|
+
record.expiresAt = new Date(Date.now() - 60_000);
|
|
107
|
+
const db = createMockDB({ apiKey: record });
|
|
108
|
+
initDB(db);
|
|
109
|
+
const handler = handleActuateAPI({
|
|
110
|
+
prismaClient: db,
|
|
111
|
+
config: { collections: { posts: { slug: 'posts', labels: { singular: 'Post', plural: 'Posts' }, fields: {} } } },
|
|
112
|
+
});
|
|
113
|
+
const response = await handler(new Request('https://example.com/api/cms/collections/posts', {
|
|
114
|
+
headers: { Authorization: `Bearer ${key}` },
|
|
115
|
+
}));
|
|
116
|
+
expect(response.status).toBe(401);
|
|
117
|
+
});
|
|
118
|
+
it('rejects with 403 when scope does not include the requested collection', async () => {
|
|
119
|
+
const { key, record } = await makeKey({ collections: ['posts'], actions: ['read'] });
|
|
120
|
+
const db = createMockDB({ apiKey: record });
|
|
121
|
+
initDB(db);
|
|
122
|
+
const handler = handleActuateAPI({
|
|
123
|
+
prismaClient: db,
|
|
124
|
+
config: {
|
|
125
|
+
collections: {
|
|
126
|
+
posts: { slug: 'posts', labels: { singular: 'Post', plural: 'Posts' }, fields: {} },
|
|
127
|
+
pages: { slug: 'pages', labels: { singular: 'Page', plural: 'Pages' }, fields: {} },
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
const response = await handler(new Request('https://example.com/api/cms/collections/pages', {
|
|
132
|
+
headers: { Authorization: `Bearer ${key}` },
|
|
133
|
+
}));
|
|
134
|
+
expect(response.status).toBe(403);
|
|
135
|
+
});
|
|
136
|
+
it('rejects with 403 when scope does not include the requested action', async () => {
|
|
137
|
+
const { key, record } = await makeKey({ collections: ['posts'], actions: ['read'] });
|
|
138
|
+
const db = createMockDB({ apiKey: record });
|
|
139
|
+
initDB(db);
|
|
140
|
+
const handler = handleActuateAPI({
|
|
141
|
+
prismaClient: db,
|
|
142
|
+
config: { collections: { posts: { slug: 'posts', labels: { singular: 'Post', plural: 'Posts' }, fields: {} } } },
|
|
143
|
+
});
|
|
144
|
+
// POST should be blocked without `create` in actions — and crucially the
|
|
145
|
+
// request has no CSRF token, so we're confirming that the API-key path
|
|
146
|
+
// bypassed CSRF and got as far as scope enforcement before failing.
|
|
147
|
+
const response = await handler(new Request('https://example.com/api/cms/collections/posts', {
|
|
148
|
+
method: 'POST',
|
|
149
|
+
headers: { Authorization: `Bearer ${key}`, 'Content-Type': 'application/json' },
|
|
150
|
+
body: JSON.stringify({ title: 'Hello' }),
|
|
151
|
+
}));
|
|
152
|
+
expect(response.status).toBe(403);
|
|
153
|
+
});
|
|
154
|
+
it('CSRF middleware does not block API-key POST requests', async () => {
|
|
155
|
+
// Same shape as the previous test but with create scope — the request
|
|
156
|
+
// should make it past CSRF, past scope, and at least into the action
|
|
157
|
+
// handler. A 500/400 from the action layer here would still mean the
|
|
158
|
+
// CSRF check passed (which is what we're asserting).
|
|
159
|
+
const { key, record } = await makeKey({ collections: ['posts'], actions: ['create'], admin: false });
|
|
160
|
+
const db = createMockDB({ apiKey: record });
|
|
161
|
+
initDB(db);
|
|
162
|
+
const handler = handleActuateAPI({
|
|
163
|
+
prismaClient: db,
|
|
164
|
+
config: { collections: { posts: { slug: 'posts', labels: { singular: 'Post', plural: 'Posts' }, fields: {} } } },
|
|
165
|
+
});
|
|
166
|
+
const response = await handler(new Request('https://example.com/api/cms/collections/posts', {
|
|
167
|
+
method: 'POST',
|
|
168
|
+
headers: { Authorization: `Bearer ${key}`, 'Content-Type': 'application/json' },
|
|
169
|
+
body: JSON.stringify({ title: 'Hello' }),
|
|
170
|
+
}));
|
|
171
|
+
// Should not be a 403 CSRF rejection.
|
|
172
|
+
expect(response.status).not.toBe(403);
|
|
173
|
+
if (response.status === 403) {
|
|
174
|
+
const body = await response.json().catch(() => ({}));
|
|
175
|
+
expect(body.error).not.toBe('Invalid CSRF token');
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
it('non-API-key requests still require CSRF for POST', async () => {
|
|
179
|
+
const db = createMockDB({});
|
|
180
|
+
initDB(db);
|
|
181
|
+
const handler = handleActuateAPI({
|
|
182
|
+
prismaClient: db,
|
|
183
|
+
config: { collections: { posts: { slug: 'posts', labels: { singular: 'Post', plural: 'Posts' }, fields: {} } } },
|
|
184
|
+
});
|
|
185
|
+
const response = await handler(new Request('https://example.com/api/cms/collections/posts', {
|
|
186
|
+
method: 'POST',
|
|
187
|
+
headers: { 'Content-Type': 'application/json' },
|
|
188
|
+
body: JSON.stringify({ title: 'Hello' }),
|
|
189
|
+
}));
|
|
190
|
+
expect(response.status).toBe(403);
|
|
191
|
+
const body = await response.json().catch(() => ({}));
|
|
192
|
+
expect(body.error).toBe('Invalid CSRF token');
|
|
193
|
+
});
|
|
194
|
+
it('admin scope grants access to any collection', async () => {
|
|
195
|
+
const { key, record } = await makeKey({ admin: true });
|
|
196
|
+
const db = createMockDB({ apiKey: record });
|
|
197
|
+
initDB(db);
|
|
198
|
+
const handler = handleActuateAPI({
|
|
199
|
+
prismaClient: db,
|
|
200
|
+
config: {
|
|
201
|
+
collections: {
|
|
202
|
+
posts: { slug: 'posts', labels: { singular: 'Post', plural: 'Posts' }, fields: {} },
|
|
203
|
+
pages: { slug: 'pages', labels: { singular: 'Page', plural: 'Pages' }, fields: {} },
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
const a = await handler(new Request('https://example.com/api/cms/collections/posts', {
|
|
208
|
+
headers: { Authorization: `Bearer ${key}` },
|
|
209
|
+
}));
|
|
210
|
+
const b = await handler(new Request('https://example.com/api/cms/collections/pages', {
|
|
211
|
+
headers: { Authorization: `Bearer ${key}` },
|
|
212
|
+
}));
|
|
213
|
+
expect(a.status).toBe(200);
|
|
214
|
+
expect(b.status).toBe(200);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
//# sourceMappingURL=api-key-auth.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key-auth.test.js","sourceRoot":"","sources":["../../../src/__tests__/api/api-key-auth.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,cAAc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;QACtD,MAAM,EAAE,GAAG,YAAY,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;QAC3C,MAAM,CAAC,EAAE,CAAC,CAAA;QACV,MAAM,OAAO,GAAG,gBAAgB,CAAC;YAC/B,YAAY,EAAE,EAAE;YAChB,MAAM,EAAE;gBACN,WAAW,EAAE;oBACX,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;oBACnF,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;iBACpF;aACF;SACF,CAAC,CAAA;QAEF,MAAM,CAAC,GAAG,MAAM,OAAO,CACrB,IAAI,OAAO,CAAC,+CAA+C,EAAE;YAC3D,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,GAAG,EAAE,EAAE;SAC5C,CAAC,CACH,CAAA;QACD,MAAM,CAAC,GAAG,MAAM,OAAO,CACrB,IAAI,OAAO,CAAC,+CAA+C,EAAE;YAC3D,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,GAAG,EAAE,EAAE;SAC5C,CAAC,CACH,CAAA;QAED,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC1B,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC5B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/api/health.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import { handleActuateAPI } from '../../api/index.js';
|
|
3
|
+
import { setActuateConfig } from '../../config/runtime.js';
|
|
4
|
+
import { initDB } from '../../db.js';
|
|
5
|
+
const VALID_SECRET = 'a-real-cms-secret-of-at-least-32-characters';
|
|
6
|
+
describe('/api/cms/health status derivation', () => {
|
|
7
|
+
// Snapshot every env var any test in this file mutates so we can restore
|
|
8
|
+
// them in `afterEach`. NOTE: `CMS_SESSION_SECRET` is included even though
|
|
9
|
+
// only one test sets it — Bugbot caught the original test where cleanup
|
|
10
|
+
// ran inline and was therefore skipped on assertion failure, leaking the
|
|
11
|
+
// legacy secret into the next `it.each` iteration and causing the
|
|
12
|
+
// config-file path test to pass for the wrong reason.
|
|
13
|
+
const original = {
|
|
14
|
+
CMS_SECRET: process.env.CMS_SECRET,
|
|
15
|
+
CMS_SESSION_SECRET: process.env.CMS_SESSION_SECRET,
|
|
16
|
+
CMS_ENCRYPTION_KEY: process.env.CMS_ENCRYPTION_KEY,
|
|
17
|
+
CRON_SECRET: process.env.CRON_SECRET,
|
|
18
|
+
DATABASE_URL: process.env.DATABASE_URL,
|
|
19
|
+
};
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
process.env.CMS_SECRET = VALID_SECRET;
|
|
22
|
+
process.env.DATABASE_URL = 'postgres://x';
|
|
23
|
+
delete process.env.CMS_SESSION_SECRET;
|
|
24
|
+
delete process.env.CMS_ENCRYPTION_KEY;
|
|
25
|
+
delete process.env.CRON_SECRET;
|
|
26
|
+
});
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
for (const [k, v] of Object.entries(original)) {
|
|
29
|
+
if (v === undefined)
|
|
30
|
+
delete process.env[k];
|
|
31
|
+
else
|
|
32
|
+
process.env[k] = v;
|
|
33
|
+
}
|
|
34
|
+
// Tests within this file share `globalThis`, so explicitly clear any
|
|
35
|
+
// config a single test stashed (see `runtime.ts` doc — "Tests reset
|
|
36
|
+
// between suites").
|
|
37
|
+
delete globalThis.__actuateConfig;
|
|
38
|
+
});
|
|
39
|
+
// Bugbot review (PR #41): the early-return DB-failure path hardcoded
|
|
40
|
+
// `status: 'degraded'`, ignoring the env validation result computed two
|
|
41
|
+
// lines above. A deploy with both a broken DB *and* a malformed CMS_SECRET
|
|
42
|
+
// would report `degraded` even though it's actually `unhealthy` —
|
|
43
|
+
// defeating M6's whole point of catching env misconfig at /health time.
|
|
44
|
+
it('returns "unhealthy" when env is misconfigured AND db() throws', async () => {
|
|
45
|
+
process.env.CMS_SECRET = 'too-short'; // triggers env error
|
|
46
|
+
// Force db() to throw by initializing with an object that the route's
|
|
47
|
+
// model probes will treat as unusable while leaving db() itself callable.
|
|
48
|
+
// The simplest way is to trip the catch by leaving DB uninitialized.
|
|
49
|
+
initDB(null); // db() will throw "Prisma client not initialised"
|
|
50
|
+
const handler = handleActuateAPI({ prismaClient: null });
|
|
51
|
+
const response = await handler(new Request('https://example.com/api/cms/health', { method: 'GET' }));
|
|
52
|
+
expect(response.status).toBe(200);
|
|
53
|
+
const payload = (await response.json());
|
|
54
|
+
expect(payload.data.databaseConnected).toBe(false);
|
|
55
|
+
expect(payload.data.status).toBe('unhealthy');
|
|
56
|
+
});
|
|
57
|
+
it('returns "degraded" when only db() throws (env is fine)', async () => {
|
|
58
|
+
initDB(null);
|
|
59
|
+
const handler = handleActuateAPI({ prismaClient: null });
|
|
60
|
+
const response = await handler(new Request('https://example.com/api/cms/health', { method: 'GET' }));
|
|
61
|
+
const payload = (await response.json());
|
|
62
|
+
expect(payload.data.status).toBe('degraded');
|
|
63
|
+
});
|
|
64
|
+
// Bugbot review (PR #41): the unauthenticated /health response embeds the
|
|
65
|
+
// full env validation, so any "ok" message that mentions the configured
|
|
66
|
+
// secret length leaks that length to anonymous callers. Validate the
|
|
67
|
+
// serialized response here so a regression in either the env module or the
|
|
68
|
+
// health route is caught.
|
|
69
|
+
it('does not leak exact secret lengths in the /health JSON', async () => {
|
|
70
|
+
process.env.CMS_SECRET = 'a'.repeat(45);
|
|
71
|
+
process.env.CRON_SECRET = 'a-real-cron-secret-with-known-length';
|
|
72
|
+
process.env.CMS_ENCRYPTION_KEY = 'a1b2'.repeat(16);
|
|
73
|
+
initDB({
|
|
74
|
+
document: { count: async () => 0 },
|
|
75
|
+
user: { count: async () => 0 },
|
|
76
|
+
media: { count: async () => 0 },
|
|
77
|
+
});
|
|
78
|
+
const handler = handleActuateAPI({
|
|
79
|
+
prismaClient: {
|
|
80
|
+
document: { count: async () => 0 },
|
|
81
|
+
user: { count: async () => 0 },
|
|
82
|
+
media: { count: async () => 0 },
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
const response = await handler(new Request('https://example.com/api/cms/health', { method: 'GET' }));
|
|
86
|
+
const text = await response.text();
|
|
87
|
+
// No "Configured (N chars)." anywhere. Use a regex broad enough to catch
|
|
88
|
+
// both "42 chars" and "42 chars." variants.
|
|
89
|
+
expect(text).not.toMatch(/\d+\s*chars?/i);
|
|
90
|
+
// And specifically, the configured lengths must not appear next to the
|
|
91
|
+
// secret names in the response body.
|
|
92
|
+
expect(text).not.toContain('45');
|
|
93
|
+
});
|
|
94
|
+
// Bugbot review (PR #43): `validateEnvShape()` only inspected
|
|
95
|
+
// `process.env.CMS_SECRET`, but `getSessionSecret()` also accepts the
|
|
96
|
+
// secret from the legacy `CMS_SESSION_SECRET` env var or `actuate.config.ts
|
|
97
|
+
// → secret`. Without the wrapping the route now applies, a deploy that
|
|
98
|
+
// configures the secret via the config file would get the contradictory
|
|
99
|
+
// response `secretConfigured: true` AND `status: "unhealthy"`, tripping
|
|
100
|
+
// monitoring / load-balancer health probes for no real fault.
|
|
101
|
+
it.each([
|
|
102
|
+
[
|
|
103
|
+
'CMS_SESSION_SECRET (legacy env var)',
|
|
104
|
+
() => {
|
|
105
|
+
delete process.env.CMS_SECRET;
|
|
106
|
+
process.env.CMS_SESSION_SECRET = 'a'.repeat(40);
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
[
|
|
110
|
+
'actuate.config.ts → secret (config-file path)',
|
|
111
|
+
() => {
|
|
112
|
+
delete process.env.CMS_SECRET;
|
|
113
|
+
setActuateConfig({ secret: 'a'.repeat(40) });
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
])('does not report unhealthy when CMS_SECRET is supplied via %s', async (_label, setup) => {
|
|
117
|
+
setup();
|
|
118
|
+
initDB({
|
|
119
|
+
document: { count: async () => 0 },
|
|
120
|
+
user: { count: async () => 0 },
|
|
121
|
+
media: { count: async () => 0 },
|
|
122
|
+
});
|
|
123
|
+
const handler = handleActuateAPI({
|
|
124
|
+
prismaClient: {
|
|
125
|
+
document: { count: async () => 0 },
|
|
126
|
+
user: { count: async () => 0 },
|
|
127
|
+
media: { count: async () => 0 },
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
const response = await handler(new Request('https://example.com/api/cms/health', { method: 'GET' }));
|
|
131
|
+
const payload = (await response.json());
|
|
132
|
+
// Both signals must agree — no contradictory `secretConfigured: true`
|
|
133
|
+
// alongside `status: "unhealthy"`.
|
|
134
|
+
expect(payload.data.secretConfigured).toBe(true);
|
|
135
|
+
expect(payload.data.status).not.toBe('unhealthy');
|
|
136
|
+
const cmsSecretCheck = payload.data.env.checks.find((c) => c.name === 'CMS_SECRET');
|
|
137
|
+
expect(cmsSecretCheck?.status).toBe('ok');
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
//# sourceMappingURL=health.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.test.js","sourceRoot":"","sources":["../../../src/__tests__/api/health.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,M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