1
1
//! Integration tests for API access methods.
2
2
use super :: { Error , TestContext } ;
3
3
use mullvad_management_interface:: MullvadProxyClient ;
4
+ use talpid_types:: net:: proxy:: CustomProxy ;
4
5
use test_macro:: test_function;
5
6
use test_rpc:: ServiceClient ;
6
7
@@ -26,13 +27,27 @@ pub async fn test_custom_access_methods(
26
27
log:: info!( "Testing Shadowsocks access method" ) ;
27
28
test_shadowsocks ( mullvad_client. clone ( ) ) . await ?;
28
29
log:: info!( "Testing SOCKS5 (Remote) access method" ) ;
29
- test_socks_remote ( ) . await ?;
30
+ test_socks_remote ( mullvad_client . clone ( ) ) . await ?;
30
31
Ok ( ( ) )
31
32
}
32
33
34
+ macro_rules! assert_access_method_works {
35
+ ( $mullvad_client: expr, $access_method: expr) => {
36
+ let successful = $mullvad_client
37
+ . test_custom_api_access_method( $access_method. clone( ) . into( ) )
38
+ . await
39
+ . expect( "Failed to test custom API access method" ) ;
40
+
41
+ assert!(
42
+ successful,
43
+ "Failed while testing access method - {:?}" ,
44
+ $access_method
45
+ ) ;
46
+ } ;
47
+ }
48
+
33
49
async fn test_shadowsocks ( mut mullvad_client : MullvadProxyClient ) -> Result < ( ) , Error > {
34
50
use mullvad_types:: relay_list:: RelayEndpointData ;
35
- use talpid_types:: net:: proxy:: CustomProxy ;
36
51
// Set up all the parameters needed to create a custom Shadowsocks access method.
37
52
//
38
53
// Since Mullvad host's Shadowsocks relays on their bridge servers, we can
@@ -54,19 +69,24 @@ async fn test_shadowsocks(mut mullvad_client: MullvadProxyClient) -> Result<(),
54
69
} )
55
70
. expect ( "`test_shadowsocks` needs at least one shadowsocks relay to execute. Found non in relay list." ) ;
56
71
57
- let successful = mullvad_client
58
- . test_custom_api_access_method ( access_method. clone ( ) . into ( ) )
59
- . await ?;
60
-
61
- assert ! (
62
- successful,
63
- "Failed while testing access method - {access_method:?}"
64
- ) ;
72
+ assert_access_method_works ! ( mullvad_client, access_method. clone( ) ) ;
65
73
66
74
Ok ( ( ) )
67
75
}
68
76
69
- #[ allow( clippy:: unused_async) ]
70
- async fn test_socks_remote ( ) -> Result < ( ) , Error > {
71
- unimplemented ! ( "Testing SOCKS5 (Remote) access method is not implemented" )
77
+ async fn test_socks_remote ( mut mullvad_client : MullvadProxyClient ) -> Result < ( ) , Error > {
78
+ use crate :: vm:: network:: { NON_TUN_GATEWAY , SOCKS5_PORT } ;
79
+ use std:: net:: SocketAddr ;
80
+ use talpid_types:: net:: proxy:: Socks5Remote ;
81
+ // Set up all the parameters needed to create a custom SOCKS5 access method.
82
+ //
83
+ // The remote SOCKS5 proxy is assumed to be running on the test manager. On
84
+ // which port it listens to is defined as a constant in the `test-manager`
85
+ // crate.
86
+ let endpoint = SocketAddr :: from ( ( NON_TUN_GATEWAY , SOCKS5_PORT ) ) ;
87
+ let access_method = CustomProxy :: from ( Socks5Remote :: new ( endpoint) ) ;
88
+
89
+ assert_access_method_works ! ( mullvad_client, access_method) ;
90
+
91
+ Ok ( ( ) )
72
92
}
0 commit comments