@stamhoofd/backend-renderer 2.143.1 → 2.144.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stamhoofd/backend-renderer",
3
- "version": "2.143.1",
3
+ "version": "2.144.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {
@@ -27,14 +27,14 @@
27
27
  "@simonbackx/simple-endpoints": "1.22.0",
28
28
  "@simonbackx/simple-errors": "1.5.0",
29
29
  "@simonbackx/simple-logging": "1.0.1",
30
- "@stamhoofd/backend-env": "2.143.1",
31
- "@stamhoofd/backend-i18n": "2.143.1",
32
- "@stamhoofd/backend-middleware": "2.143.1",
33
- "@stamhoofd/logging": "2.143.1",
34
- "@stamhoofd/queues": "2.143.1",
35
- "@stamhoofd/structures": "2.143.1",
36
- "@stamhoofd/types": "2.143.1",
37
- "@stamhoofd/utility": "2.143.1",
30
+ "@stamhoofd/backend-env": "2.144.0",
31
+ "@stamhoofd/backend-i18n": "2.144.0",
32
+ "@stamhoofd/backend-middleware": "2.144.0",
33
+ "@stamhoofd/logging": "2.144.0",
34
+ "@stamhoofd/queues": "2.144.0",
35
+ "@stamhoofd/structures": "2.144.0",
36
+ "@stamhoofd/types": "2.144.0",
37
+ "@stamhoofd/utility": "2.144.0",
38
38
  "formidable": "3.5.4",
39
39
  "luxon": "3.7.2",
40
40
  "mockdate": "3.0.5",
@@ -42,7 +42,7 @@
42
42
  "puppeteer": "25.3.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@stamhoofd/test-utils": "2.143.1",
45
+ "@stamhoofd/test-utils": "2.144.0",
46
46
  "@types/formidable": "3.5.1",
47
47
  "@types/luxon": "3.7.2",
48
48
  "@types/node": "22.20.1",
@@ -53,5 +53,5 @@
53
53
  "publishConfig": {
54
54
  "access": "public"
55
55
  },
56
- "gitHead": "2102409bc039c3ee4dc77cdd6c1338f6cf390c9c"
56
+ "gitHead": "31bc31b2a56d9516e8bc6be5779bc58af0022a88"
57
57
  }
@@ -0,0 +1,60 @@
1
+ import { signInternal, verifyInternalSignature } from '@stamhoofd/backend-env';
2
+ import { TestUtils } from '@stamhoofd/test-utils';
3
+
4
+ describe('verifyInternalSignature', () => {
5
+ const rendererKey = Buffer.from('renderer-own-secret').toString('base64');
6
+ const platformKey = Buffer.from('other-platform-secret').toString('base64');
7
+ const unknownKey = Buffer.from('unknown-secret').toString('base64');
8
+ const content = ['cache-id', '1755500000000', '<html>test</html>'];
9
+
10
+ function signWith(key: string, ...signedContent: string[]) {
11
+ TestUtils.setEnvironment('INTERNAL_SECRET_KEY', key);
12
+ return signInternal(...signedContent);
13
+ }
14
+
15
+ beforeEach(() => {
16
+ TestUtils.setEnvironment('INTERNAL_SECRET_KEY', rendererKey);
17
+ TestUtils.setEnvironment('EXTRA_INTERNAL_SECRET_KEYS', undefined);
18
+ });
19
+
20
+ test('Accepts a signature created with the own key', () => {
21
+ const signature = signWith(rendererKey, ...content);
22
+
23
+ TestUtils.setEnvironment('INTERNAL_SECRET_KEY', rendererKey);
24
+ expect(verifyInternalSignature(signature, ...content)).toBe(true);
25
+ });
26
+
27
+ test('Accepts a signature created with an extra accepted key', () => {
28
+ const signature = signWith(platformKey, ...content);
29
+
30
+ TestUtils.setEnvironment('INTERNAL_SECRET_KEY', rendererKey);
31
+ TestUtils.setEnvironment('EXTRA_INTERNAL_SECRET_KEYS', [platformKey]);
32
+ expect(verifyInternalSignature(signature, ...content)).toBe(true);
33
+ });
34
+
35
+ test('Rejects a signature created with an unknown key', () => {
36
+ const signature = signWith(unknownKey, ...content);
37
+
38
+ TestUtils.setEnvironment('INTERNAL_SECRET_KEY', rendererKey);
39
+ TestUtils.setEnvironment('EXTRA_INTERNAL_SECRET_KEYS', [platformKey]);
40
+ expect(verifyInternalSignature(signature, ...content)).toBe(false);
41
+ });
42
+
43
+ test('Rejects a signature from another key when no extra keys are configured', () => {
44
+ const signature = signWith(platformKey, ...content);
45
+
46
+ TestUtils.setEnvironment('INTERNAL_SECRET_KEY', rendererKey);
47
+ expect(verifyInternalSignature(signature, ...content)).toBe(false);
48
+ });
49
+
50
+ test('Rejects a valid signature over different content', () => {
51
+ const signature = signWith(rendererKey, ...content);
52
+
53
+ expect(verifyInternalSignature(signature, 'cache-id', '1755500000000', '<html>altered</html>')).toBe(false);
54
+ });
55
+
56
+ test('Rejects a malformed signature without throwing', () => {
57
+ expect(verifyInternalSignature('not-a-valid-signature', ...content)).toBe(false);
58
+ expect(verifyInternalSignature('', ...content)).toBe(false);
59
+ });
60
+ });