summaryrefslogtreecommitdiffhomepage
path: root/mullvad-daemon
diff options
context:
space:
mode:
authorEmīls <emils@mullvad.net>2022-02-01 17:41:41 +0000
committerEmīls <emils@mullvad.net>2022-02-01 17:41:41 +0000
commita32fcaba66459eccef5463ee7bd5efafc1adc968 (patch)
tree059383e6126e377c80c9e00b86cab9e1363de615 /mullvad-daemon
parent6c84070da9ad3c485a5198e988a0ed2e174ba101 (diff)
downloadmullvadvpn-a32fcaba66459eccef5463ee7bd5efafc1adc968.tar.xz
mullvadvpn-a32fcaba66459eccef5463ee7bd5efafc1adc968.zip
Add a slightly probabilistic test
Diffstat (limited to 'mullvad-daemon')
-rw-r--r--mullvad-daemon/src/relays/mod.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/mullvad-daemon/src/relays/mod.rs b/mullvad-daemon/src/relays/mod.rs
index 68eb8bde90..0c2aec38fe 100644
--- a/mullvad-daemon/src/relays/mod.rs
+++ b/mullvad-daemon/src/relays/mod.rs
@@ -1432,4 +1432,39 @@ mod test {
assert!(matches!(endpoint.peer.protocol, TransportProtocol::Tcp));
assert!(endpoint.exit_peer.is_none());
}
+
+ #[test]
+ fn test_selecting_wg_multihop_ports() {
+ let mut relay_constraints = WIREGUARD_MULTIHOP_CONSTRAINTS.clone();
+ let relay_selector = new_relay_selector();
+
+ const INVALID_UDP_PORTS: [u16; 2] = [80, 443];
+ for attempt in 0..1000 {
+ let result = relay_selector
+ .get_tunnel_endpoint(&relay_constraints, BridgeState::Off, attempt, true)
+ .expect("Failed to get WireGuard TCP multihop relay");
+ assert!(!INVALID_UDP_PORTS.contains(&result.endpoint.to_endpoint().address.port()));
+ assert_eq!(
+ result.endpoint.unwrap_wireguard().peer.protocol,
+ TransportProtocol::Udp
+ );
+ }
+
+ relay_constraints.wireguard_constraints.port = Constraint::Only(TransportPort {
+ port: Constraint::Any,
+ protocol: TransportProtocol::Tcp,
+ });
+
+ const VALID_TCP_PORTS: [u16; 3] = [80, 443, 5001];
+ for attempt in 0..1000 {
+ let result = relay_selector
+ .get_tunnel_endpoint(&relay_constraints, BridgeState::Off, attempt, true)
+ .expect("Failed to get WireGuard TCP multihop relay");
+ assert!(VALID_TCP_PORTS.contains(&result.endpoint.to_endpoint().address.port()));
+ assert_eq!(
+ result.endpoint.unwrap_wireguard().peer.protocol,
+ TransportProtocol::Tcp
+ );
+ }
+ }
}