Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
73ca011
drivers-2922 downstream changes first pass
aditi-khare-mongoDB Aug 14, 2024
ad151f7
temp commit
aditi-khare-mongoDB Aug 19, 2024
15dc8ee
added more prose tests
aditi-khare-mongoDB Sep 5, 2024
586f7c0
wording fix
aditi-khare-mongoDB Sep 5, 2024
36b0b49
Merge branch 'main' into uri-validate-less
aditi-khare-mongoDB Sep 5, 2024
bea037e
remove stray comment
aditi-khare-mongoDB Sep 5, 2024
ae79ac5
fix up
aditi-khare-mongoDB Sep 5, 2024
b2f843e
add back in comment
aditi-khare-mongoDB Sep 5, 2024
154e2ad
fix failing unit tests
aditi-khare-mongoDB Sep 5, 2024
1059175
Merge branch 'main' into uri-validate-less
aditi-khare-mongoDB Sep 11, 2024
d1209df
Merge branch 'main' into uri-validate-less
aditi-khare-mongoDB Sep 17, 2024
9dd438e
requested changes 1
aditi-khare-mongoDB Sep 19, 2024
f680380
requested changes + review from drivers ticket updates
aditi-khare-mongoDB Sep 24, 2024
4d3efd8
fix failing tests
aditi-khare-mongoDB Sep 25, 2024
062c139
fix failing tests 2
aditi-khare-mongoDB Sep 25, 2024
a3b489c
Merge branch 'main' into uri-validate-less
aditi-khare-mongoDB Sep 25, 2024
7895835
await close
aditi-khare-mongoDB Sep 26, 2024
4879b78
Merge branch 'main' into uri-validate-less
aditi-khare-mongoDB Sep 26, 2024
79f41e4
ready for rereivew
aditi-khare-mongoDB Oct 8, 2024
eafaf61
ready for rereivew
aditi-khare-mongoDB Oct 8, 2024
1de28de
Merge branch 'main' into uri-validate-less
aditi-khare-mongoDB Oct 8, 2024
ec63d53
add in comments of prose tests
aditi-khare-mongoDB Oct 14, 2024
6ae4230
Merge branch 'main' into uri-validate-less
aditi-khare-mongoDB Oct 14, 2024
00e235e
Merge branch 'main' into uri-validate-less
W-A-James Oct 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ready for rereivew
  • Loading branch information
aditi-khare-mongoDB committed Oct 8, 2024
commit 79f41e44eebf09778d769f3c619ae646ce046d03
6 changes: 2 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ export function checkParentDomainMatch(address: string, srvHost: string): void {
const normalizedSrvHost = srvHost.endsWith('.') ? srvHost.slice(0, srvHost.length - 1) : srvHost;

const allCharacterBeforeFirstDot = /^.*?\./;
const srvIsLessThanThreeParts = srvHost.split('.').length < 3;
const srvIsLessThanThreeParts = normalizedSrvHost.split('.').length < 3;
// Remove all characters before first dot
// Add leading dot back to string so
// an srvHostDomain = '.trusted.site'
Expand All @@ -1177,11 +1177,9 @@ export function checkParentDomainMatch(address: string, srvHost: string): void {
srvIsLessThanThreeParts &&
normalizedAddress.split('.').length <= normalizedSrvHost.split('.').length
) {
// TODO(NODE-3484): Replace with MongoConnectionStringError
throw new MongoAPIError('Server record does not have least one more domain than parent URI');
throw new MongoAPIError('Server record does not have at least one more domain level than parent URI');
}
if (!addressDomain.endsWith(srvHostDomain)) {
// TODO(NODE-3484): Replace with MongoConnectionStringError
throw new MongoAPIError('Server record does not share hostname with parent URI');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe('Initial DNS Seedlist Discovery (Prose Tests)', () => {
.catch(e => e);
expect(err).to.be.instanceOf(MongoAPIError);
expect(err.message).to.equal(
'Server record does not have least one more domain than parent URI'
'Server record does not have at least one more domain level than parent URI'
);
});

Expand All @@ -175,7 +175,7 @@ describe('Initial DNS Seedlist Discovery (Prose Tests)', () => {
.catch(e => e);
expect(err).to.be.instanceOf(MongoAPIError);
expect(err.message).to.equal(
'Server record does not have least one more domain than parent URI'
'Server record does not have at least one more domain level than parent URI'
);
});
}
Expand Down
99 changes: 56 additions & 43 deletions test/unit/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -940,56 +940,69 @@ describe('driver utils', function () {
});

describe('checkParentDomainMatch()', () => {
const exampleSrvName = 'i-love-javascript.mongodb.io';
const exampleSrvNameWithDot = 'i-love-javascript.mongodb.io.';
const exampleHostNameWithoutDot = 'i-love-javascript-00.mongodb.io';
const exampleHostNamesWithDot = exampleHostNameWithoutDot + '.';
const exampleHostNamThatDoNotMatchParent = 'i-love-javascript-00.evil-mongodb.io';
const exampleHostNamThatDoNotMatchParentWithDot = 'i-love-javascript-00.evil-mongodb.io.';

context('when address does not match parent domain', () => {
it('without a trailing dot throws', () => {
expect(() =>
checkParentDomainMatch(exampleHostNamThatDoNotMatchParent, exampleSrvName)
).to.throw('Server record does not share hostname with parent URI');
});
const exampleSrvName = ['i-love-js', 'i-love-js.mongodb', 'i-love-javascript.mongodb.io'];
const exampleSrvNameWithDot = ['i-love-js.', 'i-love-js.mongodb.', 'i-love-javascript.mongodb.io.'];
const exampleHostNameWithoutDot = ['js-00.i-love-js', 'js-00.i-love-js.mongodb', 'i-love-javascript-00.mongodb.io'];
const exampleHostNamesWithDot = ['js-00.i-love-js.', 'js-00.i-love-js.mongodb.', 'i-love-javascript-00.mongodb.io.'];
const exampleHostNameThatDoNotMatchParent = ['js-00.i-love-js-a-little','js-00.i-love-js-a-little.mongodb', 'i-love-javascript-00.evil-mongodb.io'];
const exampleHostNameThatDoNotMatchParentWithDot = ['i-love-js','', 'i-love-javascript-00.evil-mongodb.io.'];

for (let num = 0; num < 3; num += 1) {
context(`when srvName has ${num + 1} part${num !== 0 ? 's' : ''}`, () => {
context('when address does not match parent domain', () => {
it('without a trailing dot throws', () => {
expect(() =>
checkParentDomainMatch(exampleHostNameThatDoNotMatchParent[num], exampleSrvName[num])
).to.throw('Server record does not share hostname with parent URI');
});

it('with a trailing dot throws', () => {
expect(() =>
checkParentDomainMatch(exampleHostNamThatDoNotMatchParentWithDot, exampleSrvName)
).to.throw('Server record does not share hostname with parent URI');
});
});
it('with a trailing dot throws', () => {
expect(() =>
checkParentDomainMatch(exampleHostNameThatDoNotMatchParentWithDot[num], exampleSrvName[num])
).to.throw();
});
});

context('when addresses in SRV record end with a dot', () => {
it('accepts address since it is considered to still match the parent domain', () => {
expect(() =>
checkParentDomainMatch(exampleHostNamesWithDot, exampleSrvName)
).to.not.throw();
});
});
context('when addresses in SRV record end with a dot', () => {
it('accepts address since it is considered to still match the parent domain', () => {
expect(() =>
checkParentDomainMatch(exampleHostNamesWithDot[num], exampleSrvName[num])
).to.not.throw();
});
});

context('when SRV host ends with a dot', () => {
it('accepts address if it ends with a dot', () => {
expect(() =>
checkParentDomainMatch(exampleHostNamesWithDot, exampleSrvNameWithDot)
).to.not.throw();
});
context('when SRV host ends with a dot', () => {
it('accepts address if it ends with a dot', () => {
expect(() =>
checkParentDomainMatch(exampleHostNamesWithDot[num], exampleSrvNameWithDot[num])
).to.not.throw();
});

it('accepts address if it does not end with a dot', () => {
expect(() =>
checkParentDomainMatch(exampleHostNameWithoutDot, exampleSrvName)
).to.not.throw();
});
});
it('accepts address if it does not end with a dot', () => {
expect(() =>
checkParentDomainMatch(exampleHostNameWithoutDot[num], exampleSrvNameWithDot[num])
).to.not.throw();
});

if (num < 2) {
it('does not accept address if it does not contain an extra domain level', () => {
expect(() =>
checkParentDomainMatch(exampleSrvNameWithDot[num], exampleSrvNameWithDot[num])
).to.throw('Server record does not have at least one more domain level than parent URI');
});
}
});

context('when addresses in SRV record end without dots', () => {
it('accepts address since it matches the parent domain', () => {
expect(() =>
checkParentDomainMatch(exampleHostNamesWithDot, exampleSrvName)
).to.not.throw();
context('when addresses in SRV record end without dots', () => {
it('accepts address since it matches the parent domain', () => {
expect(() =>
checkParentDomainMatch(exampleHostNamesWithDot[num], exampleSrvName[num])
).to.not.throw();
});
});
});
});
}
});

describe('isUint8Array()', () => {
Expand Down