fix: correct host normalization logic in MongoDB connection functions

This commit is contained in:
Victor Santos
2025-11-20 20:00:54 -03:00
parent 06fb205b43
commit 4ed75e3e0e
2 changed files with 7 additions and 7 deletions

View File

@@ -55,9 +55,9 @@ export const mongodbCredentialsRotationFactory: TRotationFactory<
const isSrvFromHost = srvRegex.test(normalizedHost);
if (isSrvFromHost) {
normalizedHost = normalizedHost.replace(srvRegex, "");
normalizedHost = srvRegex.replace(normalizedHost, "");
} else if (protocolRegex.test(normalizedHost)) {
normalizedHost = normalizedHost.replace(protocolRegex, "");
normalizedHost = protocolRegex.replace(normalizedHost, "");
}
const [hostIp] = await verifyHostInputValidity(normalizedHost);
@@ -77,12 +77,12 @@ export const mongodbCredentialsRotationFactory: TRotationFactory<
username: authCredentials.username,
password: authCredentials.password
},
authSource: connection.credentials.database,
authSource: isSrv ? undefined : connection.credentials.database,
directConnection: !isSrv
};
// SSL is enabled if explicitly enabled OR if using SRV (which requires TLS) and requireTlsForSrv is true
if (connection.credentials.sslEnabled || (isSrv && options?.requireTlsForSrv)) {
if (connection.credentials.sslEnabled) {
clientOptions.tls = true;
clientOptions.tlsInsecure = !connection.credentials.sslRejectUnauthorized;
if (connection.credentials.sslCertificate) {

View File

@@ -24,9 +24,9 @@ export const validateMongoDBConnectionCredentials = async (config: TMongoDBConne
let normalizedHost = config.credentials.host.trim();
const isSrvFromHost = srvRegex.test(normalizedHost);
if (isSrvFromHost) {
normalizedHost = normalizedHost.replace(srvRegex, "");
normalizedHost = srvRegex.replace(normalizedHost, "");
} else if (protocolRegex.test(normalizedHost)) {
normalizedHost = normalizedHost.replace(protocolRegex, "");
normalizedHost = protocolRegex.replace(normalizedHost, "");
}
const [hostIp] = await verifyHostInputValidity(normalizedHost);
@@ -48,7 +48,7 @@ export const validateMongoDBConnectionCredentials = async (config: TMongoDBConne
username: config.credentials.username,
password: config.credentials.password
},
authSource: config.credentials.database,
authSource: isSrv ? undefined : config.credentials.database,
directConnection: !isSrv
};