Skip to content

Commit 154e2ad

Browse files
fix failing unit tests
1 parent b2f843e commit 154e2ad

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

test/unit/utils.test.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { expect } from 'chai';
33
import {
44
BufferPool,
55
ByteUtils,
6+
checkParentDomainMatch,
67
compareObjectId,
78
HostAddress,
89
hostMatchesWildcards,
910
isHello,
1011
isUint8Array,
1112
LEGACY_HELLO_COMMAND,
1213
List,
13-
matchesParentDomain,
1414
MongoDBCollectionNamespace,
1515
MongoDBNamespace,
1616
MongoRuntimeError,
@@ -937,7 +937,7 @@ describe('driver utils', function () {
937937
});
938938
});
939939

940-
describe('matchesParentDomain()', () => {
940+
describe('checkParentDomainMatch()', () => {
941941
const exampleSrvName = 'i-love-javascript.mongodb.io';
942942
const exampleSrvNameWithDot = 'i-love-javascript.mongodb.io.';
943943
const exampleHostNameWithoutDot = 'i-love-javascript-00.mongodb.io';
@@ -946,35 +946,40 @@ describe('driver utils', function () {
946946
const exampleHostNamThatDoNotMatchParentWithDot = 'i-love-javascript-00.evil-mongodb.io.';
947947

948948
context('when address does not match parent domain', () => {
949-
it('without a trailing dot returns false', () => {
950-
expect(matchesParentDomain(exampleHostNamThatDoNotMatchParent, exampleSrvName)).to.be.false;
949+
it('without a trailing dot throws', () => {
950+
expect(() =>
951+
checkParentDomainMatch(exampleHostNamThatDoNotMatchParent, exampleSrvName)
952+
).to.throw('Server record does not share hostname with parent URI');
951953
});
952954

953-
it('with a trailing dot returns false', () => {
954-
expect(matchesParentDomain(exampleHostNamThatDoNotMatchParentWithDot, exampleSrvName)).to.be
955-
.false;
955+
it('with a trailing dot throws', () => {
956+
expect(() =>
957+
checkParentDomainMatch(exampleHostNamThatDoNotMatchParentWithDot, exampleSrvName)
958+
).to.throw('Server record does not share hostname with parent URI');
956959
});
957960
});
958961

959962
context('when addresses in SRV record end with a dot', () => {
960963
it('accepts address since it is considered to still match the parent domain', () => {
961-
expect(matchesParentDomain(exampleHostNamesWithDot, exampleSrvName)).to.be.true;
964+
expect(() => checkParentDomainMatch(exampleHostNamesWithDot, exampleSrvName)).to.not.throw;
962965
});
963966
});
964967

965968
context('when SRV host ends with a dot', () => {
966969
it('accepts address if it ends with a dot', () => {
967-
expect(matchesParentDomain(exampleHostNamesWithDot, exampleSrvNameWithDot)).to.be.true;
970+
expect(() => checkParentDomainMatch(exampleHostNamesWithDot, exampleSrvNameWithDot)).to.not
971+
.throw;
968972
});
969973

970974
it('accepts address if it does not end with a dot', () => {
971-
expect(matchesParentDomain(exampleHostNameWithoutDot, exampleSrvName)).to.be.true;
975+
expect(() => checkParentDomainMatch(exampleHostNameWithoutDot, exampleSrvName)).to.not
976+
.throw;
972977
});
973978
});
974979

975980
context('when addresses in SRV record end without dots', () => {
976981
it('accepts address since it matches the parent domain', () => {
977-
expect(matchesParentDomain(exampleHostNamesWithDot, exampleSrvName)).to.be.true;
982+
expect(() => checkParentDomainMatch(exampleHostNamesWithDot, exampleSrvName)).to.not.throw;
978983
});
979984
});
980985
});

0 commit comments

Comments
 (0)