From 6caa9345f7f6ff26eb965ad81415b3ee1d0506fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20L=C3=B6nnhager?= Date: Mon, 10 Jun 2024 14:33:26 +0200 Subject: [PATCH] Add test for Shadowsocks obfuscation mode constraint --- .../tests/relay_selector.rs | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/mullvad-relay-selector/tests/relay_selector.rs b/mullvad-relay-selector/tests/relay_selector.rs index f6bcb54129da..f229d6486571 100644 --- a/mullvad-relay-selector/tests/relay_selector.rs +++ b/mullvad-relay-selector/tests/relay_selector.rs @@ -715,6 +715,31 @@ fn test_selecting_any_relay_will_consider_multihop() { } } +/// Test whether Shadowsocks is always selected as the obfuscation protocol when Shadowsocks is selected. +#[test] +fn test_selecting_wireguard_over_shadowsocks() { + let relay_selector = default_relay_selector(); + let mut query = RelayQueryBuilder::new().wireguard().shadowsocks().build(); + query.wireguard_constraints.use_multihop = Constraint::Only(false); + + let relay = relay_selector.get_relay_by_query(query).unwrap(); + match relay { + GetRelay::Wireguard { + obfuscator, + inner: WireguardConfig::Singlehop { .. }, + .. + } => { + assert!(obfuscator.is_some_and(|obfuscator| matches!( + obfuscator.config, + ObfuscatorConfig::Shadowsocks { .. } + ))) + } + wrong_relay => panic!( + "Relay selector should have picked a Wireguard relay with Shadowsocks, instead chose {wrong_relay:?}" + ), + } +} + /// Construct a query for a Wireguard configuration where UDP2TCP obfuscation is selected and /// multihop is explicitly turned off. Assert that the relay selector always return an obfuscator /// configuration. @@ -742,7 +767,7 @@ fn test_selecting_wireguard_endpoint_with_udp2tcp_obfuscation() { } } -/// Construct a query for a Wireguard configuration where UDP2TCP obfuscation is set to "Auto" and +/// Construct a query for a Wireguard configuration where obfuscation is set to "Auto" and /// multihop is explicitly turned off. Assert that the relay selector does *not* return an /// obfuscator config. ///