Add docker-fence v1 with tests and docs
This commit is contained in:
commit
305cb562f8
46 files changed
+5473
No files matched your search
@@ -0,0 +1,64 @@
|
||||
# shellcheck shell=bash
|
||||
# Variables used by the .bats files:
|
||||
# shellcheck disable=SC2034
|
||||
# Common test functions: temporary tree (FENCE_ROOT), fake binaries
|
||||
# first in PATH, test configuration.
|
||||
|
||||
REPO="$(cd "$BATS_TEST_DIRNAME/.." && pwd)"
|
||||
FENCE="$REPO/docker-fence"
|
||||
FIXTURES="$REPO/tests/fixtures"
|
||||
GOLDEN="$REPO/tests/golden"
|
||||
|
||||
setup_env() {
|
||||
export FENCE_ROOT="$BATS_TEST_TMPDIR/root"
|
||||
export STUB_STATE="$BATS_TEST_TMPDIR/state"
|
||||
export STUB_LOG="$BATS_TEST_TMPDIR/calls.log"
|
||||
export STUB_DOCKER_DIR="$BATS_TEST_TMPDIR/docker"
|
||||
mkdir -p "$FENCE_ROOT/etc/ufw" "$FENCE_ROOT/etc/docker-fence" "$FENCE_ROOT/etc/docker" \
|
||||
"$FENCE_ROOT/var/log" "$STUB_STATE" "$STUB_DOCKER_DIR"
|
||||
RULES="$FENCE_ROOT/etc/ufw/after.rules"
|
||||
cp "$FIXTURES/after.rules" "$RULES"
|
||||
chmod 0640 "$RULES"
|
||||
CONF="$FENCE_ROOT/etc/docker-fence/fence.conf"
|
||||
BACKUPS="$FENCE_ROOT/var/backups/docker-fence"
|
||||
KERNEL="$STUB_STATE/kernel"
|
||||
: >"$STUB_LOG"
|
||||
export PATH="$REPO/tests/stubs:$PATH"
|
||||
unset FENCE_LANG FENCE_CONFIG
|
||||
cd "$BATS_TEST_TMPDIR" || return 1
|
||||
}
|
||||
|
||||
# Writes the test configuration from standard input.
|
||||
write_conf() {
|
||||
cat >"$CONF"
|
||||
chmod 0644 "$CONF"
|
||||
}
|
||||
|
||||
# Minimal valid configuration.
|
||||
minimal_conf() {
|
||||
printf 'admin 192.0.2.10\n' | write_conf
|
||||
}
|
||||
|
||||
fence() {
|
||||
"$FENCE" -c "$CONF" "$@"
|
||||
}
|
||||
|
||||
# Runs the command recorded by the fake systemd-run (rollback timer
|
||||
# expiry).
|
||||
fire_timer() {
|
||||
local -a cmd
|
||||
mapfile -t cmd <"$STUB_STATE/timer_cmd"
|
||||
rm -f "$STUB_STATE/timer_cmd"
|
||||
"${cmd[@]}"
|
||||
}
|
||||
|
||||
# Checksum of a file (byte for byte comparison).
|
||||
sum_of() {
|
||||
sha256sum "$1" | cut -d' ' -f1
|
||||
}
|
||||
|
||||
# Appends the original ufw-docker block to the rules file.
|
||||
add_legacy() {
|
||||
printf '\n' >>"$RULES"
|
||||
cat "$FIXTURES/legacy-block.rules" >>"$RULES"
|
||||
}
|
||||
Reference in new issue
Block a user