Skip to content

Commit aa6a5b3

Browse files
committed
add test
1 parent 0cc4b97 commit aa6a5b3

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,34 @@ describe('resolveMongodbSrv', () => {
225225
await resolveMongodbSrv('mongodb+srv://server.example.com/?srvMaxHosts=1', { dns }),
226226
/^mongodb:\/\/host[1-3]\.example\.com\/\?tls=true$/);
227227
});
228+
229+
it('rejects SRV records without additional subdomain when parent domain has fewer than 3 parts', async () => {
230+
txtResult = [];
231+
srvResult = [{ name: 'example.com', port: 27017 }];
232+
await assert.rejects(resolveMongodbSrv('mongodb+srv://example.com', { dns }));
233+
});
234+
235+
it('allow trailing dot in SRV lookup', async () => {
236+
txtResult = [];
237+
srvResult = [
238+
{ name: 'asdf.example.com', port: 27017 },
239+
{ name: 'meow.example.com', port: 27017 }
240+
];
241+
assert.strictEqual(
242+
await resolveMongodbSrv('mongodb+srv://server.example.com.', { dns }),
243+
'mongodb://asdf.example.com,meow.example.com/?tls=true');
244+
245+
srvResult = [
246+
{ name: 'asdf.example.com.', port: 27017 },
247+
{ name: 'meow.example.com', port: 27017 }
248+
];
249+
assert.strictEqual(
250+
await resolveMongodbSrv('mongodb+srv://server.example.com', { dns }),
251+
'mongodb://asdf.example.com.,meow.example.com/?tls=true');
252+
assert.strictEqual(
253+
await resolveMongodbSrv('mongodb+srv://server.example.com.', { dns }),
254+
'mongodb://asdf.example.com.,meow.example.com/?tls=true');
255+
});
228256
});
229257

230258
for (const [name, dnsProvider] of [

0 commit comments

Comments
 (0)