Import alt-mysql plugin
This commit is contained in:
Executable
+117
@@ -0,0 +1,117 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
SYNC_SCRIPT="$SCRIPT_DIR/scripts/setup/mysql_host_sync.sh"
|
||||
|
||||
fail() {
|
||||
echo "FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
assert_contains() {
|
||||
local file="$1"
|
||||
local needle="$2"
|
||||
grep -Fq "$needle" "$file" || fail "Expected $file to contain: $needle"
|
||||
}
|
||||
|
||||
assert_not_contains() {
|
||||
local file="$1"
|
||||
local needle="$2"
|
||||
if grep -Fq "$needle" "$file"; then
|
||||
fail "Expected $file not to contain: $needle"
|
||||
fi
|
||||
}
|
||||
|
||||
assert_line_count() {
|
||||
local expected="$1"
|
||||
local file="$2"
|
||||
local needle="$3"
|
||||
local actual
|
||||
actual="$(grep -Fxc "$needle" "$file" || true)"
|
||||
[ "$actual" = "$expected" ] || fail "Expected $expected occurrences of '$needle' in $file, got $actual"
|
||||
}
|
||||
|
||||
tmpdir="$(mktemp -d)"
|
||||
trap 'rm -rf "$tmpdir"' EXIT
|
||||
|
||||
mkdir -p "$tmpdir/bin" "$tmpdir/csf"
|
||||
|
||||
cat > "$tmpdir/bin/mysql" <<'MYSQL'
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
printf '%s\n' \
|
||||
"198.51.100.10" \
|
||||
"203.0.113.20" \
|
||||
"localhost" \
|
||||
"bad-host-name"
|
||||
MYSQL
|
||||
chmod 755 "$tmpdir/bin/mysql"
|
||||
|
||||
cat > "$tmpdir/alt-mysql.conf" <<EOF
|
||||
host=localhost
|
||||
port=33033
|
||||
user=root
|
||||
password=secret
|
||||
database=mysql
|
||||
socket=$tmpdir/mysql.sock
|
||||
EOF
|
||||
|
||||
cat > "$tmpdir/alt-mariadb.cnf" <<'EOF'
|
||||
[client]
|
||||
port=33033
|
||||
|
||||
[mariadb]
|
||||
port=33033
|
||||
bind-address=127.0.0.1
|
||||
EOF
|
||||
|
||||
cat > "$tmpdir/csf/csf.allow" <<'EOF'
|
||||
# csf.allow
|
||||
EOF
|
||||
|
||||
cat > "$tmpdir/csf/csf.conf" <<'EOF'
|
||||
TCP_IN = "22,33030:33035,80,33033,443"
|
||||
TCP6_IN = "22,33033:33033"
|
||||
TCP_OUT = "22,80,33033,443"
|
||||
EOF
|
||||
|
||||
MYSQL_HOST_SYNC_ASSUME_ROOT=1 \
|
||||
MYSQL_HOST_SYNC_PLUGIN_SETTINGS="$tmpdir/missing-plugin-settings.conf" \
|
||||
MYSQL_HOST_SYNC_SKIP_CSF_RELOAD=1 \
|
||||
MYSQL_HOST_SYNC_SKIP_SERVICE_RESTART=1 \
|
||||
MYSQL_PLUGIN_CLIENT_BIN_DIR="$tmpdir/bin" \
|
||||
MYSQL_PLUGIN_CREDENTIALS_FILE="$tmpdir/alt-mysql.conf" \
|
||||
MYSQL_HOST_SYNC_INSTANCE_CNF="$tmpdir/alt-mariadb.cnf" \
|
||||
MYSQL_HOST_SYNC_CSF_DIR="$tmpdir/csf" \
|
||||
MYSQL_HOST_SYNC_CSF_ALLOW="$tmpdir/csf/csf.allow" \
|
||||
MYSQL_HOST_SYNC_CSF_CONF="$tmpdir/csf/csf.conf" \
|
||||
MYSQL_HOST_SYNC_MANAGED_ALLOW="$tmpdir/csf/alt-mysql-plugin.allow" \
|
||||
bash "$SYNC_SCRIPT" >/tmp/mysql_host_sync_test.out
|
||||
|
||||
assert_contains "$tmpdir/alt-mariadb.cnf" "bind-address=0.0.0.0"
|
||||
assert_contains "$tmpdir/csf/csf.allow" "Include $tmpdir/csf/alt-mysql-plugin.allow"
|
||||
assert_contains "$tmpdir/csf/alt-mysql-plugin.allow" "tcp|in|d=33033|s=198.51.100.10"
|
||||
assert_contains "$tmpdir/csf/alt-mysql-plugin.allow" "tcp|in|d=33033|s=203.0.113.20"
|
||||
assert_not_contains "$tmpdir/csf/alt-mysql-plugin.allow" "localhost"
|
||||
assert_not_contains "$tmpdir/csf/alt-mysql-plugin.allow" "bad-host-name"
|
||||
assert_contains "$tmpdir/csf/csf.conf" 'TCP_IN = "22,33030:33032,33034:33035,80,443"'
|
||||
assert_contains "$tmpdir/csf/csf.conf" 'TCP6_IN = "22"'
|
||||
assert_contains "$tmpdir/csf/csf.conf" 'TCP_OUT = "22,80,33033,443"'
|
||||
|
||||
MYSQL_HOST_SYNC_ASSUME_ROOT=1 \
|
||||
MYSQL_HOST_SYNC_PLUGIN_SETTINGS="$tmpdir/missing-plugin-settings.conf" \
|
||||
MYSQL_HOST_SYNC_SKIP_CSF_RELOAD=1 \
|
||||
MYSQL_HOST_SYNC_SKIP_SERVICE_RESTART=1 \
|
||||
MYSQL_PLUGIN_CLIENT_BIN_DIR="$tmpdir/bin" \
|
||||
MYSQL_PLUGIN_CREDENTIALS_FILE="$tmpdir/alt-mysql.conf" \
|
||||
MYSQL_HOST_SYNC_INSTANCE_CNF="$tmpdir/alt-mariadb.cnf" \
|
||||
MYSQL_HOST_SYNC_CSF_DIR="$tmpdir/csf" \
|
||||
MYSQL_HOST_SYNC_CSF_ALLOW="$tmpdir/csf/csf.allow" \
|
||||
MYSQL_HOST_SYNC_CSF_CONF="$tmpdir/csf/csf.conf" \
|
||||
MYSQL_HOST_SYNC_MANAGED_ALLOW="$tmpdir/csf/alt-mysql-plugin.allow" \
|
||||
bash "$SYNC_SCRIPT" >/tmp/mysql_host_sync_test_second.out
|
||||
|
||||
assert_line_count 1 "$tmpdir/csf/csf.allow" "Include $tmpdir/csf/alt-mysql-plugin.allow"
|
||||
|
||||
echo "mysql_host_sync_test: OK"
|
||||
Reference in New Issue
Block a user