1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
//! Tests of interoperability with other software
use super::{Error, TestContext, helpers};
use mullvad_management_interface::MullvadProxyClient;
use test_macro::test_function;
use test_rpc::{ExecResult, ServiceClient};
/// This test fails if there is no connectivity, or name resolution fails, when connected to a VPN.
#[test_function(target_os = "linux")]
pub async fn test_containers(
_: TestContext,
rpc: ServiceClient,
mut mullvad_client: MullvadProxyClient,
) -> Result<(), Error> {
let result = probe_container_connectivity(&rpc).await?;
assert!(
result.success(),
"containers should have connectivity when disconnected from the VPN"
);
helpers::connect_and_wait(&mut mullvad_client).await?;
let result = probe_container_connectivity(&rpc).await?;
assert!(
result.success(),
"containers should have connectivity when connected to the VPN"
);
Ok(())
}
/// This function executes curl inside podman or docker in the guest/test runner.
async fn probe_container_connectivity(rpc: &ServiceClient) -> Result<ExecResult, Error> {
let has_podman = rpc.exec("bash", ["-c", "which podman"]).await?.success();
let result = if has_podman {
// podman run docker.io/curlimages/curl:latest https://am.i.mullvad.net/connected
rpc.exec(
"podman",
[
"run",
"docker.io/curlimages/curl:latest",
"https://am.i.mullvad.net/connected",
],
)
.await?
} else {
// sudo docker run docker.io/curlimages/curl:latest https://am.i.mullvad.net/connected
rpc.exec(
"sudo",
[
"docker",
"run",
"docker.io/curlimages/curl:latest",
"https://am.i.mullvad.net/connected",
],
)
.await?
};
if !result.success() {
let stdout = std::str::from_utf8(&result.stdout).unwrap_or("invalid utf8");
let stderr = std::str::from_utf8(&result.stderr).unwrap_or("invalid utf8");
log::error!("probe_container_connectivity failed:\n\nstdout:\n\n{stdout}\n\n{stderr}\n");
}
Ok(result)
}
|