|
8 | 8 | #---------------------------------------------------------------------------------- |
9 | 9 | # CI Test: SQL Credential Creation |
10 | 10 | # 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. |
12 | 13 | # |
13 | 14 | # This script sources the shared enginescript-db-credentials.sh library and |
14 | 15 | # 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. |
16 | 19 | #---------------------------------------------------------------------------------- |
17 | 20 |
|
18 | 21 | set -euo pipefail |
@@ -46,6 +49,18 @@ fail() { |
46 | 49 | TESTS_FAILED=$((TESTS_FAILED + 1)) |
47 | 50 | } |
48 | 51 |
|
| 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 | + |
49 | 64 |
|
50 | 65 | #---------------------------------------------------------------------------------- |
51 | 66 | # Test 1: vhost-install credential creation methods |
@@ -196,32 +211,41 @@ IMPORT_DOMAIN="importtest.com" |
196 | 211 | DB_CHARSET="utf8mb4" |
197 | 212 |
|
198 | 213 | 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 |
202 | 226 |
|
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" |
205 | 229 | else |
206 | | - fail "Import ES_DB_NAME construction unexpected: '${SDB}'" |
| 230 | + fail "Import USR or PSWD was not assigned" |
207 | 231 | fi |
208 | 232 |
|
209 | 233 | # --- Step 3: Write credentials file --- |
210 | 234 | echo "" |
211 | 235 | echo "Step 3: write_credentials_file" |
212 | 236 | 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}" |
214 | 238 |
|
215 | 239 | if [[ -f "${IMPORT_CREDS_DIR}/${IMPORT_DOMAIN}.txt" ]]; then |
216 | 240 | pass "Credentials file created" |
217 | 241 | else |
218 | 242 | fail "Credentials file not found" |
219 | 243 | fi |
220 | 244 |
|
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" |
223 | 247 | else |
224 | | - fail "Sourced values do not match written values" |
| 248 | + fail "Sourced values do not preserve generated import credentials" |
225 | 249 | fi |
226 | 250 |
|
227 | 251 | # --- Step 4: Validate import credentials --- |
@@ -276,6 +300,43 @@ echo "" |
276 | 300 | echo " vhost-import test complete." |
277 | 301 |
|
278 | 302 |
|
| 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 | + |
279 | 340 | #---------------------------------------------------------------------------------- |
280 | 341 | # Summary |
281 | 342 | #---------------------------------------------------------------------------------- |
|
0 commit comments