X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=test%2Fvariables.test;h=897059dec0cfc22d618684146916803e94027bea;hb=e050753d1fc4d4465032919746c2a4db78f19932;hp=4cf9d5e53043b0d25c3daa5e46f534f2ace5a9f2;hpb=2faf3e91af90716180bde27f54370fe4cbfc64c2;p=tinc diff --git a/test/variables.test b/test/variables.test index 4cf9d5e5..897059de 100755 --- a/test/variables.test +++ b/test/variables.test @@ -2,87 +2,110 @@ . ./testlib.sh -# Initialize one node - -$tinc $c1 init foo -test "`$tinc $c1 get Name`" = "foo" - -# Test case sensitivity - -$tinc $c1 set Mode switch -test "`$tinc $c1 get Mode`" = "switch" -test "`$tinc $c1 get mode`" = "switch" -$tinc $c1 set mode router -test "`$tinc $c1 get Mode`" = "router" -test "`$tinc $c1 get mode`" = "router" -$tinc $c1 set Mode Switch -test "`$tinc $c1 get Mode`" = "Switch" - -# Test deletion - -$tinc $c1 del Mode hub && exit 1 || true -$tinc $c1 del Mode switch -test -z "`$tinc $c1 get Mode`" - -# There can only be one Mode variable - -$tinc $c1 add Mode switch -$tinc $c1 add Mode hub -test "`$tinc $c1 get Mode`" = "hub" - -# Test addition/deletion of multivalued variables - -$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`" = "1 -2 -2 -3" -$tinc $c1 del Subnet 2 -test "`$tinc $c1 get Subnet`" = "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 - -test -z "`$tinc $c1 get foo.Name`" -$tinc $c1 set foo.Name bar && exit 1 || true - -# Test getting/setting host variables for other nodes - -touch $d1/hosts/bar - -$tinc $c1 add bar.PMTU 1 -$tinc $c1 add bar.PMTU 2 -test "`$tinc $c1 get bar.PMTU`" = "2" - -$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`" = "1 -2 -2 -3" -$tinc $c1 del bar.Subnet 2 -test "`$tinc $c1 get bar.Subnet`" = "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 - -touch $d1/hosts/qu-ux - -$tinc $c1 set qu-ux.Subnet 1 && exit 1 || true - -# We should not be able to set obsolete variables unless forced - -$tinc $c1 set PrivateKey 12345 && exit 1 || true -$tinc $c1 --force set PrivateKey 12345 -test "`$tinc $c1 get PrivateKey`" = "12345" -$tinc $c1 del PrivateKey -test -z "`$tinc $c1 get PrivateKey`" +echo [STEP] Initialize one node + +tinc foo init foo +test "$(tinc foo get Name)" = "foo" + +echo [STEP] Test case sensitivity + +tinc foo set Mode switch +test "$(tinc foo get Mode)" = "switch" +test "$(tinc foo get mode)" = "switch" + +tinc foo set mode router +test "$(tinc foo get Mode)" = "router" +test "$(tinc foo get mode)" = "router" + +tinc foo set Mode Switch +test "$(tinc foo get Mode)" = "Switch" + +echo [STEP] Test deletion + +expect_code "$EXIT_FAILURE" tinc foo del Mode hub +tinc foo del Mode switch +test -z "$(tinc foo get Mode)" + +echo [STEP] There can only be one Mode variable + +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.1.1.1 +tinc foo add Subnet 2.2.2.2 +tinc foo add Subnet 2.2.2.2 +tinc foo add Subnet 3.3.3.3 +test "$(tinc foo get Subnet | rm_cr)" = "1.1.1.1 +2.2.2.2 +3.3.3.3" + +tinc foo del Subnet 2.2.2.2 +test "$(tinc foo get Subnet | rm_cr)" = "1.1.1.1 +3.3.3.3" + +tinc foo del Subnet +test -z "$(tinc foo get Subnet)" + +echo [STEP] We should not be able to get/set server variables using node.variable syntax + +test -z "$(tinc foo get foo.Name)" +expect_code "$EXIT_FAILURE" tinc foo set foo.Name bar + +echo [STEP] Test getting/setting host variables for other nodes + +touch "$DIR_FOO/hosts/bar" + +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.1.1.1 +tinc foo add bar.Subnet 2.2.2.2 +tinc foo add bar.Subnet 2.2.2.2 +tinc foo add bar.Subnet 3.3.3.3 +test "$(tinc foo get bar.Subnet | rm_cr)" = "1.1.1.1 +2.2.2.2 +3.3.3.3" + +tinc foo del bar.Subnet 2.2.2.2 +test "$(tinc foo get bar.Subnet | rm_cr)" = "1.1.1.1 +3.3.3.3" + +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 "$DIR_FOO/hosts/qu-ux" +expect_code "$EXIT_FAILURE" tinc foo set qu-ux.Subnet 1.1.1.1 + +echo [STEP] We should not be able to set obsolete variables unless forced + +expect_code "$EXIT_FAILURE" tinc foo set PrivateKey 12345 +tinc foo --force set PrivateKey 12345 +test "$(tinc foo get PrivateKey)" = "12345" + +tinc foo del PrivateKey +test -z "$(tinc foo get PrivateKey)" + +echo [STEP] We should not be able to set/add malformed Subnets + +expect_code "$EXIT_FAILURE" tinc foo add Subnet 1.1.1 +expect_code "$EXIT_FAILURE" tinc foo add Subnet 1:2:3:4:5: +expect_code "$EXIT_FAILURE" tinc foo add Subnet 1:2:3:4:5:::6 +expect_code "$EXIT_FAILURE" tinc foo add Subnet 1:2:3:4:5:6:7:8:9 +expect_code "$EXIT_FAILURE" tinc foo add Subnet 256.256.256.256 +expect_code "$EXIT_FAILURE" tinc foo add Subnet 1:2:3:4:5:6:7:8.123 +expect_code "$EXIT_FAILURE" tinc foo add Subnet 1:2:3:4:5:6:7:1.2.3.4 +expect_code "$EXIT_FAILURE" tinc foo add Subnet a:b:c:d:e:f:g:h +expect_code "$EXIT_FAILURE" tinc foo add Subnet 1.1.1.1/0 +expect_code "$EXIT_FAILURE" tinc foo add Subnet 1.1.1.1/-1 +expect_code "$EXIT_FAILURE" tinc foo add Subnet 1.1.1.1/33 +expect_code "$EXIT_FAILURE" tinc foo add Subnet 1::/0 +expect_code "$EXIT_FAILURE" tinc foo add Subnet 1::/-1 +expect_code "$EXIT_FAILURE" tinc foo add Subnet 1::/129 +expect_code "$EXIT_FAILURE" tinc foo add Subnet :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +test -z "$(tinc foo get Subnet)"