Skip to content

Commit f8cb961

Browse files
committed
Fixes
1 parent 371b156 commit f8cb961

2 files changed

Lines changed: 79 additions & 18 deletions

File tree

scripts/ci/test-sql-credentials.sh

Lines changed: 73 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
#----------------------------------------------------------------------------------
99
# CI Test: SQL Credential Creation
1010
# Tests the database credential generation, validation, and SQL execution
11-
# functions used by vhost-install.sh and vhost-import.sh.
11+
# functions used by vhost-install.sh and vhost-import.sh. It also checks the
12+
# vhost import/export source for the canonical single-archive format contract.
1213
#
1314
# This script sources the shared enginescript-db-credentials.sh library and
1415
# calls the exact same functions that production uses, so any change to
15-
# the credential logic is automatically tested.
16+
# the credential logic is automatically tested. Archive contract checks are
17+
# intentionally source-level because vhost-import.sh and vhost-export.sh are
18+
# interactive production scripts that require a real WordPress site.
1619
#----------------------------------------------------------------------------------
1720

1821
set -euo pipefail
@@ -46,6 +49,18 @@ fail() {
4649
TESTS_FAILED=$((TESTS_FAILED + 1))
4750
}
4851

52+
assert_file_contains() {
53+
local file_path="$1"
54+
local pattern="$2"
55+
local description="$3"
56+
57+
if grep -Eq -- "${pattern}" "${file_path}"; then
58+
pass "${description}"
59+
else
60+
fail "${description}"
61+
fi
62+
}
63+
4964

5065
#----------------------------------------------------------------------------------
5166
# Test 1: vhost-install credential creation methods
@@ -196,32 +211,41 @@ IMPORT_DOMAIN="importtest.com"
196211
DB_CHARSET="utf8mb4"
197212

198213
generate_import_db_name "${IMPORT_DOMAIN}" || { fail "generate_import_db_name returned non-zero"; }
199-
SDB="${ES_DB_NAME}"
200-
SUSR="${RAND_CHAR16}"
201-
SPS="${RAND_CHAR32}"
214+
DB="${ES_DB_NAME}"
215+
USR="${RAND_CHAR16}"
216+
PSWD="${RAND_CHAR32}"
217+
GENERATED_IMPORT_DB="${DB}"
218+
GENERATED_IMPORT_USR="${USR}"
219+
GENERATED_IMPORT_PSWD="${PSWD}"
220+
221+
if [[ -n "${DB}" && "${DB}" == "importtest_${RAND_CHAR4}" ]]; then
222+
pass "Import DB constructed and assigned like vhost-import.sh: '${DB}'"
223+
else
224+
fail "Import DB construction unexpected: '${DB}'"
225+
fi
202226

203-
if [[ -n "${SDB}" && "${SDB}" == "importtest_${RAND_CHAR4}" ]]; then
204-
pass "Import ES_DB_NAME constructed: '${SDB}'"
227+
if [[ -n "${USR}" && -n "${PSWD}" ]]; then
228+
pass "Import USR and PSWD assigned like vhost-import.sh"
205229
else
206-
fail "Import ES_DB_NAME construction unexpected: '${SDB}'"
230+
fail "Import USR or PSWD was not assigned"
207231
fi
208232

209233
# --- Step 3: Write credentials file ---
210234
echo ""
211235
echo "Step 3: write_credentials_file"
212236
IMPORT_CREDS_DIR="$(mktemp -d)"
213-
write_credentials_file "${IMPORT_CREDS_DIR}" "${IMPORT_DOMAIN}" "${SDB}" "${SUSR}" "${SPS}"
237+
write_credentials_file "${IMPORT_CREDS_DIR}" "${IMPORT_DOMAIN}" "${DB}" "${USR}" "${PSWD}"
214238

215239
if [[ -f "${IMPORT_CREDS_DIR}/${IMPORT_DOMAIN}.txt" ]]; then
216240
pass "Credentials file created"
217241
else
218242
fail "Credentials file not found"
219243
fi
220244

221-
if [[ "${DB}" == "${SDB}" && "${USR}" == "${SUSR}" && "${PSWD}" == "${SPS}" ]]; then
222-
pass "Sourced values match written values"
245+
if [[ "${DB}" == "${GENERATED_IMPORT_DB}" && "${USR}" == "${GENERATED_IMPORT_USR}" && "${PSWD}" == "${GENERATED_IMPORT_PSWD}" ]]; then
246+
pass "Sourced values preserve generated import credentials"
223247
else
224-
fail "Sourced values do not match written values"
248+
fail "Sourced values do not preserve generated import credentials"
225249
fi
226250

227251
# --- Step 4: Validate import credentials ---
@@ -276,6 +300,43 @@ echo ""
276300
echo " vhost-import test complete."
277301

278302

303+
#----------------------------------------------------------------------------------
304+
# Test 3: vhost import/export single-archive contract
305+
#----------------------------------------------------------------------------------
306+
echo ""
307+
echo "======================================================="
308+
echo " Test 3: vhost import/export archive contract"
309+
echo "======================================================="
310+
echo ""
311+
312+
IMPORT_SCRIPT="${REPO_ROOT}/scripts/functions/vhost/vhost-import.sh"
313+
EXPORT_SCRIPT="${REPO_ROOT}/scripts/functions/vhost/vhost-export.sh"
314+
315+
assert_file_contains "${EXPORT_SCRIPT}" 'manifest\.txt' "vhost-export documents manifest.txt in the bundle"
316+
assert_file_contains "${EXPORT_SCRIPT}" 'database/<site>_db_<timestamp>\.sql\.gz' "vhost-export documents database/<site>_db_<timestamp>.sql.gz"
317+
assert_file_contains "${EXPORT_SCRIPT}" 'files/<site>_files_<timestamp>\.tar\.gz' "vhost-export documents files/<site>_files_<timestamp>.tar.gz"
318+
assert_file_contains "${EXPORT_SCRIPT}" 'zip -0 -r -q "\$\{COMBINED_EXPORT_PATH\}" \.' "vhost-export stores the already-compressed payloads in the outer ZIP"
319+
assert_file_contains "${EXPORT_SCRIPT}" 'format=enginescript-site-archive' "vhost-export writes the EngineScript archive format marker"
320+
assert_file_contains "${EXPORT_SCRIPT}" 'version=1' "vhost-export writes archive version 1"
321+
assert_file_contains "${EXPORT_SCRIPT}" 'database_path=database/\$\{DB_EXPORT_FILENAME\}\.gz' "vhost-export writes the canonical database manifest path"
322+
assert_file_contains "${EXPORT_SCRIPT}" 'files_archive_path=files/\$\{FILES_EXPORT_FILENAME\}' "vhost-export writes the canonical files manifest path"
323+
324+
assert_file_contains "${IMPORT_SCRIPT}" 'MANIFEST_PATH="\$\{WP_EXTRACTED_PATH\}/manifest\.txt"' "vhost-import requires manifest.txt at the archive root"
325+
assert_file_contains "${IMPORT_SCRIPT}" 'format=enginescript-site-archive' "vhost-import validates the EngineScript archive format marker"
326+
assert_file_contains "${IMPORT_SCRIPT}" 'version=1' "vhost-import validates archive version 1"
327+
assert_file_contains "${IMPORT_SCRIPT}" 'find "\$\{WP_EXTRACTED_PATH\}/database" -maxdepth 1 -type f -name "\*\.sql\.gz"' "vhost-import requires exactly one database/*.sql.gz file"
328+
assert_file_contains "${IMPORT_SCRIPT}" 'find "\$\{WP_EXTRACTED_PATH\}/files" -maxdepth 1 -type f -name "\*\.tar\.gz"' "vhost-import requires exactly one files/*.tar.gz archive"
329+
330+
if grep -Eq 'two_file|SINGLE_ZIP_FILE|WP_ARCHIVE_DIR|DB_IMPORT_DIR|root-directory|database-file' "${IMPORT_SCRIPT}"; then
331+
fail "vhost-import still contains legacy separate-file import markers"
332+
else
333+
pass "vhost-import no longer contains legacy separate-file import markers"
334+
fi
335+
336+
echo ""
337+
echo " vhost import/export archive contract test complete."
338+
339+
279340
#----------------------------------------------------------------------------------
280341
# Summary
281342
#----------------------------------------------------------------------------------

scripts/functions/vhost/vhost-import.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ echo " 3. Download the generated .zip file (e.g., site_export_es_se_... .zip
146146
echo " - Place this single downloaded .zip file directly inside the following directory on the EngineScript server:"
147147
echo " \`${IMPORT_BASE_DIR}\`"
148148
echo " (Ensure only this one .zip file is present in ${IMPORT_BASE_DIR})"
149-
echo " - The old separate root-directory/database-file import folders are no longer supported."
149+
echo " - Only this canonical single-archive format is supported."
150150
echo "---------------------------------------------------------------------"
151151
prompt_continue "Press [Enter] when your files are prepared and ready" 600
152152
# --- End Instructions ---
@@ -254,7 +254,7 @@ if [[ "${COMBINED_ARCHIVE_COUNT}" -ne 1 ]]; then
254254
echo "Please place exactly one EngineScript site export .zip directly in:"
255255
echo " ${IMPORT_BASE_DIR}"
256256
echo ""
257-
echo "Legacy separate-file imports using root-directory/ and database-file/ are no longer supported."
257+
echo "The archive must contain manifest.txt, database/*.sql.gz, and files/*.tar.gz."
258258
exit 1
259259
fi
260260

@@ -507,12 +507,12 @@ echo "System Date: $(date)"
507507
# Domain Creation Variables (Generate *new* secure credentials for this server)
508508
source /usr/local/bin/enginescript/enginescript-variables.txt
509509
generate_import_db_name "${DOMAIN}" || exit 1
510-
SDB="${ES_DB_NAME}"
511-
SUSR="${RAND_CHAR16}"
512-
SPS="${RAND_CHAR32}"
510+
DB="${ES_DB_NAME}"
511+
USR="${RAND_CHAR16}"
512+
PSWD="${RAND_CHAR32}"
513513

514514
# Domain Database Credentials (Store the *new* credentials)
515-
write_credentials_file "/home/EngineScript/mysql-credentials" "${DOMAIN}" "${SDB}" "${SUSR}" "${SPS}"
515+
write_credentials_file "/home/EngineScript/mysql-credentials" "${DOMAIN}" "${DB}" "${USR}" "${PSWD}"
516516

517517
echo "Generated new MySQL database credentials for ${SITE_URL}."
518518

0 commit comments

Comments
 (0)