fix(connection): preserve credentials for credential-free URLs
Closes #5377
This commit is contained in:
1 parent
3d114c28e2
commit
2ecbac4a6f
2 files changed
+62
No files matched your search
@@ -674,6 +674,11 @@ function zookeeperConnectStringFromUrl(parsed: URL, defaultPort: number): string
|
||||
return `${host}:${port}${chroot}`;
|
||||
}
|
||||
|
||||
function shouldPreserveCredentialFreeUrlCredentials(config: Omit<ConnectionConfig, "id">, parsed: ParsedConnectionUrl): boolean {
|
||||
const currentProfile = config.driver_profile?.trim();
|
||||
return parsed.dbType === config.db_type && (!currentProfile || parsed.driverProfile === currentProfile) && !parsed.username && !parsed.password;
|
||||
}
|
||||
|
||||
function applyParsedUsername(config: Omit<ConnectionConfig, "id">, parsed: ParsedConnectionUrl): string {
|
||||
if (parsed.dbType === "h2" && config.db_type === "h2" && !h2JdbcUrlHasUserParam(parsed.connectionString)) {
|
||||
return config.username || parsed.username;
|
||||
@@ -681,6 +686,9 @@ function applyParsedUsername(config: Omit<ConnectionConfig, "id">, parsed: Parse
|
||||
if (parsed.dbType === "kingbase" && config.db_type === "kingbase" && !parsed.username) {
|
||||
return config.username;
|
||||
}
|
||||
if (shouldPreserveCredentialFreeUrlCredentials(config, parsed)) {
|
||||
return config.username || parsed.username;
|
||||
}
|
||||
return parsed.username;
|
||||
}
|
||||
|
||||
@@ -691,6 +699,9 @@ function applyParsedPassword(config: Omit<ConnectionConfig, "id">, parsed: Parse
|
||||
if (parsed.dbType === "kingbase" && config.db_type === "kingbase" && !parsed.password) {
|
||||
return config.password;
|
||||
}
|
||||
if (shouldPreserveCredentialFreeUrlCredentials(config, parsed)) {
|
||||
return config.password || parsed.password;
|
||||
}
|
||||
return parsed.password;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user