@friggframework/core 2.0.0--canary.461.d9e41f3.0 → 2.0.0--canary.461.4166d53.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.
|
@@ -66,8 +66,9 @@ class CheckEncryptionHealthUseCase {
|
|
|
66
66
|
|
|
67
67
|
const isBypassed = bypassStages.includes(STAGE);
|
|
68
68
|
const hasAES = AES_KEY_ID && AES_KEY_ID.trim() !== '';
|
|
69
|
-
const hasKMS = KMS_KEY_ARN && KMS_KEY_ARN.trim() !== ''
|
|
70
|
-
|
|
69
|
+
const hasKMS = KMS_KEY_ARN && KMS_KEY_ARN.trim() !== '';
|
|
70
|
+
// Prefer KMS over AES when both are configured (KMS is more secure)
|
|
71
|
+
const mode = hasKMS ? 'kms' : hasAES ? 'aes' : 'none';
|
|
71
72
|
|
|
72
73
|
return {
|
|
73
74
|
stage: STAGE || null,
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for CheckEncryptionHealthUseCase
|
|
3
|
+
*
|
|
4
|
+
* Tests encryption configuration detection and health checking
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { CheckEncryptionHealthUseCase } = require('./check-encryption-health-use-case');
|
|
8
|
+
|
|
9
|
+
describe('CheckEncryptionHealthUseCase', () => {
|
|
10
|
+
let originalEnv;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
// Save original env
|
|
14
|
+
originalEnv = { ...process.env };
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
// Restore original env
|
|
19
|
+
process.env = originalEnv;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('_getEncryptionConfiguration()', () => {
|
|
23
|
+
it('should prefer KMS over AES when both are configured', async () => {
|
|
24
|
+
process.env.STAGE = 'production';
|
|
25
|
+
process.env.KMS_KEY_ARN = 'arn:aws:kms:us-east-1:123:key/abc';
|
|
26
|
+
process.env.AES_KEY_ID = 'aes-key-123';
|
|
27
|
+
process.env.AES_KEY = 'some-aes-key';
|
|
28
|
+
|
|
29
|
+
const mockTestEncryption = {
|
|
30
|
+
execute: jest.fn().mockResolvedValue({ success: true }),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const useCase = new CheckEncryptionHealthUseCase({
|
|
34
|
+
testEncryptionUseCase: mockTestEncryption,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const result = await useCase.execute();
|
|
38
|
+
|
|
39
|
+
expect(result.mode).toBe('kms'); // KMS should be preferred over AES
|
|
40
|
+
expect(result.debug.hasKMS).toBe(true);
|
|
41
|
+
expect(result.debug.hasAES).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should use AES when only AES is configured', async () => {
|
|
45
|
+
process.env.STAGE = 'production';
|
|
46
|
+
process.env.AES_KEY_ID = 'aes-key-123';
|
|
47
|
+
process.env.AES_KEY = 'some-aes-key';
|
|
48
|
+
delete process.env.KMS_KEY_ARN;
|
|
49
|
+
|
|
50
|
+
const mockTestEncryption = {
|
|
51
|
+
execute: jest.fn().mockResolvedValue({ status: 'healthy', encryptionWorks: true }),
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const useCase = new CheckEncryptionHealthUseCase({
|
|
55
|
+
testEncryptionUseCase: mockTestEncryption,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const result = await useCase.execute();
|
|
59
|
+
|
|
60
|
+
expect(result.mode).toBe('aes');
|
|
61
|
+
expect(result.status).toBe('healthy');
|
|
62
|
+
expect(result.encryptionWorks).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should use KMS when only KMS is configured', async () => {
|
|
66
|
+
process.env.STAGE = 'production';
|
|
67
|
+
process.env.KMS_KEY_ARN = 'arn:aws:kms:us-east-1:123:key/abc';
|
|
68
|
+
delete process.env.AES_KEY_ID;
|
|
69
|
+
delete process.env.AES_KEY;
|
|
70
|
+
|
|
71
|
+
const mockTestEncryption = {
|
|
72
|
+
execute: jest.fn().mockResolvedValue({ status: 'healthy', encryptionWorks: true }),
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const useCase = new CheckEncryptionHealthUseCase({
|
|
76
|
+
testEncryptionUseCase: mockTestEncryption,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const result = await useCase.execute();
|
|
80
|
+
|
|
81
|
+
expect(result.mode).toBe('kms');
|
|
82
|
+
expect(result.status).toBe('healthy');
|
|
83
|
+
expect(result.encryptionWorks).toBe(true);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('should bypass encryption for dev stage', async () => {
|
|
87
|
+
process.env.STAGE = 'dev';
|
|
88
|
+
process.env.KMS_KEY_ARN = 'arn:aws:kms:us-east-1:123:key/abc';
|
|
89
|
+
|
|
90
|
+
const useCase = new CheckEncryptionHealthUseCase({
|
|
91
|
+
testEncryptionUseCase: { execute: jest.fn() },
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const result = await useCase.execute();
|
|
95
|
+
|
|
96
|
+
expect(result.bypassed).toBe(true);
|
|
97
|
+
expect(result.stage).toBe('dev');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('should not bypass encryption for production stage', async () => {
|
|
101
|
+
process.env.STAGE = 'production';
|
|
102
|
+
process.env.KMS_KEY_ARN = 'arn:aws:kms:us-east-1:123:key/abc';
|
|
103
|
+
|
|
104
|
+
const mockTestEncryption = {
|
|
105
|
+
execute: jest.fn().mockResolvedValue({ success: true }),
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const useCase = new CheckEncryptionHealthUseCase({
|
|
109
|
+
testEncryptionUseCase: mockTestEncryption,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const result = await useCase.execute();
|
|
113
|
+
|
|
114
|
+
expect(result.bypassed).toBe(false);
|
|
115
|
+
expect(result.stage).toBe('production');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should use qa stage correctly (not in bypass list)', async () => {
|
|
119
|
+
process.env.STAGE = 'qa';
|
|
120
|
+
process.env.KMS_KEY_ARN = 'arn:aws:kms:us-east-1:123:key/abc';
|
|
121
|
+
|
|
122
|
+
const mockTestEncryption = {
|
|
123
|
+
execute: jest.fn().mockResolvedValue({ success: true }),
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const useCase = new CheckEncryptionHealthUseCase({
|
|
127
|
+
testEncryptionUseCase: mockTestEncryption,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const result = await useCase.execute();
|
|
131
|
+
|
|
132
|
+
expect(result.bypassed).toBe(false);
|
|
133
|
+
expect(result.stage).toBe('qa');
|
|
134
|
+
expect(result.mode).toBe('kms');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('should return mode none when no encryption keys configured', async () => {
|
|
138
|
+
process.env.STAGE = 'production';
|
|
139
|
+
delete process.env.KMS_KEY_ARN;
|
|
140
|
+
delete process.env.AES_KEY_ID;
|
|
141
|
+
delete process.env.AES_KEY;
|
|
142
|
+
|
|
143
|
+
const useCase = new CheckEncryptionHealthUseCase({
|
|
144
|
+
testEncryptionUseCase: { execute: jest.fn() },
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const result = await useCase.execute();
|
|
148
|
+
|
|
149
|
+
expect(result.status).toBe('disabled');
|
|
150
|
+
expect(result.mode).toBe('none');
|
|
151
|
+
expect(result.bypassed).toBe(false);
|
|
152
|
+
expect(result.testResult).toBe('No encryption keys configured');
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe('execute() - bypass scenarios', () => {
|
|
157
|
+
it('should return disabled status when encryption is bypassed', async () => {
|
|
158
|
+
process.env.STAGE = 'dev';
|
|
159
|
+
process.env.KMS_KEY_ARN = 'arn:aws:kms:us-east-1:123:key/abc';
|
|
160
|
+
|
|
161
|
+
const useCase = new CheckEncryptionHealthUseCase({
|
|
162
|
+
testEncryptionUseCase: { execute: jest.fn() },
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const result = await useCase.execute();
|
|
166
|
+
|
|
167
|
+
expect(result.status).toBe('disabled');
|
|
168
|
+
expect(result.bypassed).toBe(true);
|
|
169
|
+
expect(result.stage).toBe('dev');
|
|
170
|
+
expect(result.testResult).toBe('Encryption bypassed for this stage');
|
|
171
|
+
expect(result.encryptionWorks).toBe(false);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('should return disabled status when no encryption keys configured', async () => {
|
|
175
|
+
process.env.STAGE = 'production';
|
|
176
|
+
delete process.env.KMS_KEY_ARN;
|
|
177
|
+
delete process.env.AES_KEY_ID;
|
|
178
|
+
|
|
179
|
+
const useCase = new CheckEncryptionHealthUseCase({
|
|
180
|
+
testEncryptionUseCase: { execute: jest.fn() },
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const result = await useCase.execute();
|
|
184
|
+
|
|
185
|
+
expect(result.status).toBe('disabled');
|
|
186
|
+
expect(result.bypassed).toBe(false);
|
|
187
|
+
expect(result.mode).toBe('none');
|
|
188
|
+
expect(result.testResult).toBe('No encryption keys configured');
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/core",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "2.0.0--canary.461.
|
|
4
|
+
"version": "2.0.0--canary.461.4166d53.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
|
|
7
7
|
"@aws-sdk/client-kms": "^3.588.0",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@friggframework/eslint-config": "2.0.0--canary.461.
|
|
41
|
-
"@friggframework/prettier-config": "2.0.0--canary.461.
|
|
42
|
-
"@friggframework/test": "2.0.0--canary.461.
|
|
40
|
+
"@friggframework/eslint-config": "2.0.0--canary.461.4166d53.0",
|
|
41
|
+
"@friggframework/prettier-config": "2.0.0--canary.461.4166d53.0",
|
|
42
|
+
"@friggframework/test": "2.0.0--canary.461.4166d53.0",
|
|
43
43
|
"@prisma/client": "^6.17.0",
|
|
44
44
|
"@types/lodash": "4.17.15",
|
|
45
45
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
"publishConfig": {
|
|
80
80
|
"access": "public"
|
|
81
81
|
},
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "4166d530b765f85965bdaa77cd4341e8d6e2c12f"
|
|
83
83
|
}
|