f472a7abfc
alt_mysql_restore_payload.sh (the DirectAdmin native-restore hook that imports a plugin-origin backup payload into alt-mariadb) had zero behavioral test coverage - only hook-installation plumbing was tested. Add a fake mariadb/mariadb-dump client stub (tracking a simple existing-databases state file) to exercise the real script end-to-end without a live server, covering: checksum mismatch rejection, overwrite=deny enforcement against an existing database, and the happy-path restore. Add a DA_ALT_MYSQL_SETTINGS_FILE override (same pattern as worker.sh's PLUGIN_DIR) so the script's settings file can be pointed at a test fixture instead of the real system one. Also extend da_integration_install_test.sh to check hook-symlink install/uninstall coverage for database_delete_pre.sh, database_user_password_change_pre.sh, database_user_create_post.sh, and database_destroy_user_post.sh, which were previously untested (only database_create_pre.sh was checked).
46 lines
2.9 KiB
Bash
46 lines
2.9 KiB
Bash
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
PLUGIN_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
|
INSTALLER="$PLUGIN_DIR/scripts/setup/da_integration_install.sh"
|
|
TMP_DIR="$(mktemp -d)"
|
|
trap 'rm -rf "$TMP_DIR"' EXIT
|
|
|
|
fail() {
|
|
echo "FAIL: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
mkdir -p "$TMP_DIR/custom"
|
|
cat > "$TMP_DIR/custom/user_backup_compress_pre.sh" <<'EOF'
|
|
#!/bin/bash
|
|
echo existing
|
|
EOF
|
|
chmod 755 "$TMP_DIR/custom/user_backup_compress_pre.sh"
|
|
|
|
DA_CUSTOM_HOOK_DIR="$TMP_DIR/custom" bash "$INSTALLER" install >/dev/null
|
|
|
|
[ -f "$TMP_DIR/custom/user_backup_compress_pre.sh" ] || fail "dispatcher not created"
|
|
grep -Fq "managed by DirectAdmin MySQL plugin hook dispatcher" "$TMP_DIR/custom/user_backup_compress_pre.sh" \
|
|
|| fail "dispatcher marker missing"
|
|
[ -f "$TMP_DIR/custom/user_backup_compress_pre.sh.d/00-existing.sh" ] || fail "existing hook not preserved"
|
|
[ -L "$TMP_DIR/custom/user_backup_compress_pre.sh.d/10-alt-mysql.sh" ] || fail "alt backup hook link missing"
|
|
[ -L "$TMP_DIR/custom/user_restore_post_pre_cleanup.sh.d/10-alt-mysql.sh" ] || fail "alt restore hook link missing"
|
|
[ -L "$TMP_DIR/custom/database_create_pre.sh.d/20-alt-mysql-block-native-db.sh" ] || fail "native DB blocker link missing"
|
|
[ -L "$TMP_DIR/custom/database_delete_pre.sh.d/20-alt-mysql-block-native-db.sh" ] || fail "native DB delete blocker link missing"
|
|
[ -L "$TMP_DIR/custom/database_user_password_change_pre.sh.d/20-alt-mysql-block-native-db.sh" ] || fail "native DB password-change blocker link missing"
|
|
[ -L "$TMP_DIR/custom/database_user_create_post.sh.d/20-alt-mysql-observe-native-db.sh" ] || fail "native DB user-create observer link missing"
|
|
[ -L "$TMP_DIR/custom/database_destroy_user_post.sh.d/20-alt-mysql-observe-native-db.sh" ] || fail "native DB user-destroy observer link missing"
|
|
|
|
DA_CUSTOM_HOOK_DIR="$TMP_DIR/custom" bash "$INSTALLER" uninstall >/dev/null
|
|
[ ! -e "$TMP_DIR/custom/user_backup_compress_pre.sh.d/10-alt-mysql.sh" ] || fail "alt backup hook link not removed"
|
|
[ ! -e "$TMP_DIR/custom/user_restore_post_pre_cleanup.sh.d/10-alt-mysql.sh" ] || fail "alt restore hook link not removed"
|
|
[ ! -e "$TMP_DIR/custom/database_create_pre.sh.d/20-alt-mysql-block-native-db.sh" ] || fail "native DB blocker link not removed"
|
|
[ ! -e "$TMP_DIR/custom/database_delete_pre.sh.d/20-alt-mysql-block-native-db.sh" ] || fail "native DB delete blocker link not removed"
|
|
[ ! -e "$TMP_DIR/custom/database_user_password_change_pre.sh.d/20-alt-mysql-block-native-db.sh" ] || fail "native DB password-change blocker link not removed"
|
|
[ ! -e "$TMP_DIR/custom/database_user_create_post.sh.d/20-alt-mysql-observe-native-db.sh" ] || fail "native DB user-create observer link not removed"
|
|
[ ! -e "$TMP_DIR/custom/database_destroy_user_post.sh.d/20-alt-mysql-observe-native-db.sh" ] || fail "native DB user-destroy observer link not removed"
|
|
[ -f "$TMP_DIR/custom/user_backup_compress_pre.sh.d/00-existing.sh" ] || fail "preserved existing hook should remain"
|
|
|
|
echo "da_integration_install_test: OK"
|