@friggframework/core 2.0.0-next.41 → 2.0.0-next.42
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/CLAUDE.md +693 -0
- package/README.md +931 -50
- package/application/commands/README.md +421 -0
- package/application/commands/credential-commands.js +224 -0
- package/application/commands/entity-commands.js +315 -0
- package/application/commands/integration-commands.js +160 -0
- package/application/commands/integration-commands.test.js +123 -0
- package/application/commands/user-commands.js +213 -0
- package/application/index.js +69 -0
- package/core/CLAUDE.md +690 -0
- package/core/create-handler.js +0 -6
- package/credential/repositories/credential-repository-factory.js +47 -0
- package/credential/repositories/credential-repository-interface.js +98 -0
- package/credential/repositories/credential-repository-mongo.js +301 -0
- package/credential/repositories/credential-repository-postgres.js +307 -0
- package/credential/repositories/credential-repository.js +307 -0
- package/credential/use-cases/get-credential-for-user.js +21 -0
- package/credential/use-cases/update-authentication-status.js +15 -0
- package/database/config.js +117 -0
- package/database/encryption/README.md +683 -0
- package/database/encryption/encryption-integration.test.js +553 -0
- package/database/encryption/encryption-schema-registry.js +141 -0
- package/database/encryption/encryption-schema-registry.test.js +392 -0
- package/database/encryption/field-encryption-service.js +226 -0
- package/database/encryption/field-encryption-service.test.js +525 -0
- package/database/encryption/logger.js +79 -0
- package/database/encryption/mongo-decryption-fix-verification.test.js +348 -0
- package/database/encryption/postgres-decryption-fix-verification.test.js +371 -0
- package/database/encryption/postgres-relation-decryption.test.js +245 -0
- package/database/encryption/prisma-encryption-extension.js +222 -0
- package/database/encryption/prisma-encryption-extension.test.js +439 -0
- package/database/index.js +25 -12
- package/database/models/readme.md +1 -0
- package/database/prisma.js +162 -0
- package/database/repositories/health-check-repository-factory.js +38 -0
- package/database/repositories/health-check-repository-interface.js +86 -0
- package/database/repositories/health-check-repository-mongodb.js +72 -0
- package/database/repositories/health-check-repository-postgres.js +75 -0
- package/database/repositories/health-check-repository.js +108 -0
- package/database/use-cases/check-database-health-use-case.js +34 -0
- package/database/use-cases/check-encryption-health-use-case.js +82 -0
- package/database/use-cases/test-encryption-use-case.js +252 -0
- package/encrypt/Cryptor.js +20 -152
- package/encrypt/index.js +1 -2
- package/encrypt/test-encrypt.js +0 -2
- package/handlers/app-definition-loader.js +38 -0
- package/handlers/app-handler-helpers.js +0 -3
- package/handlers/auth-flow.integration.test.js +147 -0
- package/handlers/backend-utils.js +25 -45
- package/handlers/integration-event-dispatcher.js +54 -0
- package/handlers/integration-event-dispatcher.test.js +141 -0
- package/handlers/routers/HEALTHCHECK.md +103 -1
- package/handlers/routers/auth.js +3 -14
- package/handlers/routers/health.js +63 -424
- package/handlers/routers/health.test.js +7 -0
- package/handlers/routers/integration-defined-routers.js +8 -5
- package/handlers/routers/user.js +25 -5
- package/handlers/routers/websocket.js +5 -3
- package/handlers/use-cases/check-external-apis-health-use-case.js +81 -0
- package/handlers/use-cases/check-integrations-health-use-case.js +32 -0
- package/handlers/workers/integration-defined-workers.js +6 -3
- package/index.js +45 -22
- package/integrations/index.js +12 -10
- package/integrations/integration-base.js +224 -53
- package/integrations/integration-router.js +386 -178
- package/integrations/options.js +1 -1
- package/integrations/repositories/integration-mapping-repository-factory.js +50 -0
- package/integrations/repositories/integration-mapping-repository-interface.js +106 -0
- package/integrations/repositories/integration-mapping-repository-mongo.js +161 -0
- package/integrations/repositories/integration-mapping-repository-postgres.js +227 -0
- package/integrations/repositories/integration-mapping-repository.js +156 -0
- package/integrations/repositories/integration-repository-factory.js +44 -0
- package/integrations/repositories/integration-repository-interface.js +115 -0
- package/integrations/repositories/integration-repository-mongo.js +271 -0
- package/integrations/repositories/integration-repository-postgres.js +319 -0
- package/integrations/tests/doubles/dummy-integration-class.js +90 -0
- package/integrations/tests/doubles/test-integration-repository.js +99 -0
- package/integrations/tests/use-cases/create-integration.test.js +131 -0
- package/integrations/tests/use-cases/delete-integration-for-user.test.js +150 -0
- package/integrations/tests/use-cases/find-integration-context-by-external-entity-id.test.js +92 -0
- package/integrations/tests/use-cases/get-integration-for-user.test.js +150 -0
- package/integrations/tests/use-cases/get-integration-instance.test.js +176 -0
- package/integrations/tests/use-cases/get-integrations-for-user.test.js +176 -0
- package/integrations/tests/use-cases/get-possible-integrations.test.js +188 -0
- package/integrations/tests/use-cases/update-integration-messages.test.js +142 -0
- package/integrations/tests/use-cases/update-integration-status.test.js +103 -0
- package/integrations/tests/use-cases/update-integration.test.js +141 -0
- package/integrations/use-cases/create-integration.js +83 -0
- package/integrations/use-cases/delete-integration-for-user.js +73 -0
- package/integrations/use-cases/find-integration-context-by-external-entity-id.js +72 -0
- package/integrations/use-cases/get-integration-for-user.js +78 -0
- package/integrations/use-cases/get-integration-instance-by-definition.js +67 -0
- package/integrations/use-cases/get-integration-instance.js +83 -0
- package/integrations/use-cases/get-integrations-for-user.js +87 -0
- package/integrations/use-cases/get-possible-integrations.js +27 -0
- package/integrations/use-cases/index.js +11 -0
- package/integrations/use-cases/load-integration-context-full.test.js +329 -0
- package/integrations/use-cases/load-integration-context.js +71 -0
- package/integrations/use-cases/load-integration-context.test.js +114 -0
- package/integrations/use-cases/update-integration-messages.js +44 -0
- package/integrations/use-cases/update-integration-status.js +32 -0
- package/integrations/use-cases/update-integration.js +93 -0
- package/integrations/utils/map-integration-dto.js +36 -0
- package/jest-global-setup-noop.js +3 -0
- package/jest-global-teardown-noop.js +3 -0
- package/{module-plugin → modules}/entity.js +1 -0
- package/{module-plugin → modules}/index.js +0 -8
- package/modules/module-factory.js +56 -0
- package/modules/module-hydration.test.js +205 -0
- package/modules/module.js +221 -0
- package/modules/repositories/module-repository-factory.js +33 -0
- package/modules/repositories/module-repository-interface.js +129 -0
- package/modules/repositories/module-repository-mongo.js +386 -0
- package/modules/repositories/module-repository-postgres.js +437 -0
- package/modules/repositories/module-repository.js +327 -0
- package/{module-plugin → modules}/test/mock-api/api.js +8 -3
- package/{module-plugin → modules}/test/mock-api/definition.js +12 -8
- package/modules/tests/doubles/test-module-factory.js +16 -0
- package/modules/tests/doubles/test-module-repository.js +39 -0
- package/modules/use-cases/get-entities-for-user.js +32 -0
- package/modules/use-cases/get-entity-options-by-id.js +59 -0
- package/modules/use-cases/get-entity-options-by-type.js +34 -0
- package/modules/use-cases/get-module-instance-from-type.js +31 -0
- package/modules/use-cases/get-module.js +56 -0
- package/modules/use-cases/process-authorization-callback.js +121 -0
- package/modules/use-cases/refresh-entity-options.js +59 -0
- package/modules/use-cases/test-module-auth.js +55 -0
- package/modules/utils/map-module-dto.js +18 -0
- package/package.json +14 -6
- package/prisma-mongodb/schema.prisma +321 -0
- package/prisma-postgresql/migrations/20250930193005_init/migration.sql +315 -0
- package/prisma-postgresql/migrations/20251006135218_init/migration.sql +9 -0
- package/prisma-postgresql/migrations/migration_lock.toml +3 -0
- package/prisma-postgresql/schema.prisma +303 -0
- package/syncs/manager.js +468 -443
- package/syncs/repositories/sync-repository-factory.js +38 -0
- package/syncs/repositories/sync-repository-interface.js +109 -0
- package/syncs/repositories/sync-repository-mongo.js +239 -0
- package/syncs/repositories/sync-repository-postgres.js +319 -0
- package/syncs/sync.js +0 -1
- package/token/repositories/token-repository-factory.js +33 -0
- package/token/repositories/token-repository-interface.js +131 -0
- package/token/repositories/token-repository-mongo.js +212 -0
- package/token/repositories/token-repository-postgres.js +257 -0
- package/token/repositories/token-repository.js +219 -0
- package/types/integrations/index.d.ts +2 -6
- package/types/module-plugin/index.d.ts +5 -57
- package/types/syncs/index.d.ts +0 -2
- package/user/repositories/user-repository-factory.js +46 -0
- package/user/repositories/user-repository-interface.js +198 -0
- package/user/repositories/user-repository-mongo.js +250 -0
- package/user/repositories/user-repository-postgres.js +311 -0
- package/user/tests/doubles/test-user-repository.js +72 -0
- package/user/tests/use-cases/create-individual-user.test.js +24 -0
- package/user/tests/use-cases/create-organization-user.test.js +28 -0
- package/user/tests/use-cases/create-token-for-user-id.test.js +19 -0
- package/user/tests/use-cases/get-user-from-bearer-token.test.js +64 -0
- package/user/tests/use-cases/login-user.test.js +140 -0
- package/user/use-cases/create-individual-user.js +61 -0
- package/user/use-cases/create-organization-user.js +47 -0
- package/user/use-cases/create-token-for-user-id.js +30 -0
- package/user/use-cases/get-user-from-bearer-token.js +77 -0
- package/user/use-cases/login-user.js +122 -0
- package/user/user.js +77 -0
- package/websocket/repositories/websocket-connection-repository-factory.js +37 -0
- package/websocket/repositories/websocket-connection-repository-interface.js +106 -0
- package/websocket/repositories/websocket-connection-repository-mongo.js +155 -0
- package/websocket/repositories/websocket-connection-repository-postgres.js +195 -0
- package/websocket/repositories/websocket-connection-repository.js +160 -0
- package/database/models/State.js +0 -9
- package/database/models/Token.js +0 -70
- package/database/mongo.js +0 -171
- package/encrypt/Cryptor.test.js +0 -32
- package/encrypt/encrypt.js +0 -104
- package/encrypt/encrypt.test.js +0 -1069
- package/handlers/routers/middleware/loadUser.js +0 -15
- package/handlers/routers/middleware/requireLoggedInUser.js +0 -12
- package/integrations/create-frigg-backend.js +0 -31
- package/integrations/integration-factory.js +0 -251
- package/integrations/integration-mapping.js +0 -43
- package/integrations/integration-model.js +0 -46
- package/integrations/integration-user.js +0 -144
- package/integrations/test/integration-base.test.js +0 -144
- package/module-plugin/auther.js +0 -393
- package/module-plugin/credential.js +0 -22
- package/module-plugin/entity-manager.js +0 -70
- package/module-plugin/manager.js +0 -169
- package/module-plugin/module-factory.js +0 -61
- package/module-plugin/test/auther.test.js +0 -97
- /package/{module-plugin → modules}/ModuleConstants.js +0 -0
- /package/{module-plugin → modules}/requester/api-key.js +0 -0
- /package/{module-plugin → modules}/requester/basic.js +0 -0
- /package/{module-plugin → modules}/requester/oauth-2.js +0 -0
- /package/{module-plugin → modules}/requester/requester.js +0 -0
- /package/{module-plugin → modules}/requester/requester.test.js +0 -0
- /package/{module-plugin → modules}/test/mock-api/mocks/hubspot.js +0 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verification Test: Repository Fix for MongoDB Decryption Bug
|
|
3
|
+
*
|
|
4
|
+
* This test verifies that the fix in ModuleRepositoryMongo successfully
|
|
5
|
+
* decrypts credentials when fetching entities (after removing `include`).
|
|
6
|
+
*
|
|
7
|
+
* Expected Behavior After Fix:
|
|
8
|
+
* - All repository methods should return decrypted credentials
|
|
9
|
+
* - No encrypted tokens should leak through to the application layer
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
process.env.DB_TYPE = 'mongodb';
|
|
13
|
+
process.env.DATABASE_URL = process.env.DATABASE_URL || 'mongodb://localhost:27017/frigg?replicaSet=rs0';
|
|
14
|
+
process.env.STAGE = 'integration-test';
|
|
15
|
+
process.env.AES_KEY_ID = 'test-key-id';
|
|
16
|
+
process.env.AES_KEY = 'test-aes-key-32-characters-long!';
|
|
17
|
+
|
|
18
|
+
jest.mock('../config', () => ({
|
|
19
|
+
DB_TYPE: 'mongodb',
|
|
20
|
+
getDatabaseType: jest.fn(() => 'mongodb'),
|
|
21
|
+
PRISMA_LOG_LEVEL: 'error,warn',
|
|
22
|
+
PRISMA_QUERY_LOGGING: false,
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
const { prisma, connectPrisma, disconnectPrisma } = require('../prisma');
|
|
26
|
+
const { ModuleRepositoryMongo } = require('../../modules/repositories/module-repository-mongo');
|
|
27
|
+
|
|
28
|
+
describe('Repository Fix Verification - MongoDB Decryption', () => {
|
|
29
|
+
let repository;
|
|
30
|
+
let testCredentialId;
|
|
31
|
+
let testEntityId;
|
|
32
|
+
let testUserId;
|
|
33
|
+
const TEST_TOKEN = 'my-secret-access-token-12345';
|
|
34
|
+
const TEST_REFRESH_TOKEN = 'my-secret-refresh-token-67890';
|
|
35
|
+
const TEST_DOMAIN = 'example-test.com';
|
|
36
|
+
|
|
37
|
+
beforeAll(async () => {
|
|
38
|
+
await connectPrisma();
|
|
39
|
+
repository = new ModuleRepositoryMongo();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
afterAll(async () => {
|
|
43
|
+
if (testEntityId) {
|
|
44
|
+
await prisma.entity.deleteMany({
|
|
45
|
+
where: { id: testEntityId }
|
|
46
|
+
}).catch(() => {});
|
|
47
|
+
}
|
|
48
|
+
if (testCredentialId) {
|
|
49
|
+
await prisma.credential.deleteMany({
|
|
50
|
+
where: { id: testCredentialId }
|
|
51
|
+
}).catch(() => {});
|
|
52
|
+
}
|
|
53
|
+
if (testUserId) {
|
|
54
|
+
await prisma.user.deleteMany({
|
|
55
|
+
where: { id: testUserId }
|
|
56
|
+
}).catch(() => {});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
await disconnectPrisma();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
afterEach(async () => {
|
|
63
|
+
if (testEntityId) {
|
|
64
|
+
await prisma.entity.deleteMany({
|
|
65
|
+
where: { id: testEntityId }
|
|
66
|
+
}).catch(() => {});
|
|
67
|
+
testEntityId = null;
|
|
68
|
+
}
|
|
69
|
+
if (testCredentialId) {
|
|
70
|
+
await prisma.credential.deleteMany({
|
|
71
|
+
where: { id: testCredentialId }
|
|
72
|
+
}).catch(() => {});
|
|
73
|
+
testCredentialId = null;
|
|
74
|
+
}
|
|
75
|
+
if (testUserId) {
|
|
76
|
+
await prisma.user.deleteMany({
|
|
77
|
+
where: { id: testUserId }
|
|
78
|
+
}).catch(() => {});
|
|
79
|
+
testUserId = null;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('✅ FIX VERIFICATION: findEntityById returns decrypted credential', async () => {
|
|
84
|
+
const user = await prisma.user.create({
|
|
85
|
+
data: {
|
|
86
|
+
type: 'INDIVIDUAL',
|
|
87
|
+
hashword: 'test-hash'
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
testUserId = user.id;
|
|
91
|
+
|
|
92
|
+
const credential = await prisma.credential.create({
|
|
93
|
+
data: {
|
|
94
|
+
userId: testUserId,
|
|
95
|
+
externalId: 'test-cred-findEntityById',
|
|
96
|
+
data: {
|
|
97
|
+
access_token: TEST_TOKEN,
|
|
98
|
+
refresh_token: TEST_REFRESH_TOKEN,
|
|
99
|
+
domain: TEST_DOMAIN,
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
testCredentialId = credential.id;
|
|
104
|
+
|
|
105
|
+
const entity = await prisma.entity.create({
|
|
106
|
+
data: {
|
|
107
|
+
userId: testUserId,
|
|
108
|
+
credentialId: testCredentialId,
|
|
109
|
+
moduleName: 'test-module',
|
|
110
|
+
externalId: 'test-entity-findById',
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
testEntityId = entity.id;
|
|
114
|
+
|
|
115
|
+
const result = await repository.findEntityById(testEntityId);
|
|
116
|
+
|
|
117
|
+
expect(result).toBeDefined();
|
|
118
|
+
expect(result.credential).toBeDefined();
|
|
119
|
+
expect(result.credential.data.access_token).toBe(TEST_TOKEN);
|
|
120
|
+
expect(result.credential.data.refresh_token).toBe(TEST_REFRESH_TOKEN);
|
|
121
|
+
expect(result.credential.data.domain).toBe(TEST_DOMAIN);
|
|
122
|
+
|
|
123
|
+
expect(result.credential.data.access_token).not.toContain(':');
|
|
124
|
+
|
|
125
|
+
console.log('✅ findEntityById: Credential successfully decrypted!');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('✅ FIX VERIFICATION: findEntitiesByUserId returns decrypted credentials', async () => {
|
|
129
|
+
const user = await prisma.user.create({
|
|
130
|
+
data: {
|
|
131
|
+
type: 'INDIVIDUAL',
|
|
132
|
+
hashword: 'test-hash'
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
testUserId = user.id;
|
|
136
|
+
|
|
137
|
+
const credential = await prisma.credential.create({
|
|
138
|
+
data: {
|
|
139
|
+
userId: testUserId,
|
|
140
|
+
externalId: 'test-cred-findByUserId',
|
|
141
|
+
data: {
|
|
142
|
+
access_token: TEST_TOKEN,
|
|
143
|
+
domain: TEST_DOMAIN,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
testCredentialId = credential.id;
|
|
148
|
+
|
|
149
|
+
const entity = await prisma.entity.create({
|
|
150
|
+
data: {
|
|
151
|
+
userId: testUserId,
|
|
152
|
+
credentialId: testCredentialId,
|
|
153
|
+
moduleName: 'test-module',
|
|
154
|
+
externalId: 'test-entity-findByUserId',
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
testEntityId = entity.id;
|
|
158
|
+
|
|
159
|
+
const results = await repository.findEntitiesByUserId(testUserId);
|
|
160
|
+
|
|
161
|
+
expect(results).toBeDefined();
|
|
162
|
+
expect(results.length).toBeGreaterThan(0);
|
|
163
|
+
const firstEntity = results[0];
|
|
164
|
+
expect(firstEntity.credential).toBeDefined();
|
|
165
|
+
expect(firstEntity.credential.data.access_token).toBe(TEST_TOKEN);
|
|
166
|
+
expect(firstEntity.credential.data.access_token).not.toContain(':');
|
|
167
|
+
|
|
168
|
+
console.log('✅ findEntitiesByUserId: Credentials successfully decrypted!');
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('✅ FIX VERIFICATION: findEntitiesByIds returns decrypted credentials', async () => {
|
|
172
|
+
const user = await prisma.user.create({
|
|
173
|
+
data: {
|
|
174
|
+
type: 'INDIVIDUAL',
|
|
175
|
+
hashword: 'test-hash'
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
testUserId = user.id;
|
|
179
|
+
|
|
180
|
+
const credential = await prisma.credential.create({
|
|
181
|
+
data: {
|
|
182
|
+
userId: testUserId,
|
|
183
|
+
externalId: 'test-cred-findByIds',
|
|
184
|
+
data: {
|
|
185
|
+
access_token: TEST_TOKEN,
|
|
186
|
+
domain: TEST_DOMAIN,
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
testCredentialId = credential.id;
|
|
191
|
+
|
|
192
|
+
const entity = await prisma.entity.create({
|
|
193
|
+
data: {
|
|
194
|
+
userId: testUserId,
|
|
195
|
+
credentialId: testCredentialId,
|
|
196
|
+
moduleName: 'test-module',
|
|
197
|
+
externalId: 'test-entity-findByIds',
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
testEntityId = entity.id;
|
|
201
|
+
|
|
202
|
+
const results = await repository.findEntitiesByIds([testEntityId]);
|
|
203
|
+
|
|
204
|
+
expect(results).toBeDefined();
|
|
205
|
+
expect(results.length).toBe(1);
|
|
206
|
+
expect(results[0].credential).toBeDefined();
|
|
207
|
+
expect(results[0].credential.data.access_token).toBe(TEST_TOKEN);
|
|
208
|
+
expect(results[0].credential.data.access_token).not.toContain(':');
|
|
209
|
+
|
|
210
|
+
console.log('✅ findEntitiesByIds: Credentials successfully decrypted!');
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test('✅ FIX VERIFICATION: createEntity returns decrypted credential', async () => {
|
|
214
|
+
const user = await prisma.user.create({
|
|
215
|
+
data: {
|
|
216
|
+
type: 'INDIVIDUAL',
|
|
217
|
+
hashword: 'test-hash'
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
testUserId = user.id;
|
|
221
|
+
|
|
222
|
+
const credential = await prisma.credential.create({
|
|
223
|
+
data: {
|
|
224
|
+
userId: testUserId,
|
|
225
|
+
externalId: 'test-cred-create',
|
|
226
|
+
data: {
|
|
227
|
+
access_token: TEST_TOKEN,
|
|
228
|
+
domain: TEST_DOMAIN,
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
testCredentialId = credential.id;
|
|
233
|
+
|
|
234
|
+
const entity = await repository.createEntity({
|
|
235
|
+
userId: testUserId,
|
|
236
|
+
credentialId: testCredentialId,
|
|
237
|
+
moduleName: 'test-module',
|
|
238
|
+
externalId: 'test-entity-create',
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
testEntityId = entity.id;
|
|
242
|
+
|
|
243
|
+
expect(entity).toBeDefined();
|
|
244
|
+
expect(entity.credential).toBeDefined();
|
|
245
|
+
expect(entity.credential.data.access_token).toBe(TEST_TOKEN);
|
|
246
|
+
expect(entity.credential.data.access_token).not.toContain(':');
|
|
247
|
+
|
|
248
|
+
console.log('✅ createEntity: Credential successfully decrypted!');
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test('✅ FIX VERIFICATION: updateEntity returns decrypted credential', async () => {
|
|
252
|
+
const user = await prisma.user.create({
|
|
253
|
+
data: {
|
|
254
|
+
type: 'INDIVIDUAL',
|
|
255
|
+
hashword: 'test-hash'
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
testUserId = user.id;
|
|
259
|
+
|
|
260
|
+
const credential = await prisma.credential.create({
|
|
261
|
+
data: {
|
|
262
|
+
userId: testUserId,
|
|
263
|
+
externalId: 'test-cred-update',
|
|
264
|
+
data: {
|
|
265
|
+
access_token: TEST_TOKEN,
|
|
266
|
+
domain: TEST_DOMAIN,
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
testCredentialId = credential.id;
|
|
271
|
+
|
|
272
|
+
const entity = await prisma.entity.create({
|
|
273
|
+
data: {
|
|
274
|
+
userId: testUserId,
|
|
275
|
+
credentialId: testCredentialId,
|
|
276
|
+
moduleName: 'test-module',
|
|
277
|
+
externalId: 'test-entity-update',
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
testEntityId = entity.id;
|
|
281
|
+
|
|
282
|
+
const updated = await repository.updateEntity(testEntityId, {
|
|
283
|
+
name: 'Updated Name',
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
expect(updated).toBeDefined();
|
|
287
|
+
expect(updated.name).toBe('Updated Name');
|
|
288
|
+
expect(updated.credential).toBeDefined();
|
|
289
|
+
expect(updated.credential.data.access_token).toBe(TEST_TOKEN);
|
|
290
|
+
expect(updated.credential.data.access_token).not.toContain(':');
|
|
291
|
+
|
|
292
|
+
console.log('✅ updateEntity: Credential successfully decrypted!');
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test('📊 COMPARISON: Verify tokens are encrypted in database but decrypted in repository', async () => {
|
|
296
|
+
const user = await prisma.user.create({
|
|
297
|
+
data: {
|
|
298
|
+
type: 'INDIVIDUAL',
|
|
299
|
+
hashword: 'test-hash'
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
testUserId = user.id;
|
|
303
|
+
|
|
304
|
+
const credential = await prisma.credential.create({
|
|
305
|
+
data: {
|
|
306
|
+
userId: testUserId,
|
|
307
|
+
externalId: 'test-cred-comparison',
|
|
308
|
+
data: {
|
|
309
|
+
access_token: TEST_TOKEN,
|
|
310
|
+
domain: TEST_DOMAIN,
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
testCredentialId = credential.id;
|
|
315
|
+
|
|
316
|
+
const entity = await prisma.entity.create({
|
|
317
|
+
data: {
|
|
318
|
+
userId: testUserId,
|
|
319
|
+
credentialId: testCredentialId,
|
|
320
|
+
moduleName: 'test-module',
|
|
321
|
+
externalId: 'test-entity-comparison',
|
|
322
|
+
},
|
|
323
|
+
});
|
|
324
|
+
testEntityId = entity.id;
|
|
325
|
+
|
|
326
|
+
const rawCred = await prisma.$runCommandRaw({
|
|
327
|
+
find: 'Credential',
|
|
328
|
+
filter: { _id: { $oid: testCredentialId } }
|
|
329
|
+
});
|
|
330
|
+
const rawDoc = rawCred.cursor.firstBatch[0];
|
|
331
|
+
const rawToken = rawDoc.data.access_token;
|
|
332
|
+
|
|
333
|
+
const repoEntity = await repository.findEntityById(testEntityId);
|
|
334
|
+
const repoToken = repoEntity.credential.data.access_token;
|
|
335
|
+
|
|
336
|
+
console.log('\n📊 COMPARISON RESULTS:');
|
|
337
|
+
console.log('Raw DB token (encrypted):', rawToken.substring(0, 50) + '...');
|
|
338
|
+
console.log('Repository token (decrypted):', repoToken);
|
|
339
|
+
|
|
340
|
+
expect(rawToken).toContain(':');
|
|
341
|
+
expect(rawToken.split(':')).toHaveLength(4);
|
|
342
|
+
|
|
343
|
+
expect(repoToken).toBe(TEST_TOKEN);
|
|
344
|
+
expect(repoToken).not.toContain(':');
|
|
345
|
+
|
|
346
|
+
console.log('✅ Database stores encrypted, repository returns decrypted - FIX WORKS!');
|
|
347
|
+
});
|
|
348
|
+
});
|