Skip to content

Commit 256e061

Browse files
authored
tests: enable keychain on ci for linux COMPASS-6119 (#5214)
1 parent d5eb2f2 commit 256e061

File tree

8 files changed

+31
-97
lines changed

8 files changed

+31
-97
lines changed

.evergreen/functions.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ variables:
2323
- &compass-env
2424
WORKDIR: ${workdir}
2525
CI: '1'
26+
MONGODB_COMPASS_TEST_USE_PLAIN_SAFE_STORAGE: 'true'
2627
EVERGREEN: '1'
2728
EVERGREEN_AUTHOR: ${author}
2829
EVERGREEN_BRANCH_NAME: ${branch_name}

packages/atlas-service/src/secret-store.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ export class SecretStore {
1515

1616
async getState(): Promise<string | undefined> {
1717
try {
18-
if (process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE === 'true') {
19-
throw new Error('Unsupported environment');
20-
}
2118
const data = await this.userData.readOne(this.fileName);
2219
if (!data) {
2320
return undefined;
@@ -30,9 +27,6 @@ export class SecretStore {
3027

3128
async setState(value: string): Promise<void> {
3229
try {
33-
if (process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE === 'true') {
34-
throw new Error('Unsupported environment');
35-
}
3630
const data = safeStorage.encryptString(value).toString('base64');
3731
await this.userData.write(this.fileName, data);
3832
} catch {

packages/compass-e2e-tests/tests/atlas-login.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,10 @@ describe('Atlas Login', function () {
3636
let compass: Compass;
3737
let browser: CompassBrowser;
3838
let oidcMockProvider: OIDCMockProvider;
39-
let originalDisableKeychainUsage: string | undefined;
4039
let getTokenPayload: OIDCMockProviderConfig['getTokenPayload'];
4140
let stopMockAtlasServer: () => Promise<void>;
4241

4342
before(async function () {
44-
originalDisableKeychainUsage =
45-
process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE;
46-
4743
// Start a mock server to pass an ai response.
4844
const { endpoint, stop } = await startMockAtlasServiceServer();
4945
stopMockAtlasServer = stop;
@@ -100,11 +96,6 @@ describe('Atlas Login', function () {
10096
process.env.COMPASS_CLIENT_ID_OVERRIDE = 'testServer';
10197
process.env.COMPASS_OIDC_ISSUER_OVERRIDE = oidcMockProvider.issuer;
10298
process.env.COMPASS_ATLAS_AUTH_PORTAL_URL_OVERRIDE = `${oidcMockProvider.issuer}/auth-portal-redirect`;
103-
if (process.platform === 'linux' && process.env.CI) {
104-
// Keychain is not working on Linux in CI, see
105-
// https://jira.mongodb.org/browse/COMPASS-6119 for more details.
106-
process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE = 'true';
107-
}
10899
});
109100

110101
beforeEach(async function () {
@@ -134,10 +125,6 @@ describe('Atlas Login', function () {
134125
delete process.env.COMPASS_CLIENT_ID_OVERRIDE;
135126
delete process.env.COMPASS_OIDC_ISSUER_OVERRIDE;
136127
delete process.env.COMPASS_ATLAS_AUTH_PORTAL_URL_OVERRIDE;
137-
if (originalDisableKeychainUsage)
138-
process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE =
139-
originalDisableKeychainUsage;
140-
else delete process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE;
141128

142129
await stopMockAtlasServer();
143130
delete process.env.COMPASS_ATLAS_SERVICE_UNAUTH_BASE_URL_OVERRIDE;

packages/compass-e2e-tests/tests/import-export-connections.test.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,11 @@ const debug = Debug('import-export-connections');
1616
describe('Connection Import / Export', function () {
1717
let tmpdir: string;
1818
let i = 0;
19-
let originalDisableKeychainUsage: string | undefined;
2019
let telemetry: Telemetry;
2120

2221
const getTrackedEvents = (): any[] =>
2322
telemetry.events().filter((e: any) => e.type === 'track');
2423

25-
before(function () {
26-
originalDisableKeychainUsage =
27-
process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE;
28-
if (process.platform === 'linux' && process.env.CI) {
29-
// keytar is not working on Linux in CI, see
30-
// https://jira.mongodb.org/browse/COMPASS-6119 for more details.
31-
process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE = 'true';
32-
}
33-
});
34-
3524
beforeEach(async function () {
3625
telemetry = await startTelemetryServer();
3726

@@ -48,13 +37,6 @@ describe('Connection Import / Export', function () {
4837
await telemetry.stop();
4938
});
5039

51-
after(function () {
52-
if (originalDisableKeychainUsage)
53-
process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE =
54-
originalDisableKeychainUsage;
55-
else delete process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE;
56-
});
57-
5840
const connectionString = 'mongodb://foo:bar@host:1234/';
5941
const connectionStringWithoutCredentials = 'mongodb://foo@host:1234/';
6042
const favoriteName = 'Fav for export';

packages/compass-e2e-tests/tests/oidc.test.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ function getTestBrowserShellCommand() {
4646
describe('OIDC integration', function () {
4747
let compass: Compass;
4848
let browser: CompassBrowser;
49-
let originalDisableKeychainUsage: string | undefined;
5049

5150
let getTokenPayload: typeof oidcMockProviderConfig.getTokenPayload;
5251
let overrideRequestHandler: typeof oidcMockProviderConfig.overrideRequestHandler;
@@ -63,16 +62,6 @@ describe('OIDC integration', function () {
6362
) => Promise<Record<string, any> | undefined>;
6463

6564
before(async function () {
66-
{
67-
originalDisableKeychainUsage =
68-
process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE;
69-
if (process.platform === 'linux' && process.env.CI) {
70-
// keytar is not working on Linux in CI, see
71-
// https://jira.mongodb.org/browse/COMPASS-6119 for more details.
72-
process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE = 'true';
73-
}
74-
}
75-
7665
if (process.platform !== 'linux') {
7766
// OIDC is only supported on Linux in the 7.0+ enterprise server.
7867
return this.skip();
@@ -170,11 +159,6 @@ describe('OIDC integration', function () {
170159
await cluster?.close();
171160
await oidcMockProvider?.close();
172161
if (tmpdir) await fs.rmdir(tmpdir, { recursive: true });
173-
174-
if (originalDisableKeychainUsage)
175-
process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE =
176-
originalDisableKeychainUsage;
177-
else delete process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE;
178162
});
179163

180164
it('can successfully connect with a connection string', async function () {

packages/compass/src/app/auto-connect.spec.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,13 @@ const loadAutoConnectWithConnection = async (
5555

5656
describe('auto connection argument parsing', function () {
5757
let sandbox: sinon.SinonSandbox;
58-
const initialKeychainEnvValue =
59-
process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE;
60-
6158
beforeEach(function () {
6259
sandbox = sinon.createSandbox();
6360
sandbox.stub(ipcRenderer!, 'call').resolves(true);
64-
if (process.platform === 'linux' && process.env.CI) {
65-
// Keychain is not working on Linux in CI, see
66-
// https://jira.mongodb.org/browse/COMPASS-6119 for more details.
67-
process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE = 'true';
68-
}
6961
});
7062

7163
afterEach(function () {
7264
sandbox.restore();
73-
if (initialKeychainEnvValue) {
74-
process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE = initialKeychainEnvValue;
75-
} else {
76-
delete process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE;
77-
}
7865
});
7966

8067
it('skips connecting if shouldAutoConnect is false', async function () {

packages/compass/src/main/application.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import './disable-node-deprecations'; // Separate module so it runs first
22
import path from 'path';
33
import { EventEmitter } from 'events';
44
import type { BrowserWindow, Event } from 'electron';
5-
import { app } from 'electron';
5+
import { app, safeStorage } from 'electron';
66
import { ipcMain } from 'hadron-ipc';
77
import { CompassAutoUpdateManager } from './auto-update-manager';
88
import { CompassLogging } from './logging';
@@ -98,6 +98,13 @@ class CompassApplication {
9898
);
9999
}
100100

101+
if (process.env.MONGODB_COMPASS_TEST_USE_PLAIN_SAFE_STORAGE === 'true') {
102+
// When testing we want to use plain text encryption to avoid having to
103+
// deal with keychain popups or setting up keychain for test on CI (Linux env).
104+
// This method is only available on Linux and is no-op on other platforms.
105+
safeStorage.setUsePlainTextEncryption(true);
106+
}
107+
101108
if (mode === 'CLI') {
102109
return;
103110
}

packages/connection-storage/src/connection-storage.ts

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,10 @@ export class ConnectionStorage {
233233
return deleteCompassAppNameParam(connectionInfo);
234234
}
235235

236+
// This method is only called when compass tries to migrate connections to a new version.
237+
// In e2e-tests we do not migrate any connections as all the connections are created
238+
// in the new format, so keychain is not triggered (using keytar) and hence test is not blocked.
236239
private static async getKeytarCredentials() {
237-
if (process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE === 'true') {
238-
return {};
239-
}
240240
try {
241241
const credentials = await keytar.findCredentials(getKeytarServiceName());
242242
return Object.fromEntries(
@@ -326,34 +326,26 @@ export class ConnectionStorage {
326326
// where we use storage-mixin. storage-mixin uses this prop
327327
// to map keytar credentials to the stored connection.
328328

329-
// While testing, we don't use keychain to store secrets
330-
if (process.env.COMPASS_E2E_DISABLE_KEYCHAIN_USAGE === 'true') {
331-
await this.userData.write(connectionInfo.id, {
332-
connectionInfo,
333-
_id: connectionInfo.id,
334-
});
335-
} else {
336-
const { secrets, connectionInfo: connectionInfoWithoutSecrets } =
337-
extractSecrets(connectionInfo);
338-
339-
let connectionSecrets: string | undefined = undefined;
340-
try {
341-
connectionSecrets = this.encryptSecrets(secrets);
342-
} catch (e) {
343-
log.error(
344-
mongoLogId(1_001_000_202),
345-
'Connection Storage',
346-
'Failed to encrypt secrets',
347-
{ message: (e as Error).message }
348-
);
349-
}
350-
await this.userData.write(connectionInfo.id, {
351-
_id: connectionInfo.id,
352-
connectionInfo: connectionInfoWithoutSecrets,
353-
connectionSecrets,
354-
version: this.version,
355-
});
329+
const { secrets, connectionInfo: connectionInfoWithoutSecrets } =
330+
extractSecrets(connectionInfo);
331+
332+
let connectionSecrets: string | undefined = undefined;
333+
try {
334+
connectionSecrets = this.encryptSecrets(secrets);
335+
} catch (e) {
336+
log.error(
337+
mongoLogId(1_001_000_202),
338+
'Connection Storage',
339+
'Failed to encrypt secrets',
340+
{ message: (e as Error).message }
341+
);
356342
}
343+
await this.userData.write(connectionInfo.id, {
344+
_id: connectionInfo.id,
345+
connectionInfo: connectionInfoWithoutSecrets,
346+
connectionSecrets,
347+
version: this.version,
348+
});
357349
await this.afterConnectionHasBeenSaved(connectionInfo);
358350
} catch (err) {
359351
log.error(

0 commit comments

Comments
 (0)