Skip to content

Commit c5a91a5

Browse files
committed
feat(service-provider-core): add ConnectionString class MONGOSH-528
Add a ConnectionString class for easier URI manipulation.
1 parent 3a867c3 commit c5a91a5

17 files changed

+475
-142
lines changed

packages/cli-repl/test/e2e-direct.spec.ts

Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -27,74 +27,76 @@ describe('e2e direct connection', () => {
2727
});
2828
});
2929

30-
it('allows to initialize the replica set', async() => {
31-
const replSetConfig = {
32-
_id: replSetId,
33-
version: 1,
34-
members: [
35-
{ _id: 0, host: await rs0.hostport(), priority: 1 },
36-
{ _id: 1, host: await rs1.hostport(), priority: 0 },
37-
{ _id: 2, host: await rs2.hostport(), priority: 0 },
38-
]
39-
};
30+
context('after rs.initiate()', () => {
31+
before(async() => {
32+
const replSetConfig = {
33+
_id: replSetId,
34+
version: 1,
35+
members: [
36+
{ _id: 0, host: await rs0.hostport(), priority: 1 },
37+
{ _id: 1, host: await rs1.hostport(), priority: 0 },
38+
{ _id: 2, host: await rs2.hostport(), priority: 0 },
39+
]
40+
};
4041

41-
const shell = TestShell.start({ args: [await rs0.connectionString()] });
42-
await shell.waitForPrompt();
43-
await shell.executeLine(`rs.initiate(${JSON.stringify(replSetConfig)})`);
44-
shell.assertContainsOutput('ok: 1');
45-
await eventually(async() => {
46-
await shell.executeLine('db.isMaster()');
47-
shell.assertContainsOutput('ismaster: true');
48-
shell.assertContainsOutput(`me: '${await rs0.hostport()}'`);
49-
shell.assertContainsOutput(`setName: '${replSetId}'`);
50-
});
51-
});
52-
53-
context('connecting to secondary members directly', () => {
54-
it('works when specifying a connection string', async() => {
55-
const shell = TestShell.start({ args: [await rs1.connectionString()] });
42+
const shell = TestShell.start({ args: [await rs0.connectionString()] });
5643
await shell.waitForPrompt();
57-
await shell.executeLine('db.isMaster()');
58-
shell.assertContainsOutput('ismaster: false');
59-
shell.assertContainsOutput(`me: '${await rs1.hostport()}'`);
60-
shell.assertContainsOutput(`setName: '${replSetId}'`);
44+
await shell.executeLine(`rs.initiate(${JSON.stringify(replSetConfig)})`);
45+
shell.assertContainsOutput('ok: 1');
46+
await eventually(async() => {
47+
await shell.executeLine('db.isMaster()');
48+
shell.assertContainsOutput('ismaster: true');
49+
shell.assertContainsOutput(`me: '${await rs0.hostport()}'`);
50+
shell.assertContainsOutput(`setName: '${replSetId}'`);
51+
});
6152
});
6253

63-
it('works when specifying just host and port', async() => {
64-
const shell = TestShell.start({ args: [await rs1.hostport()] });
65-
await shell.waitForPrompt();
66-
await shell.executeLine('db.isMaster()');
67-
shell.assertContainsOutput('ismaster: false');
68-
shell.assertContainsOutput(`me: '${await rs1.hostport()}'`);
69-
shell.assertContainsOutput(`setName: '${replSetId}'`);
70-
});
71-
});
54+
context('connecting to secondary members directly', () => {
55+
it('works when specifying a connection string', async() => {
56+
const shell = TestShell.start({ args: [await rs1.connectionString()] });
57+
await shell.waitForPrompt();
58+
await shell.executeLine('db.isMaster()');
59+
shell.assertContainsOutput('ismaster: false');
60+
shell.assertContainsOutput(`me: '${await rs1.hostport()}'`);
61+
shell.assertContainsOutput(`setName: '${replSetId}'`);
62+
});
7263

73-
context('connecting to primary', () => {
74-
it('when specifying replicaSet', async() => {
75-
const shell = TestShell.start({ args: [`${await rs1.connectionString()}?replicaSet=${replSetId}`] });
76-
await shell.waitForPrompt();
77-
await shell.executeLine('db.isMaster()');
78-
shell.assertContainsOutput('ismaster: true');
79-
shell.assertContainsOutput(`me: '${await rs0.hostport()}'`);
80-
shell.assertContainsOutput(`setName: '${replSetId}'`);
64+
it('works when specifying just host and port', async() => {
65+
const shell = TestShell.start({ args: [await rs1.hostport()] });
66+
await shell.waitForPrompt();
67+
await shell.executeLine('db.isMaster()');
68+
shell.assertContainsOutput('ismaster: false');
69+
shell.assertContainsOutput(`me: '${await rs1.hostport()}'`);
70+
shell.assertContainsOutput(`setName: '${replSetId}'`);
71+
});
8172
});
82-
it('when setting directConnection to false', async() => {
83-
const shell = TestShell.start({ args: [`${await rs1.connectionString()}?directConnection=false`] });
84-
await shell.waitForPrompt();
85-
await shell.executeLine('db.isMaster()');
86-
shell.assertContainsOutput('ismaster: true');
87-
shell.assertContainsOutput(`me: '${await rs0.hostport()}'`);
88-
shell.assertContainsOutput(`setName: '${replSetId}'`);
89-
});
90-
it('when specifying multiple seeds', async() => {
91-
const connectionString = 'mongodb://' + await rs2.hostport() + ',' + await rs1.hostport() + ',' + await rs0.hostport();
92-
const shell = TestShell.start({ args: [connectionString] });
93-
await shell.waitForPrompt();
94-
await shell.executeLine('db.isMaster()');
95-
shell.assertContainsOutput('ismaster: true');
96-
shell.assertContainsOutput(`me: '${await rs0.hostport()}'`);
97-
shell.assertContainsOutput(`setName: '${replSetId}'`);
73+
74+
context('connecting to primary', () => {
75+
it('when specifying replicaSet', async() => {
76+
const shell = TestShell.start({ args: [`${await rs1.connectionString()}?replicaSet=${replSetId}`] });
77+
await shell.waitForPrompt();
78+
await shell.executeLine('db.isMaster()');
79+
shell.assertContainsOutput('ismaster: true');
80+
shell.assertContainsOutput(`me: '${await rs0.hostport()}'`);
81+
shell.assertContainsOutput(`setName: '${replSetId}'`);
82+
});
83+
it('when setting directConnection to false', async() => {
84+
const shell = TestShell.start({ args: [`${await rs1.connectionString()}?directConnection=false`] });
85+
await shell.waitForPrompt();
86+
await shell.executeLine('db.isMaster()');
87+
shell.assertContainsOutput('ismaster: true');
88+
shell.assertContainsOutput(`me: '${await rs0.hostport()}'`);
89+
shell.assertContainsOutput(`setName: '${replSetId}'`);
90+
});
91+
it('when specifying multiple seeds', async() => {
92+
const connectionString = 'mongodb://' + await rs2.hostport() + ',' + await rs1.hostport() + ',' + await rs0.hostport();
93+
const shell = TestShell.start({ args: [connectionString] });
94+
await shell.waitForPrompt();
95+
await shell.executeLine('db.isMaster()');
96+
shell.assertContainsOutput('ismaster: true');
97+
shell.assertContainsOutput(`me: '${await rs0.hostport()}'`);
98+
shell.assertContainsOutput(`setName: '${replSetId}'`);
99+
});
98100
});
99101
});
100102
});

packages/cli-repl/test/e2e-tls.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ describe('e2e TLS', () => {
220220
args: [
221221
`${await server.connectionString()}?serverSelectionTimeoutMS=1500`
222222
+ '&authMechanism=MONGODB-X509'
223-
+ `&tls=true&tlsCAFile=${encodeURIComponent(CA_CERT)}&tlsCertificateKeyFile=${encodeURIComponent(CLIENT_CERT)}&tlsCertificateFile=${encodeURIComponent(CLIENT_CERT)}`
223+
+ `&tls=true&tlsCAFile=${encodeURIComponent(CA_CERT)}&tlsCertificateKeyFile=${encodeURIComponent(CLIENT_CERT)}`
224224
]
225225
});
226226
const prompt = await waitForPromptOrExit(shell);

packages/java-shell/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/src/main/resources/js/all-standalone.js
2+
/src/test/resources/URI.txt
23
/build/
34
/.gradle/

packages/java-shell/package-lock.json

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

packages/service-provider-core/package-lock.json

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

packages/service-provider-core/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
"@mongosh/i18n": "0.0.0-dev.0",
3232
"bson": "^4.2.2",
3333
"mongodb": "github:mongodb/node-mongodb-native#b1bdb06c",
34-
"mongodb-build-info": "^1.1.1"
34+
"mongodb-build-info": "^1.1.1",
35+
"whatwg-url": "^8.4.0"
3536
},
3637
"devDependencies": {
37-
"@types/bl": "^2.1.0"
38+
"@types/bl": "^2.1.0",
39+
"@types/whatwg-url": "^8.0.0"
3840
},
3941
"dependency-check": {
4042
"entries": [

0 commit comments

Comments
 (0)