Skip to content

Commit 344e7de

Browse files
mcasimiraddaleax
andauthored
fix(connection-storage): allow extract/merge secrets for cosmos connection string COMPASS-5958 (#3280)
* fix(connection-storage): allow extract/merge secrets for cosmos connection string COMPASS-5958 * fixup: bump mongodb-connection-string-url Co-authored-by: Anna Henningsen <[email protected]>
1 parent a5f79c8 commit 344e7de

File tree

10 files changed

+90
-27
lines changed

10 files changed

+90
-27
lines changed

package-lock.json

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-collection/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
"mocha": "^8.4.0",
9494
"mongodb": "^4.6.0",
9595
"mongodb-collection-model": "^4.26.1",
96-
"mongodb-connection-string-url": "^2.5.2",
96+
"mongodb-connection-string-url": "^2.5.3",
9797
"mongodb-ns": "^2.4.0",
9898
"mongodb-data-service": "^21.24.1",
9999
"numeral": "^2.0.6",

packages/compass-connections/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"mocha": "^8.4.0",
8585
"mongodb-build-info": "^1.3.0",
8686
"mongodb-cloud-info": "^1.1.3",
87-
"mongodb-connection-string-url": "^2.5.2",
87+
"mongodb-connection-string-url": "^2.5.3",
8888
"mongodb-data-service": "^21.24.1",
8989
"nyc": "^15.1.0",
9090
"prettier": "^2.7.1",

packages/compass-e2e-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"lodash": "^4.17.21",
5151
"mocha": "^8.4.0",
5252
"mongodb": "^4.6.0",
53-
"mongodb-connection-string-url": "^2.5.2",
53+
"mongodb-connection-string-url": "^2.5.3",
5454
"mongodb-log-writer": "^1.1.4",
5555
"mongodb-runner": "^4.9.0",
5656
"nyc": "^15.1.0",

packages/connection-form/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"@testing-library/react-hooks": "^7.0.2",
5656
"lodash": "^4.17.21",
5757
"mongodb-build-info": "^1.4.0",
58-
"mongodb-connection-string-url": "^2.5.2",
58+
"mongodb-connection-string-url": "^2.5.3",
5959
"mongodb-query-parser": "^2.4.6",
6060
"react": "^16.14.0",
6161
"react-dom": "^16.14.0"

packages/connection-model/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"ampersand-rest-collection": "^6.0.0",
3939
"debug": "^4.2.0",
4040
"lodash": "^4.17.15",
41-
"mongodb-connection-string-url": "^2.5.2",
41+
"mongodb-connection-string-url": "^2.5.3",
4242
"mongodb3": "npm:mongodb@^3.6.3",
4343
"os-dns-native": "^1.2.0",
4444
"raf": "^3.4.1",

packages/data-service/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"mongodb-build-info": "^1.3.0",
6969
"mongodb-client-encryption": "^2.2.0-alpha.1",
7070
"mongodb-connection-model": "^21.19.1",
71-
"mongodb-connection-string-url": "^2.5.2",
71+
"mongodb-connection-string-url": "^2.5.3",
7272
"mongodb-index-model": "^3.12.0",
7373
"mongodb-ns": "^2.4.0",
7474
"uuid": "^8.3.2"

packages/data-service/src/connection-secrets.spec.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ describe('connection secrets', function () {
9090
},
9191
} as ConnectionInfo);
9292
});
93+
94+
it('merges secrets for a cosmosdb connection string', function () {
95+
const originalConnectionInfo: ConnectionInfo = {
96+
connectionOptions: {
97+
connectionString:
98+
'mongodb://[email protected]:8888/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@database-haha@',
99+
},
100+
};
101+
102+
const newConnectionInfo = mergeSecrets(originalConnectionInfo, {
103+
password: 'userPassword',
104+
});
105+
106+
expect(newConnectionInfo).to.be.deep.equal({
107+
connectionOptions: {
108+
connectionString:
109+
'mongodb://database-ut:[email protected]:8888/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@database-haha@',
110+
},
111+
} as ConnectionInfo);
112+
});
93113
});
94114

95115
describe('extractSecrets', function () {
@@ -321,5 +341,47 @@ describe('connection secrets', function () {
321341
);
322342
expect(secretsNoFle).to.deep.equal(_.omit(secrets, 'autoEncryption'));
323343
});
344+
345+
it('extracts secrets for a cosmosdb connection string', function () {
346+
const originalConnectionInfo: ConnectionInfo = {
347+
connectionOptions: {
348+
connectionString:
349+
'mongodb://database-ut:[email protected]:8888/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@database-haha@',
350+
},
351+
};
352+
353+
const { connectionInfo: newConnectionInfo, secrets } = extractSecrets(
354+
originalConnectionInfo
355+
);
356+
357+
expect(newConnectionInfo).to.be.deep.equal({
358+
connectionOptions: {
359+
connectionString:
360+
'mongodb://[email protected]:8888/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@database-haha@',
361+
},
362+
} as ConnectionInfo);
363+
364+
expect(secrets).to.be.deep.equal({
365+
password: 'somerandomsecret',
366+
} as ConnectionSecrets);
367+
368+
const { connectionInfo: newConnectionInfoNoFle, secrets: secretsNoFle } =
369+
extractSecrets(
370+
_.set(
371+
_.cloneDeep(originalConnectionInfo),
372+
'connectionOptions.fleOptions.storeCredentials',
373+
false
374+
)
375+
);
376+
377+
expect(newConnectionInfoNoFle).to.deep.equal(
378+
_.set(
379+
_.cloneDeep(newConnectionInfo),
380+
'connectionOptions.fleOptions.storeCredentials',
381+
false
382+
)
383+
);
384+
expect(secretsNoFle).to.deep.equal(_.omit(secrets, 'autoEncryption'));
385+
});
324386
});
325387
});

packages/data-service/src/connection-secrets.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export function mergeSecrets(
3232
const connectionOptions = connectionInfoWithSecrets.connectionOptions;
3333

3434
const uri = new ConnectionString(connectionOptions.connectionString);
35+
3536
const searchParams = uri.typedSearchParams<MongoClientOptions>();
3637

3738
if (secrets.password) {

scripts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"lodash": "^4.17.21",
4949
"make-fetch-happen": "^8.0.14",
5050
"minimist": "^1.2.5",
51-
"mongodb-connection-string-url": "^2.5.2",
51+
"mongodb-connection-string-url": "^2.5.3",
5252
"mongodb-data-service": "^21.24.1",
5353
"ora": "^5.4.0",
5454
"pacote": "^11.3.5",

0 commit comments

Comments
 (0)