Skip to content

Commit 2421487

Browse files
committed
feat(backend): update cloud credential tests for GCP provider
1 parent 696316c commit 2421487

File tree

3 files changed

+108
-105
lines changed

3 files changed

+108
-105
lines changed

services/backend/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = {
22
preset: 'ts-jest',
33
testEnvironment: 'node',
44
testMatch: ['**/tests/e2e/**/*.test.ts'],
5+
testPathIgnorePatterns: ['/node_modules/', '\\._.*'],
56
moduleNameMapper: {
67
'^@src/(.*)$': '<rootDir>/src/$1',
78
},

services/backend/tests/e2e/15-cloud-credentials.e2e.test.ts

Lines changed: 87 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -134,36 +134,38 @@ describe('Cloud Credentials E2E Tests', () => {
134134
expect(response.body.data).toBeInstanceOf(Array);
135135
expect(response.body.data.length).toBeGreaterThan(0);
136136

137-
// Verify AWS provider exists
138-
const awsProvider = response.body.data.find((provider: any) => provider.id === 'aws');
139-
expect(awsProvider).toBeDefined();
140-
expect(awsProvider.name).toBe('Amazon Web Services');
141-
expect(awsProvider.enabled).toBe(true);
142-
expect(awsProvider.fields).toBeInstanceOf(Array);
137+
// Verify GCP provider exists
138+
const gcpProvider = response.body.data.find((provider: any) => provider.id === 'gcp');
139+
expect(gcpProvider).toBeDefined();
140+
expect(gcpProvider.name).toBe('Google Cloud Platform');
141+
expect(gcpProvider.enabled).toBe(true);
142+
expect(gcpProvider.fields).toBeInstanceOf(Array);
143143

144144
// Verify required fields exist
145-
const accessKeyField = awsProvider.fields.find((field: any) => field.key === 'access_key_id');
146-
const secretKeyField = awsProvider.fields.find((field: any) => field.key === 'secret_access_key');
147-
148-
expect(accessKeyField).toBeDefined();
149-
expect(accessKeyField.required).toBe(true);
150-
expect(accessKeyField.secret).toBe(false);
151-
152-
expect(secretKeyField).toBeDefined();
153-
expect(secretKeyField.required).toBe(true);
154-
expect(secretKeyField.secret).toBe(true);
145+
const serviceAccountField = gcpProvider.fields.find((field: any) => field.key === 'service_account_key');
146+
const projectIdField = gcpProvider.fields.find((field: any) => field.key === 'project_id');
147+
148+
expect(serviceAccountField).toBeDefined();
149+
expect(serviceAccountField.required).toBe(true);
150+
expect(serviceAccountField.secret).toBe(true);
151+
expect(serviceAccountField.type).toBe('textarea');
152+
153+
expect(projectIdField).toBeDefined();
154+
expect(projectIdField.required).toBe(true);
155+
expect(projectIdField.secret).toBe(false);
156+
expect(projectIdField.type).toBe('text');
155157
});
156158

157159
it('should create first cloud credential as team admin', async () => {
158160
const context = getTestContext();
159161

160162
const credentialData = {
161-
providerId: 'aws',
162-
name: 'Test AWS Credentials',
163+
providerId: 'gcp',
164+
name: 'Test GCP Credentials',
163165
comment: 'Test credentials for E2E testing',
164166
credentials: {
165-
access_key_id: 'AKIATEST123456789',
166-
secret_access_key: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEYtest123'
167+
service_account_key: '{\n "type": "service_account",\n "project_id": "test-project-123",\n "private_key_id": "test-key-id-123456",\n "private_key": "-----BEGIN PRIVATE KEY-----\\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC7VJT...TEST...\\n-----END PRIVATE KEY-----\\n",\n "client_email": "test-service@test-project-123.iam.gserviceaccount.com",\n "client_id": "123456789012345678901",\n "auth_uri": "https://accounts.google.com/o/oauth2/auth",\n "token_uri": "https://oauth2.googleapis.com/token",\n "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",\n "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/test-service%40test-project-123.iam.gserviceaccount.com"\n}',
168+
project_id: 'test-project-123'
167169
}
168170
};
169171

@@ -180,26 +182,26 @@ describe('Cloud Credentials E2E Tests', () => {
180182
const credential = response.body.data;
181183
expect(credential.id).toBeDefined();
182184
expect(credential.teamId).toBe(context.teamAdminTeamId);
183-
expect(credential.providerId).toBe('aws');
185+
expect(credential.providerId).toBe('gcp');
184186
expect(credential.name).toBe(credentialData.name);
185187
expect(credential.comment).toBe(credentialData.comment);
186188
expect(credential.createdBy).toBe(context.secondUserId);
187189

188190
// Verify provider information
189-
expect(credential.provider.id).toBe('aws');
190-
expect(credential.provider.name).toBe('Amazon Web Services');
191+
expect(credential.provider.id).toBe('gcp');
192+
expect(credential.provider.name).toBe('Google Cloud Platform');
191193

192194
// Verify fields structure - team admin should see non-secret values but no secret values
193195
expect(credential.fields).toBeDefined();
194-
expect(credential.fields.access_key_id).toBeDefined();
195-
expect(credential.fields.access_key_id.hasValue).toBe(true);
196-
expect(credential.fields.access_key_id.secret).toBe(false);
197-
expect(credential.fields.access_key_id.value).toBe('PLACEHOLDER_VALUE'); // Non-secret field shows placeholder
196+
expect(credential.fields.project_id).toBeDefined();
197+
expect(credential.fields.project_id.hasValue).toBe(true);
198+
expect(credential.fields.project_id.secret).toBe(false);
199+
expect(credential.fields.project_id.value).toBe('PLACEHOLDER_VALUE'); // Non-secret field shows placeholder
198200

199-
expect(credential.fields.secret_access_key).toBeDefined();
200-
expect(credential.fields.secret_access_key.hasValue).toBe(true);
201-
expect(credential.fields.secret_access_key.secret).toBe(true);
202-
expect(credential.fields.secret_access_key.value).toBeUndefined(); // Secret field never shows value
201+
expect(credential.fields.service_account_key).toBeDefined();
202+
expect(credential.fields.service_account_key.hasValue).toBe(true);
203+
expect(credential.fields.service_account_key.secret).toBe(true);
204+
expect(credential.fields.service_account_key.value).toBeUndefined(); // Secret field never shows value
203205

204206
// Store credential ID for later tests
205207
updateTestContext({
@@ -211,12 +213,12 @@ describe('Cloud Credentials E2E Tests', () => {
211213
const context = getTestContext();
212214

213215
const credentialData = {
214-
providerId: 'aws',
215-
name: 'Edit Test AWS Credentials',
216+
providerId: 'gcp',
217+
name: 'Edit Test GCP Credentials',
216218
comment: 'Credentials for edit/delete testing',
217219
credentials: {
218-
access_key_id: 'AKIAEDIT123456789',
219-
secret_access_key: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEYedit123'
220+
service_account_key: '{\n "type": "service_account",\n "project_id": "edit-test-project-456",\n "private_key_id": "edit-key-id-456789",\n "private_key": "-----BEGIN PRIVATE KEY-----\\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC7VJT...EDIT...\\n-----END PRIVATE KEY-----\\n",\n "client_email": "edit-service@edit-test-project-456.iam.gserviceaccount.com",\n "client_id": "456789012345678901234",\n "auth_uri": "https://accounts.google.com/o/oauth2/auth",\n "token_uri": "https://oauth2.googleapis.com/token",\n "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",\n "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/edit-service%40edit-test-project-456.iam.gserviceaccount.com"\n}',
221+
project_id: 'edit-test-project-456'
220222
}
221223
};
222224

@@ -243,10 +245,10 @@ describe('Cloud Credentials E2E Tests', () => {
243245
expect(context.editTestCredentialId).not.toBe('undefined');
244246

245247
const updateData = {
246-
name: 'Updated Test AWS Credentials',
248+
name: 'Updated Test GCP Credentials',
247249
comment: 'Updated comment for testing',
248250
credentials: {
249-
access_key_id: 'AKIATEST987654321' // Update non-secret field
251+
project_id: 'updated-test-project-789' // Update non-secret field
250252
}
251253
};
252254

@@ -265,12 +267,12 @@ describe('Cloud Credentials E2E Tests', () => {
265267
expect(credential.comment).toBe(updateData.comment);
266268

267269
// Verify updated field (team admin sees placeholder, not actual value)
268-
expect(credential.fields.access_key_id.value).toBe('PLACEHOLDER_VALUE');
269-
expect(credential.fields.access_key_id.hasValue).toBe(true);
270+
expect(credential.fields.project_id.value).toBe('PLACEHOLDER_VALUE');
271+
expect(credential.fields.project_id.hasValue).toBe(true);
270272

271273
// Verify secret field remains unchanged (still has value but not shown)
272-
expect(credential.fields.secret_access_key.hasValue).toBe(true);
273-
expect(credential.fields.secret_access_key.value).toBeUndefined();
274+
expect(credential.fields.service_account_key.hasValue).toBe(true);
275+
expect(credential.fields.service_account_key.value).toBeUndefined();
274276
});
275277

276278
it('should delete own credential as team admin', async () => {
@@ -297,12 +299,12 @@ describe('Cloud Credentials E2E Tests', () => {
297299

298300
// Create first credential in team admin's team
299301
const credential1Data = {
300-
providerId: 'aws',
301-
name: 'Production AWS',
302+
providerId: 'gcp',
303+
name: 'Production GCP',
302304
comment: 'Production environment credentials',
303305
credentials: {
304-
access_key_id: 'AKIAPROD123456789',
305-
secret_access_key: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEYprod123'
306+
service_account_key: '{\n "type": "service_account",\n "project_id": "prod-project-123",\n "private_key_id": "prod-key-id-123456",\n "private_key": "-----BEGIN PRIVATE KEY-----\\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC7VJT...PROD...\\n-----END PRIVATE KEY-----\\n",\n "client_email": "prod-service@prod-project-123.iam.gserviceaccount.com",\n "client_id": "123456789012345678901",\n "auth_uri": "https://accounts.google.com/o/oauth2/auth",\n "token_uri": "https://oauth2.googleapis.com/token",\n "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",\n "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/prod-service%40prod-project-123.iam.gserviceaccount.com"\n}',
307+
project_id: 'prod-project-123'
306308
}
307309
};
308310

@@ -316,12 +318,12 @@ describe('Cloud Credentials E2E Tests', () => {
316318

317319
// Create second credential in team admin's team
318320
const credential2Data = {
319-
providerId: 'aws',
320-
name: 'Staging AWS',
321+
providerId: 'gcp',
322+
name: 'Staging GCP',
321323
comment: 'Staging environment credentials',
322324
credentials: {
323-
access_key_id: 'AKIASTAGING123456789',
324-
secret_access_key: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEYstag123'
325+
service_account_key: '{\n "type": "service_account",\n "project_id": "staging-project-456",\n "private_key_id": "staging-key-id-456789",\n "private_key": "-----BEGIN PRIVATE KEY-----\\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC7VJT...STAGING...\\n-----END PRIVATE KEY-----\\n",\n "client_email": "staging-service@staging-project-456.iam.gserviceaccount.com",\n "client_id": "456789012345678901234",\n "auth_uri": "https://accounts.google.com/o/oauth2/auth",\n "token_uri": "https://oauth2.googleapis.com/token",\n "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",\n "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/staging-service%40staging-project-456.iam.gserviceaccount.com"\n}',
326+
project_id: 'staging-project-456'
325327
}
326328
};
327329

@@ -358,26 +360,26 @@ describe('Cloud Credentials E2E Tests', () => {
358360
for (const credential of credentials) {
359361
expect(credential.id).toBeDefined();
360362
expect(credential.name).toBeDefined();
361-
expect(credential.providerId).toBe('aws');
363+
expect(credential.providerId).toBe('gcp');
362364
expect(credential.teamId).toBe(context.teamAdminTeamId);
363365
expect(credential.createdBy).toBe(context.secondUserId);
364366

365367
// Global admin should see field metadata but NO values (even for non-secret fields)
366368
expect(credential.fields).toBeDefined();
367-
expect(credential.fields.access_key_id).toBeDefined();
368-
expect(credential.fields.access_key_id.hasValue).toBe(true);
369-
expect(credential.fields.access_key_id.secret).toBe(false);
370-
expect(credential.fields.access_key_id.value).toBeUndefined(); // Global admin sees no values
369+
expect(credential.fields.project_id).toBeDefined();
370+
expect(credential.fields.project_id.hasValue).toBe(true);
371+
expect(credential.fields.project_id.secret).toBe(false);
372+
expect(credential.fields.project_id.value).toBeUndefined(); // Global admin sees no values
371373

372-
expect(credential.fields.secret_access_key).toBeDefined();
373-
expect(credential.fields.secret_access_key.hasValue).toBe(true);
374-
expect(credential.fields.secret_access_key.secret).toBe(true);
375-
expect(credential.fields.secret_access_key.value).toBeUndefined(); // Global admin sees no values
374+
expect(credential.fields.service_account_key).toBeDefined();
375+
expect(credential.fields.service_account_key.hasValue).toBe(true);
376+
expect(credential.fields.service_account_key.secret).toBe(true);
377+
expect(credential.fields.service_account_key.value).toBeUndefined(); // Global admin sees no values
376378
}
377379

378380
// Verify we can find both credentials
379-
const prodCredential = credentials.find((c: any) => c.name === 'Production AWS');
380-
const stagingCredential = credentials.find((c: any) => c.name === 'Staging AWS');
381+
const prodCredential = credentials.find((c: any) => c.name === 'Production GCP');
382+
const stagingCredential = credentials.find((c: any) => c.name === 'Staging GCP');
381383

382384
expect(prodCredential).toBeDefined();
383385
expect(stagingCredential).toBeDefined();
@@ -408,17 +410,17 @@ describe('Cloud Credentials E2E Tests', () => {
408410
expect(response.body.data).toBeDefined();
409411

410412
const credential = response.body.data;
411-
expect(credential.name).toBe('Production AWS');
413+
expect(credential.name).toBe('Production GCP');
412414
expect(credential.comment).toBe('Production environment credentials');
413415

414416
// Verify global admin sees metadata but no actual values
415-
expect(credential.fields.access_key_id.hasValue).toBe(true);
416-
expect(credential.fields.access_key_id.secret).toBe(false);
417-
expect(credential.fields.access_key_id.value).toBeUndefined(); // No value for global admin
417+
expect(credential.fields.project_id.hasValue).toBe(true);
418+
expect(credential.fields.project_id.secret).toBe(false);
419+
expect(credential.fields.project_id.value).toBeUndefined(); // No value for global admin
418420

419-
expect(credential.fields.secret_access_key.hasValue).toBe(true);
420-
expect(credential.fields.secret_access_key.secret).toBe(true);
421-
expect(credential.fields.secret_access_key.value).toBeUndefined(); // No value for global admin
421+
expect(credential.fields.service_account_key.hasValue).toBe(true);
422+
expect(credential.fields.service_account_key.secret).toBe(true);
423+
expect(credential.fields.service_account_key.value).toBeUndefined(); // No value for global admin
422424
});
423425

424426
it('should verify no secret values are ever returned in any response', async () => {
@@ -433,14 +435,14 @@ describe('Cloud Credentials E2E Tests', () => {
433435
const globalAdminCredential = globalAdminResponse.body.data;
434436

435437
// Global admin should see no values at all for other team's credentials
436-
expect(globalAdminCredential.fields.secret_access_key.value).toBeUndefined();
437-
expect(globalAdminCredential.fields.access_key_id.value).toBeUndefined();
438-
expect(globalAdminCredential.fields.secret_access_key.hasValue).toBe(true);
439-
expect(globalAdminCredential.fields.access_key_id.hasValue).toBe(true);
438+
expect(globalAdminCredential.fields.service_account_key.value).toBeUndefined();
439+
expect(globalAdminCredential.fields.project_id.value).toBeUndefined();
440+
expect(globalAdminCredential.fields.service_account_key.hasValue).toBe(true);
441+
expect(globalAdminCredential.fields.project_id.hasValue).toBe(true);
440442

441443
// Verify secret fields are properly marked
442-
expect(globalAdminCredential.fields.secret_access_key.secret).toBe(true);
443-
expect(globalAdminCredential.fields.access_key_id.secret).toBe(false);
444+
expect(globalAdminCredential.fields.service_account_key.secret).toBe(true);
445+
expect(globalAdminCredential.fields.project_id.secret).toBe(false);
444446

445447
// Test as team admin viewing own team's credentials
446448
const teamAdminResponse = await request(server.server)
@@ -451,10 +453,10 @@ describe('Cloud Credentials E2E Tests', () => {
451453
const teamAdminCredential = teamAdminResponse.body.data;
452454

453455
// Team admin should see placeholder for non-secret fields but never secret values
454-
expect(teamAdminCredential.fields.secret_access_key.value).toBeUndefined(); // Secret never shown
455-
expect(teamAdminCredential.fields.access_key_id.value).toBe('PLACEHOLDER_VALUE'); // Non-secret shows placeholder
456-
expect(teamAdminCredential.fields.secret_access_key.hasValue).toBe(true);
457-
expect(teamAdminCredential.fields.access_key_id.hasValue).toBe(true);
456+
expect(teamAdminCredential.fields.service_account_key.value).toBeUndefined(); // Secret never shown
457+
expect(teamAdminCredential.fields.project_id.value).toBe('PLACEHOLDER_VALUE'); // Non-secret shows placeholder
458+
expect(teamAdminCredential.fields.service_account_key.hasValue).toBe(true);
459+
expect(teamAdminCredential.fields.project_id.hasValue).toBe(true);
458460
});
459461

460462
it('should handle validation errors correctly', async () => {
@@ -479,11 +481,11 @@ describe('Cloud Credentials E2E Tests', () => {
479481
.post(`/api/teams/${context.teamAdminTeamId}/cloud-credentials`)
480482
.set('Cookie', context.teamAdminCredentialsCookie!)
481483
.send({
482-
providerId: 'aws',
484+
providerId: 'gcp',
483485
name: 'Test Credential',
484486
credentials: {
485-
access_key_id: 'AKIATEST123456789'
486-
// Missing secret_access_key
487+
project_id: 'test-project-123'
488+
// Missing service_account_key
487489
}
488490
});
489491

@@ -496,15 +498,15 @@ describe('Cloud Credentials E2E Tests', () => {
496498
.post(`/api/teams/${context.teamAdminTeamId}/cloud-credentials`)
497499
.set('Cookie', context.teamAdminCredentialsCookie!)
498500
.send({
499-
providerId: 'aws',
500-
name: 'Production AWS', // Same name as existing credential
501+
providerId: 'gcp',
502+
name: 'Production GCP', // Same name as existing credential
501503
credentials: {
502-
access_key_id: 'AKIATEST123456789',
503-
secret_access_key: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEYdupe123'
504+
service_account_key: '{"type": "service_account", "project_id": "duplicate-test"}',
505+
project_id: 'duplicate-test-project'
504506
}
505507
});
506508

507-
expect(duplicateNameResponse.status).toBe(409);
509+
expect(duplicateNameResponse.status).toBe(400);
508510
expect(duplicateNameResponse.body.success).toBe(false);
509511
expect(duplicateNameResponse.body.error).toBeDefined();
510512
});

0 commit comments

Comments
 (0)