Skip to content

Commit 73ca011

Browse files
drivers-2922 downstream changes first pass
1 parent 5565d50 commit 73ca011

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

src/connection_string.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ export async function resolveSRVRecord(options: MongoOptions): Promise<HostAddre
6464
throw new MongoAPIError('Option "srvHost" must not be empty');
6565
}
6666

67-
if (options.srvHost.split('.').length < 3) {
68-
// TODO(NODE-3484): Replace with MongoConnectionStringError
69-
throw new MongoAPIError('URI must include hostname, domain name, and tld');
70-
}
71-
7267
// Asynchronously start TXT resolution so that we do not have to wait until
7368
// the SRV record is resolved before starting a second DNS query.
7469
const lookupAddress = options.srvHost;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { expect } from 'chai';
2+
import * as dns from 'dns';
3+
4+
import { MongoClient } from '../../mongodb';
5+
import sinon = require('sinon');
6+
7+
describe.only('Initial DNS Seedlist Discovery (Prose Tests)', () => {
8+
function makeSrvStub() {
9+
sinon.stub(dns.promises, 'resolveSrv').callsFake(async () => {
10+
return [
11+
{
12+
name: 'localhost',
13+
port: 27017,
14+
weight: 0,
15+
priority: 0
16+
}
17+
];
18+
});
19+
20+
sinon.stub(dns.promises, 'resolveTxt').callsFake(async () => {
21+
throw { code: 'ENODATA' };
22+
});
23+
}
24+
25+
afterEach(async () => {
26+
sinon.restore();
27+
});
28+
29+
it('1.1 Driver should not throw error on SRV URI with two parts', async () => {
30+
// 1. stub dns resolution to always pass
31+
makeSrvStub();
32+
// 2. assert that creating a MongoClient with the uri 'mongodb+srv://mongodb.localhost' does not cause an error
33+
//const client = new MongoClient('mongodb+srv://mongodb.localhost', {});
34+
const client = new MongoClient('mongodb+srv://mongodb.localhost');
35+
// 3. assert that connecting the client from 2. to the server does not cause an error
36+
await client.connect();
37+
});
38+
39+
it('1.2 Driver should not throw error on SRV URI with one part', async () => {
40+
// 1. stub dns resolution to always pass
41+
makeSrvStub();
42+
// 2. assert that creating a MongoClient with the uri 'mongodb+srv//localhost' does not cause an error
43+
const client = new MongoClient('mongodb+srv://localhost', {});
44+
// 3. assert that connecting the client from 2. to the server does not cause an error
45+
await client.connect();
46+
});
47+
});

0 commit comments

Comments
 (0)