fix(connection): improve synced password recovery
This commit is contained in:
14 files changed
+334
-39
No files matched your search
@@ -33,6 +33,7 @@ function jdbcConfig(): ConnectionConfig {
|
||||
|
||||
const t = (key: string) => {
|
||||
if (key === "connection.mysqlTlsConnectionFailureHint") return "Set TLS Mode to Disabled.";
|
||||
if (key === "connection.mysqlMissingPasswordHint") return "No database password was sent.";
|
||||
if (key === "connection.jdbcMissingRuntimeDependencyHint") return "Install from Maven or import every dependency JAR.";
|
||||
return key;
|
||||
};
|
||||
@@ -64,6 +65,20 @@ describe("appendConnectionErrorHints", () => {
|
||||
expect(message).toBe("Access denied for user root");
|
||||
});
|
||||
|
||||
it("replaces a passwordless MySQL access-denied error with an actionable message", () => {
|
||||
const message = appendConnectionErrorHints(mysqlConfig(undefined), "MySQL connection failed: Server error: `ERROR 1045 (28000): Access denied for user 'root'@'192.168.100.133' (using password: NO)'", t);
|
||||
|
||||
expect(message).toBe("No database password was sent.");
|
||||
expect(message).not.toContain("192.168.100.133");
|
||||
});
|
||||
|
||||
it("keeps the native MySQL access-denied error when a password was supplied", () => {
|
||||
const config = { ...mysqlConfig(undefined), password: "wrong-password" };
|
||||
const error = "Access denied for user 'root'@'192.168.100.133' (using password: YES)";
|
||||
|
||||
expect(appendConnectionErrorHints(config, error, t)).toBe(error);
|
||||
});
|
||||
|
||||
it("adds an installation hint when a custom JDBC driver is missing a runtime dependency", () => {
|
||||
const error = "Missing Java class com.alibaba.fastjson.JSONException. Install the required runtime dependency.";
|
||||
const message = appendConnectionErrorHints(jdbcConfig(), error, t);
|
||||
|
||||
@@ -37,6 +37,11 @@ function isMysqlTlsLikeFailure(message: string): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
export function isMysqlMissingPasswordFailure(config: ConnectionConfig, message: string): boolean {
|
||||
if (config.db_type !== "mysql" || config.password) return false;
|
||||
return /access denied for user[\s\S]*using password:\s*no/i.test(message);
|
||||
}
|
||||
|
||||
export function isJdbcMissingRuntimeDependencyError(message: string): boolean {
|
||||
return /Missing Java class|NoClassDefFoundError|ClassNotFoundException/i.test(message);
|
||||
}
|
||||
@@ -52,6 +57,13 @@ export function appendConnectionErrorHints(config: ConnectionConfig | undefined,
|
||||
result = appendHint(result, t("connection.jdbcMissingRuntimeDependencyHint"));
|
||||
}
|
||||
if (config.db_type !== "mysql") return result;
|
||||
// MySQL includes the client's source IP in this error, which is easy to
|
||||
// mistake for a host rewritten by sync. When no password was sent, lead
|
||||
// with the actionable fix and reserve the native grant error for attempts
|
||||
// that actually supplied credentials.
|
||||
if (isMysqlMissingPasswordFailure(config, message)) {
|
||||
return t("connection.mysqlMissingPasswordHint");
|
||||
}
|
||||
if (mysqlTlsMode(config) === "disabled") return message;
|
||||
if (!isMysqlTlsLikeFailure(message)) return message;
|
||||
const hint = t("connection.mysqlTlsConnectionFailureHint");
|
||||
|
||||
Reference in new issue
Block a user