Skip to content

Commit 4d3efd8

Browse files
fix failing tests
1 parent f680380 commit 4d3efd8

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,19 +1166,21 @@ export function checkParentDomainMatch(address: string, srvHost: string): void {
11661166
// an srvHostDomain = '.trusted.site'
11671167
// will not satisfy an addressDomain that endsWith '.fake-trusted.site'
11681168
const addressDomain = `.${normalizedAddress.replace(allCharacterBeforeFirstDot, '')}`;
1169-
const srvHostDomain = srvIsLessThanThreeParts
1169+
let srvHostDomain = srvIsLessThanThreeParts
11701170
? normalizedSrvHost
11711171
: `.${normalizedSrvHost.replace(allCharacterBeforeFirstDot, '')}`;
11721172

1173+
if (!srvIsLessThanThreeParts && !srvHostDomain.startsWith('.')) {
1174+
srvHostDomain = '.' + srvHostDomain;
1175+
}
11731176
if (
11741177
srvIsLessThanThreeParts &&
11751178
normalizedAddress.split('.').length <= normalizedSrvHost.split('.').length
11761179
) {
11771180
// TODO(NODE-3484): Replace with MongoConnectionStringError
11781181
throw new MongoAPIError('Server record does not have least one more domain than parent URI');
11791182
}
1180-
1181-
if (!('.' + addressDomain).endsWith('.' + srvHostDomain)) {
1183+
if (!addressDomain.endsWith(srvHostDomain)) {
11821184
// TODO(NODE-3484): Replace with MongoConnectionStringError
11831185
throw new MongoAPIError('Server record does not share hostname with parent URI');
11841186
}

0 commit comments

Comments
 (0)