Skip to content

Commit 94ad95c

Browse files
TowyTowyclaude
andcommitted
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 <noreply@anthropic.com>
1 parent 8b83c5a commit 94ad95c

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

features/db-import.feature

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,25 @@ Feature: Import a WordPress database
106106
Success: Imported from 'debug.sql'.
107107
"""
108108

109+
# Regression test for https://github.com/wp-cli/db-command/issues/218
110+
# The `--ssl` flag used to be silently dropped by `get_mysql_args()` because it
111+
# was missing from the list of allowed MySQL client options, so `wp db import
112+
# --ssl` connected without SSL. Assert the flag is now forwarded to the MySQL
113+
# command (visible in the debug output before the connection is attempted).
114+
# SQLite does not use the MySQL client, hence the tag.
115+
@require-mysql-or-mariadb
116+
Scenario: Import forwards the --ssl flag to the MySQL client
117+
Given a WP install
118+
119+
When I run `wp db export wp_cli_test.sql`
120+
Then the wp_cli_test.sql file should exist
121+
122+
When I try `wp db import wp_cli_test.sql --ssl --debug`
123+
Then STDERR should contain:
124+
"""
125+
--ssl
126+
"""
127+
109128
# For SQLite this would fail at the `wp db create` step
110129
# because of the missing plugin/drop-in.
111130
@require-mysql-or-mariadb

src/DB_Command.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,7 +2231,9 @@ private static function get_mysql_args( $assoc_args ) {
22312231
'skip-named-commands',
22322232
'skip-pager',
22332233
'skip-reconnect',
2234+
'skip-ssl',
22342235
'socket',
2236+
'ssl',
22352237
'ssl-ca',
22362238
'ssl-capath',
22372239
'ssl-cert',

0 commit comments

Comments
 (0)