X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=test%2Fvariables.test;h=d4c606fe6eba49de421b1424241877d23376871b;hb=046a10d692d1ac22de4daf783ee4fe025c4eb6ec;hp=d9494b4ffa2c72adfbeeb53afea38961e0603bad;hpb=ada609f3ab838fdcb522de54510c414452be5950;p=tinc diff --git a/test/variables.test b/test/variables.test index d9494b4f..d4c606fe 100755 --- a/test/variables.test +++ b/test/variables.test @@ -1,86 +1,93 @@ #!/bin/sh +# shellcheck source=testlib.sh . "${0%/*}/testlib.sh" -# Initialize one node +echo [STEP] Initialize one node -$tinc $c1 init foo -test "`$tinc $c1 get Name | tr -d '\r'`" = "foo" +tinc foo init foo +test "$(tinc foo get Name)" = "foo" -# Test case sensitivity +echo [STEP] Test case sensitivity -$tinc $c1 set Mode switch -test "`$tinc $c1 get Mode | tr -d '\r'`" = "switch" -test "`$tinc $c1 get mode | tr -d '\r'`" = "switch" -$tinc $c1 set mode router -test "`$tinc $c1 get Mode | tr -d '\r'`" = "router" -test "`$tinc $c1 get mode | tr -d '\r'`" = "router" -$tinc $c1 set Mode Switch -test "`$tinc $c1 get Mode | tr -d '\r'`" = "Switch" +tinc foo set Mode switch +test "$(tinc foo get Mode)" = "switch" +test "$(tinc foo get mode)" = "switch" -# Test deletion +tinc foo set mode router +test "$(tinc foo get Mode)" = "router" +test "$(tinc foo get mode)" = "router" -$tinc $c1 del Mode hub && exit 1 || true -$tinc $c1 del Mode switch -test -z "`$tinc $c1 get Mode`" +tinc foo set Mode Switch +test "$(tinc foo get Mode)" = "Switch" -# There can only be one Mode variable +echo [STEP] Test deletion -$tinc $c1 add Mode switch -$tinc $c1 add Mode hub -test "`$tinc $c1 get Mode | tr -d '\r'`" = "hub" +must_fail tinc foo del Mode hub +tinc foo del Mode switch +test -z "$(tinc foo get Mode)" -# Test addition/deletion of multivalued variables +echo [STEP] There can only be one Mode variable -$tinc $c1 add Subnet 1 -$tinc $c1 add Subnet 2 -$tinc $c1 add Subnet 2 -$tinc $c1 add Subnet 3 -test "`$tinc $c1 get Subnet | tr -d '\r'`" = "1 +tinc foo add Mode switch +tinc foo add Mode hub +test "$(tinc foo get Mode)" = "hub" + +echo [STEP] Test addition/deletion of multivalued variables + +tinc foo add Subnet 1 +tinc foo add Subnet 2 +tinc foo add Subnet 2 +tinc foo add Subnet 3 +test "$(tinc foo get Subnet | rm_cr)" = "1 2 3" -$tinc $c1 del Subnet 2 -test "`$tinc $c1 get Subnet | tr -d '\r'`" = "1 + +tinc foo del Subnet 2 +test "$(tinc foo get Subnet | rm_cr)" = "1 3" -$tinc $c1 del Subnet -test -z "`$tinc $c1 get Subnet`" -# We should not be able to get/set server variables using node.variable syntax +tinc foo del Subnet +test -z "$(tinc foo get Subnet)" -test -z "`$tinc $c1 get foo.Name`" -$tinc $c1 set foo.Name bar && exit 1 || true +echo [STEP] We should not be able to get/set server variables using node.variable syntax -# Test getting/setting host variables for other nodes +test -z "$(tinc foo get foo.Name)" +must_fail tinc foo set foo.Name bar -touch $d1/hosts/bar +echo [STEP] Test getting/setting host variables for other nodes -$tinc $c1 add bar.PMTU 1 -$tinc $c1 add bar.PMTU 2 -test "`$tinc $c1 get bar.PMTU | tr -d '\r'`" = "2" +touch "$DIR_FOO/hosts/bar" -$tinc $c1 add bar.Subnet 1 -$tinc $c1 add bar.Subnet 2 -$tinc $c1 add bar.Subnet 2 -$tinc $c1 add bar.Subnet 3 -test "`$tinc $c1 get bar.Subnet | tr -d '\r'`" = "1 +tinc foo add bar.PMTU 1 +tinc foo add bar.PMTU 2 +test "$(tinc foo get bar.PMTU)" = "2" + +tinc foo add bar.Subnet 1 +tinc foo add bar.Subnet 2 +tinc foo add bar.Subnet 2 +tinc foo add bar.Subnet 3 +test "$(tinc foo get bar.Subnet | rm_cr)" = "1 2 3" -$tinc $c1 del bar.Subnet 2 -test "`$tinc $c1 get bar.Subnet | tr -d '\r'`" = "1 + +tinc foo del bar.Subnet 2 +test "$(tinc foo get bar.Subnet | rm_cr)" = "1 3" -$tinc $c1 del bar.Subnet -test -z "`$tinc $c1 get bar.Subnet`" -# We should not be able to get/set for nodes with invalid names +tinc foo del bar.Subnet +test -z "$(tinc foo get bar.Subnet)" + +echo [STEP] We should not be able to get/set for nodes with invalid names -touch $d1/hosts/qu-ux +touch "$DIR_FOO/hosts/qu-ux" +must_fail tinc foo set qu-ux.Subnet 1 -$tinc $c1 set qu-ux.Subnet 1 && exit 1 || true +echo [STEP] We should not be able to set obsolete variables unless forced -# We should not be able to set obsolete variables unless forced +must_fail tinc foo set PrivateKey 12345 +tinc foo --force set PrivateKey 12345 +test "$(tinc foo get PrivateKey)" = "12345" -$tinc $c1 set PrivateKey 12345 && exit 1 || true -$tinc $c1 --force set PrivateKey 12345 -test "`$tinc $c1 get PrivateKey | tr -d '\r'`" = "12345" -$tinc $c1 del PrivateKey -test -z "`$tinc $c1 get PrivateKey`" +tinc foo del PrivateKey +test -z "$(tinc foo get PrivateKey)"