| 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright (c) 2020 Protocol Labs |
| 4 | # MIT/Apache-2.0 Licensed; see the LICENSE file in this repository. |
| 5 | # |
| 6 | |
| 7 | test_description="Test swarm filters are effective" |
| 8 | |
| 9 | AF="/ip4/127.0.0.0/ipcidr/24" |
| 10 | |
| 11 | . lib/test-lib.sh |
| 12 | |
| 13 | NUM_NODES=3 |
| 14 | |
| 15 | test_expect_success "set up testbed" ' |
| 16 | iptb testbed create -type localipfs -count $NUM_NODES -force -init && |
| 17 | iptb run -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true |
| 18 | ' |
| 19 | |
| 20 | test_expect_success 'filter 127.0.0.0/24 on node 1' ' |
| 21 | ipfsi 1 config --json Swarm.AddrFilters "[\"$AF\"]" |
| 22 | ' |
| 23 | |
| 24 | for i in $(seq 0 $(( NUM_NODES - 1 ))); do |
| 25 | test_expect_success "change IP for node $i" ' |
| 26 | ipfsi $i config --json "Addresses.Swarm" \ |
| 27 | "[\"/ip4/127.0.$i.1/tcp/0\",\"/ip4/127.0.$i.1/udp/0/quic\",\"/ip4/127.0.$i.1/tcp/0/ws\"]" |
| 28 | ' |
| 29 | done |
| 30 | |
| 31 | test_expect_success 'start cluster' ' |
| 32 | iptb start --wait |
| 33 | ' |
| 34 | |
| 35 | test_expect_success 'connecting 1 to 0 fails' ' |
| 36 | test_must_fail iptb connect 1 0 |
| 37 | ' |
| 38 | |
| 39 | test_expect_success 'connecting 0 to 1 fails' ' |
| 40 | test_must_fail iptb connect 1 0 |
| 41 | ' |
| 42 | |
| 43 | test_expect_success 'connecting 2 to 0 succeeds' ' |
| 44 | iptb connect 2 0 |
| 45 | ' |
| 46 | |
| 47 | test_expect_success 'connecting 1 to 0 with dns addrs fails' ' |
| 48 | ipfsi 0 id -f "<addrs>" | sed "s|^/ip4/127.0.0.1/|/dns4/localhost/|" > addrs && |
| 49 | test_must_fail ipfsi 1 swarm connect $(cat addrs) |
| 50 | ' |
| 51 | |
| 52 | |
| 53 | test_expect_success 'stopping cluster' ' |
| 54 | iptb stop |
| 55 | ' |
| 56 | |
| 57 | test_done |