From 94ad95c9b51e43e9d13b7963f289ffef8e207fa9 Mon Sep 17 00:00:00 2001 From: TowyTowy Date: Fri, 10 Jul 2026 12:05:01 +0200 Subject: [PATCH] Support the `--ssl` and `--skip-ssl` flags in `wp db import` `wp db import` (and other commands that build their MySQL invocation via `DB_Command::get_mysql_args()`, such as `wp db query`) run the associative arguments through an allow-list of valid MySQL client options. That list already contained `ssl-mode` and every `ssl-*` certificate option, but was missing the plain on/off toggles `ssl` and `skip-ssl`. As a result, `wp db import --ssl` silently dropped the flag and connected without SSL, while `wp db cli --ssl` worked because it passes the arguments straight through. This produced confusing failures such as "Error: Failed to get current SQL modes. Reason: ERROR 1045 (28000): Access denied" against servers that require SSL. Add `ssl` and `skip-ssl` to the allow-list so both are forwarded to the MySQL/MariaDB client, matching `wp db cli` behaviour. A Behat scenario asserts the flag now appears in the final MySQL command. Fixes #218. Co-Authored-By: Claude Fable 5 --- features/db-import.feature | 19 +++++++++++++++++++ src/DB_Command.php | 2 ++ 2 files changed, 21 insertions(+) diff --git a/features/db-import.feature b/features/db-import.feature index d1ba3348..d520a61e 100644 --- a/features/db-import.feature +++ b/features/db-import.feature @@ -106,6 +106,25 @@ Feature: Import a WordPress database Success: Imported from 'debug.sql'. """ + # Regression test for https://github.com/wp-cli/db-command/issues/218 + # The `--ssl` flag used to be silently dropped by `get_mysql_args()` because it + # was missing from the list of allowed MySQL client options, so `wp db import + # --ssl` connected without SSL. Assert the flag is now forwarded to the MySQL + # command (visible in the debug output before the connection is attempted). + # SQLite does not use the MySQL client, hence the tag. + @require-mysql-or-mariadb + Scenario: Import forwards the --ssl flag to the MySQL client + Given a WP install + + When I run `wp db export wp_cli_test.sql` + Then the wp_cli_test.sql file should exist + + When I try `wp db import wp_cli_test.sql --ssl --debug` + Then STDERR should contain: + """ + --ssl + """ + # For SQLite this would fail at the `wp db create` step # because of the missing plugin/drop-in. @require-mysql-or-mariadb diff --git a/src/DB_Command.php b/src/DB_Command.php index 83331ece..dfa24586 100644 --- a/src/DB_Command.php +++ b/src/DB_Command.php @@ -2231,7 +2231,9 @@ private static function get_mysql_args( $assoc_args ) { 'skip-named-commands', 'skip-pager', 'skip-reconnect', + 'skip-ssl', 'socket', + 'ssl', 'ssl-ca', 'ssl-capath', 'ssl-cert',