Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions tests/test-init-fence.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# under a scratch INITHOOKS_PATH; /etc/default/turnkey-init-fence, the
# htdocs, the pid file and the log file are scratch paths.

bats_require_minimum_version 1.5.0

load helpers

REPO=$BATS_TEST_DIRNAME/..
Expand Down Expand Up @@ -89,7 +91,7 @@ teardown() {
@test "nat_available asks the family for its nat PREROUTING chain" {
fence_nat_available iptables
stub_tables ip6tables 3 0
! fence_nat_available ip6tables
run ! fence_nat_available ip6tables
[ "$(calls ip6tables)" = '-t nat -n -L PREROUTING' ]
}

Expand Down Expand Up @@ -197,7 +199,7 @@ teardown() {
[ "$output" = 'Stopping init-fence mini-server' ]
[ ! -e "$PIDFILE" ]
sleep 0.2
! kill -0 "$pid" 2>/dev/null
run ! kill -0 "$pid" 2>/dev/null
[ -z "$(calls pgrep)" ]
}

Expand All @@ -211,7 +213,7 @@ teardown() {
[ "${lines[3]}" = "Found simplehttpd.py (pid: $pid) - killing" ]
[ "$(calls pgrep)" = '--oldest --full /usr/lib/inithooks/bin/simplehttpd.py.*lib/inithooks/turnkey-init-fence/htdocs' ]
sleep 0.2
! kill -0 "$pid" 2>/dev/null
run ! kill -0 "$pid" 2>/dev/null
}

@test "stop_mini_server reports when no server is found" {
Expand All @@ -231,7 +233,7 @@ teardown() {
[ "$(count ip6tables ' -A PREROUTING ')" -eq 4 ]
[ "$(count iptables ' -A INPUT ')" -eq 2 ]
[ "$(count ip6tables ' -A INPUT ')" -eq 2 ]
! printf '%s\n' "${lines[@]}" | grep -q WARNING
run ! grep -q WARNING <<<"$output"
[[ "$(calls simplehttpd.py)" == *"$WRITABLE_HTDOCS 60080 60443 "* ]]
}

Expand Down Expand Up @@ -287,7 +289,7 @@ teardown() {
[ "$(count iptables ' -D INPUT ')" -eq 2 ]
[ ! -e "$PIDFILE" ]
sleep 0.2
! kill -0 "$pid" 2>/dev/null
run ! kill -0 "$pid" 2>/dev/null
}

@test "stop-post removes the rules after a failed run" {
Expand Down
48 changes: 25 additions & 23 deletions tests/test-ipconfig.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# scratch /etc/default/inithooks, preseed and interfaces file with ip, ifup,
# turnkey-version and head replaced by stubs.

bats_require_minimum_version 1.5.0

load helpers

REPO=$BATS_TEST_DIRNAME/..
Expand Down Expand Up @@ -56,9 +58,9 @@ preseed() {
}

@test "valid_config rejects anything else" {
! ipconfig_valid_config bogus
! ipconfig_valid_config ''
! ipconfig_valid_config 'static dhcp'
run ! ipconfig_valid_config bogus
run ! ipconfig_valid_config ''
run ! ipconfig_valid_config 'static dhcp'
}

@test "iface is br0 on lxc and eth0 elsewhere" {
Expand All @@ -69,8 +71,8 @@ preseed() {

@test "unchanged succeeds only when the stanza is already there" {
ipconfig_unchanged "$INTERFACES" eth0 dhcp
! ipconfig_unchanged "$INTERFACES" eth0 static
! ipconfig_unchanged "$INTERFACES" br0 dhcp
run ! ipconfig_unchanged "$INTERFACES" eth0 static
run ! ipconfig_unchanged "$INTERFACES" br0 dhcp
}

@test "unchanged fails silently when the file is missing" {
Expand Down Expand Up @@ -271,7 +273,7 @@ iface eth0 inet6 dhcp
[ "$(calls ip)" = 'link set eth0 down' ]
[ -z "$(calls ifup)" ]
[ "$(tail -1 "$INTERFACES")" = ' hostname tkldev' ]
! grep -q inet6 "$INTERFACES"
run ! grep -q inet6 "$INTERFACES"
}

@test "hook static without a netmask is fatal" {
Expand All @@ -289,7 +291,7 @@ iface eth0 inet6 dhcp
[ "$status" -eq 0 ]
grep -q '^iface br0 inet manual$' "$INTERFACES"
grep -q '^iface br0 inet6 dhcp$' "$INTERFACES"
! grep -q eth0 "$INTERFACES"
run ! grep -q eth0 "$INTERFACES"
[ "$(calls ip)" = 'link set br0 down' ]
}

Expand All @@ -304,9 +306,9 @@ iface eth0 inet6 dhcp

@test "unchanged also checks the inet6 stanza when a config is given" {
ipconfig_unchanged "$INTERFACES" eth0 dhcp dhcp
! ipconfig_unchanged "$INTERFACES" eth0 dhcp static
run ! ipconfig_unchanged "$INTERFACES" eth0 dhcp static
sed -i 's/inet dhcp/inet manual/' "$INTERFACES"
! ipconfig_unchanged "$INTERFACES" eth0 dhcp dhcp
run ! ipconfig_unchanged "$INTERFACES" eth0 dhcp dhcp
}

@test "ip6_syntax accepts full, compressed and edge addresses" {
Expand All @@ -321,19 +323,19 @@ iface eth0 inet6 dhcp
}

@test "ip6_syntax rejects what is not an IPv6 address" {
! ipconfig_ip6_syntax ''
! ipconfig_ip6_syntax 2001
! ipconfig_ip6_syntax 192.0.2.10
! ipconfig_ip6_syntax 2001:db8:1::10/64
! ipconfig_ip6_syntax 2001:db8:1:::10
! ipconfig_ip6_syntax 2001::db8::10
! ipconfig_ip6_syntax :2001:db8:1:2:3:4:5:6
! ipconfig_ip6_syntax 2001:db8:1:2:3:4:5:6:
! ipconfig_ip6_syntax 12345::1
! ipconfig_ip6_syntax 2001:db8:g::1
! ipconfig_ip6_syntax 1:2:3:4:5:6:7
! ipconfig_ip6_syntax 1:2:3:4:5:6:7:8:9
! ipconfig_ip6_syntax 1:2:3:4:5:6:7::8
run ! ipconfig_ip6_syntax ''
run ! ipconfig_ip6_syntax 2001
run ! ipconfig_ip6_syntax 192.0.2.10
run ! ipconfig_ip6_syntax 2001:db8:1::10/64
run ! ipconfig_ip6_syntax 2001:db8:1:::10
run ! ipconfig_ip6_syntax 2001::db8::10
run ! ipconfig_ip6_syntax :2001:db8:1:2:3:4:5:6
run ! ipconfig_ip6_syntax 2001:db8:1:2:3:4:5:6:
run ! ipconfig_ip6_syntax 12345::1
run ! ipconfig_ip6_syntax 2001:db8:g::1
run ! ipconfig_ip6_syntax 1:2:3:4:5:6:7
run ! ipconfig_ip6_syntax 1:2:3:4:5:6:7:8:9
run ! ipconfig_ip6_syntax 1:2:3:4:5:6:7::8
}

@test "ip6_first_group pads and lowercases the first group" {
Expand Down Expand Up @@ -512,7 +514,7 @@ iface eth0 inet6 dhcp
run "$HOOK"
[ "$status" -eq 0 ]
grep -q '^iface eth0 inet6 dhcp$' "$INTERFACES"
! grep -q 'address' "$INTERFACES"
run ! grep -q 'address' "$INTERFACES"
}

@test "hook IP6_CONFIG=dhcp writes what an unset key writes" {
Expand Down
4 changes: 3 additions & 1 deletion tests/test-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# job is to create the conf file gets the path before the file is there; that
# is what an appliance first boot found missing.

bats_require_minimum_version 1.5.0

load helpers

setup() {
Expand Down Expand Up @@ -106,7 +108,7 @@ EOF
[ "$status" -eq 0 ]
grep -q '^export ROOT_PASS=' "$CONF"
grep -q '^export AUTO_RUN=TRUE' "$CONF"
! grep -qi 'ambiguous redirect' "$ROOT/inithooks.log"
run ! grep -qi 'ambiguous redirect' "$ROOT/inithooks.log"
}

@test "a failing hook is logged and the run carries on" {
Expand Down
6 changes: 4 additions & 2 deletions tests/test-tagid.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# /etc/default/turnkey-init-fence and the fence htdocs, with systemctl
# replaced by a stub.

bats_require_minimum_version 1.5.0

load helpers

REPO=$BATS_TEST_DIRNAME/..
Expand Down Expand Up @@ -63,7 +65,7 @@ exit 0'

@test "is_tagged looks for the ajax host" {
echo '<html><body>fence</body></html>' > "$BATS_TEST_TMPDIR/index.html"
! tagid_is_tagged "$BATS_TEST_TMPDIR/index.html"
run ! tagid_is_tagged "$BATS_TEST_TMPDIR/index.html"
echo "$SCRIPTS" >> "$BATS_TEST_TMPDIR/index.html"
tagid_is_tagged "$BATS_TEST_TMPDIR/index.html"
}
Expand All @@ -88,7 +90,7 @@ exit 0'
run "$HOOK"
[ "$status" -eq 0 ]
[ -f "$HTDOCS/index.html" ]
! grep -q '@APP_NAME@' "$HTDOCS/index.html"
run ! grep -q '@APP_NAME@' "$HTDOCS/index.html"
grep -q 'core' "$HTDOCS/index.html"
[ "$(tail -2 "$HTDOCS/index.html")" = "$SCRIPTS" ]
# the packaged copy is left as shipped
Expand Down
Loading