Skip to content

Commit 6a4823a

Browse files
authored
Merge pull request #13 from kanopi/hotfix/keys-w-passwords
Updates refresh to wait for keys, and fail if anything fails
2 parents a3968cd + 96301ea commit 6a4823a

File tree

4 files changed

+64
-6
lines changed

4 files changed

+64
-6
lines changed

commands/web/db-refresh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,24 @@ fi
106106
if [[ "$HOSTING_PROVIDER" == "pantheon" ]]; then
107107
echo -e "${green}Using Pantheon refresh script...${NC}"
108108
# Call the Pantheon-specific refresh script
109-
bash .ddev/scripts/refresh-pantheon.sh "$ENVIRONMENT" "$FORCE_BACKUP"
109+
if ! bash .ddev/scripts/refresh-pantheon.sh "$ENVIRONMENT" "$FORCE_BACKUP"; then
110+
echo -e "${red}Database refresh failed. Please check the error messages above.${NC}"
111+
exit 1
112+
fi
110113
elif [[ "$HOSTING_PROVIDER" == "wpengine" ]]; then
111114
echo -e "${green}Using WPEngine refresh script...${NC}"
112115
# Call the WPEngine-specific refresh script
113-
bash .ddev/scripts/refresh-wpengine.sh "$ENVIRONMENT" "$FORCE_BACKUP"
116+
if ! bash .ddev/scripts/refresh-wpengine.sh "$ENVIRONMENT" "$FORCE_BACKUP"; then
117+
echo -e "${red}Database refresh failed. Please check the error messages above.${NC}"
118+
exit 1
119+
fi
114120
elif [[ "$HOSTING_PROVIDER" == "kinsta" ]]; then
115121
echo -e "${green}Using Kinsta refresh script...${NC}"
116122
# Call the Kinsta-specific refresh script
117-
bash .ddev/scripts/refresh-kinsta.sh "$ENVIRONMENT" "$FORCE_BACKUP"
123+
if ! bash .ddev/scripts/refresh-kinsta.sh "$ENVIRONMENT" "$FORCE_BACKUP"; then
124+
echo -e "${red}Database refresh failed. Please check the error messages above.${NC}"
125+
exit 1
126+
fi
118127
else
119128
echo -e "${red}Hosting platform '$HOSTING_PROVIDER' not supported${NC}"
120129
echo -e "${yellow}Supported platforms: pantheon, wpengine, kinsta${NC}"

scripts/refresh-kinsta.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ if [ "$EXPORT_DATABASE" = true ]; then
9595

9696
# Test SSH connectivity first
9797
echo -e "${yellow}Testing SSH connectivity to Kinsta...${NC}"
98-
if ! ssh -o ConnectTimeout=10 -o BatchMode=yes -o StrictHostKeyChecking=no -p "${SSH_PORT}" "${SSH_CONNECTION}" "echo 'SSH connection successful'" 2>/dev/null; then
98+
if ! ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no -p "${SSH_PORT}" "${SSH_CONNECTION}" "echo 'SSH connection successful'"; then
9999
echo -e "${red}Error: Cannot connect to Kinsta via SSH${NC}"
100100
echo -e "${red}Please ensure:${NC}"
101101
echo -e "${red}1. Your SSH key is properly configured with Kinsta${NC}"

scripts/refresh-wpengine.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ if [ "$DOWNLOAD_BACKUP" = true ]; then
7676
echo -e "${yellow}Testing SSH connectivity to WPEngine...${NC}"
7777

7878
# Build SSH command with key if specified
79-
SSH_CMD="ssh -o ConnectTimeout=10 -o BatchMode=yes"
79+
SSH_CMD="ssh -o ConnectTimeout=10"
8080
if [ -n "${WPENGINE_SSH_KEY:-}" ]; then
8181
# Convert host path to container path if needed
8282
CONTAINER_SSH_KEY="${WPENGINE_SSH_KEY}"
@@ -102,7 +102,7 @@ if [ "$DOWNLOAD_BACKUP" = true ]; then
102102
fi
103103
fi
104104

105-
if ! $SSH_CMD "$WPENGINE_SSH" "echo 'SSH connection successful'" 2>/dev/null; then
105+
if ! $SSH_CMD "$WPENGINE_SSH" "echo 'SSH connection successful'"; then
106106
echo -e "${red}Error: Cannot connect to WPEngine via SSH${NC}"
107107
echo -e "${red}Please ensure:${NC}"
108108
echo -e "${red}1. Your SSH key is properly configured with WPEngine${NC}"

tests/test.bats

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,52 @@ EOF
295295
# Verify WP-CLI works without fatal errors
296296
ddev exec wp core version 2>/dev/null || echo "WP-CLI not available or WordPress not fully configured"
297297
}
298+
299+
@test "db-refresh error handling and exit status" {
300+
set -eu -o pipefail
301+
cd $TESTDIR
302+
ddev config --project-name=$PROJNAME --project-type=wordpress --docroot=web --create-docroot
303+
ddev add-on get $DIR
304+
ddev start
305+
306+
# Test 1: Verify db-refresh fails properly when SSH connection fails
307+
# Configure for a provider that will fail SSH connectivity test
308+
ddev config --web-environment-add="HOSTING_PROVIDER=wpengine"
309+
ddev config --web-environment-add="HOSTING_SITE=nonexistent-site-12345"
310+
ddev restart
311+
312+
# Run db-refresh and expect it to fail with non-zero exit code
313+
# This should fail because SSH connection to nonexistent site will fail
314+
run ddev db-refresh
315+
[ "$status" -ne 0 ] || (echo "db-refresh should fail with non-zero exit code when SSH fails" && exit 1)
316+
317+
# Test 2: Verify error message is displayed (not silenced)
318+
echo "$output" | grep -i "error" || echo "Warning: Expected error message in output"
319+
320+
# Test 3: Test Kinsta provider with invalid SSH configuration
321+
ddev config --web-environment-add="HOSTING_PROVIDER=kinsta"
322+
ddev config --web-environment-add="REMOTE_HOST=invalid.host.example.com"
323+
ddev config --web-environment-add="REMOTE_PORT=22"
324+
ddev config --web-environment-add="REMOTE_USER=testuser"
325+
ddev config --web-environment-add="REMOTE_PATH=/invalid/path"
326+
ddev restart
327+
328+
# This should also fail with non-zero exit code
329+
run ddev db-refresh
330+
[ "$status" -ne 0 ] || (echo "db-refresh should fail for Kinsta with invalid config" && exit 1)
331+
332+
# Test 4: Verify refresh script itself validates properly
333+
# Check that the refresh scripts exist and have proper error handling
334+
ddev exec "test -f .ddev/scripts/refresh-wpengine.sh" || (echo "WPEngine refresh script missing" && exit 1)
335+
ddev exec "test -f .ddev/scripts/refresh-kinsta.sh" || (echo "Kinsta refresh script missing" && exit 1)
336+
ddev exec "test -f .ddev/scripts/refresh-pantheon.sh" || (echo "Pantheon refresh script missing" && exit 1)
337+
338+
# Test 5: Verify SSH command doesn't use BatchMode (which blocks password prompts)
339+
ddev exec "grep -v 'BatchMode=yes' .ddev/scripts/refresh-wpengine.sh" || (echo "WPEngine script should not use BatchMode=yes" && exit 1)
340+
ddev exec "grep -v 'BatchMode=yes' .ddev/scripts/refresh-kinsta.sh" || (echo "Kinsta script should not use BatchMode=yes" && exit 1)
341+
342+
# Test 6: Verify error messages are not silenced (no 2>/dev/null on SSH tests)
343+
# Check WPEngine SSH test line doesn't silence errors
344+
ddev exec "grep 'SSH connection successful' .ddev/scripts/refresh-wpengine.sh | grep -v '2>/dev/null'" || (echo "WPEngine SSH test should not silence errors" && exit 1)
345+
ddev exec "grep 'SSH connection successful' .ddev/scripts/refresh-kinsta.sh | grep -v '2>/dev/null'" || (echo "Kinsta SSH test should not silence errors" && exit 1)
346+
}

0 commit comments

Comments
 (0)