From e6f25ca1d79b659ae3f028433c03de8e26b6033a Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Fri, 12 Nov 2021 17:53:37 +0900 Subject: [PATCH] docker-tests: add simultaneous peer invitation test --- client/src/main.rs | 5 ++-- docker-tests/run-docker-tests.sh | 47 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/client/src/main.rs b/client/src/main.rs index 7991cb8..6b8ee46 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -539,7 +539,8 @@ fn fetch( log::info!("fetching state from server."); let mut store = DataStore::open_or_create(interface)?; - let State { peers, cidrs } = Api::new(&config.server).http("GET", "/user/state")?; + let api = Api::new(&config.server); + let State { peers, cidrs } = api.http("GET", "/user/state")?; let device = Device::get(interface, network.backend)?; let modifications = device.diff(&peers); @@ -581,7 +582,7 @@ fn fetch( candidates.len(), if candidates.len() == 1 { "" } else { "es" } ); - match Api::new(&config.server).http_form::<_, ()>("PUT", "/user/candidates", &candidates) { + match api.http_form::<_, ()>("PUT", "/user/candidates", &candidates) { Err(ureq::Error::Status(404, _)) => { log::warn!("your network is using an old version of innernet-server that doesn't support NAT traversal candidate reporting.") }, diff --git a/docker-tests/run-docker-tests.sh b/docker-tests/run-docker-tests.sh index 898047a..b89749b 100755 --- a/docker-tests/run-docker-tests.sh +++ b/docker-tests/run-docker-tests.sh @@ -147,6 +147,53 @@ cmd docker cp "$tmp_dir/peer2.toml" "$PEER2_CONTAINER:/app/invite.toml" cmd docker start "$PEER2_CONTAINER" sleep 10 +info "Creating invitation for fourth and fifth peer from first peer." +cmd docker exec "$PEER1_CONTAINER" innernet \ + add-peer evilcorp \ + --name "peer4" \ + --cidr "robots" \ + --admin false \ + --auto-ip \ + --save-config "/app/peer4.toml" \ + --invite-expires "30s" \ + --yes +cmd docker cp "$PEER1_CONTAINER:/app/peer4.toml" "$tmp_dir" +cmd docker exec "$PEER1_CONTAINER" innernet \ + add-peer evilcorp \ + --name "peer5" \ + --cidr "robots" \ + --admin false \ + --auto-ip \ + --save-config "/app/peer5.toml" \ + --invite-expires "30s" \ + --yes +cmd docker cp "$PEER1_CONTAINER:/app/peer5.toml" "$tmp_dir" + +info "Starting fourth and fifth peer and redeeming simultaneously." +PEER4_CONTAINER=$(docker create --rm -it \ + --network "$NETWORK" \ + --ip 172.18.1.4 \ + --volume /dev/net/tun:/dev/net/tun \ + --cap-add NET_ADMIN \ + --env INTERFACE=evilcorp \ + --env INNERNET_ARGS="$INNERNET_ARGS" \ + innernet /app/start-client.sh) +cmd docker cp "$tmp_dir/peer4.toml" "$PEER4_CONTAINER:/app/invite.toml" +PEER5_CONTAINER=$(docker create --rm -it \ + --network "$NETWORK" \ + --ip 172.18.1.5 \ + --volume /dev/net/tun:/dev/net/tun \ + --cap-add NET_ADMIN \ + --env INTERFACE=evilcorp \ + --env INNERNET_ARGS="$INNERNET_ARGS" \ + innernet /app/start-client.sh) +cmd docker cp "$tmp_dir/peer5.toml" "$PEER5_CONTAINER:/app/invite.toml" + +cmd docker start "$PEER4_CONTAINER" +info "peer4 started as $PEER4_CONTAINER" +cmd docker start -a "$PEER5_CONTAINER" & +info "peer5 started as $PEER5_CONTAINER" + info "Checking connectivity betweeen peers." cmd docker exec "$PEER2_CONTAINER" ping -c3 10.66.0.1 cmd docker exec "$PEER2_CONTAINER" ping -c3 10.66.1.1