summaryrefslogtreecommitdiffhomepage
path: root/test/test-runner/src
diff options
context:
space:
mode:
Diffstat (limited to 'test/test-runner/src')
-rw-r--r--test/test-runner/src/main.rs25
-rw-r--r--test/test-runner/src/sys.rs45
2 files changed, 70 insertions, 0 deletions
diff --git a/test/test-runner/src/main.rs b/test/test-runner/src/main.rs
index 95392dc93f..51a357543e 100644
--- a/test/test-runner/src/main.rs
+++ b/test/test-runner/src/main.rs
@@ -318,6 +318,31 @@ impl Service for TestServer {
sys::start_app().await
}
+ /// Disable the Mullvad VPN system service.
+ async fn disable_mullvad_daemon(self, _: context::Context) -> Result<(), test_rpc::Error> {
+ #[cfg(not(target_os = "windows"))]
+ {
+ log::warn!("disable_mullvad_daemon is only implemented on Windows");
+ return Err(test_rpc::Error::Syscall);
+ }
+ #[cfg(target_os = "windows")]
+ {
+ sys::disable_system_service_startup().await
+ }
+ }
+
+ async fn enable_mullvad_daemon(self, _: context::Context) -> Result<(), test_rpc::Error> {
+ #[cfg(not(target_os = "windows"))]
+ {
+ log::warn!("enable_mullvad_daemon is only implemented on Windows");
+ return Err(test_rpc::Error::Syscall);
+ }
+ #[cfg(target_os = "windows")]
+ {
+ sys::enable_system_service_startup().await
+ }
+ }
+
async fn set_daemon_log_level(
self,
_: context::Context,
diff --git a/test/test-runner/src/sys.rs b/test/test-runner/src/sys.rs
index a20a84cbaa..3490353b55 100644
--- a/test/test-runner/src/sys.rs
+++ b/test/test-runner/src/sys.rs
@@ -284,6 +284,51 @@ pub async fn start_app() -> Result<(), test_rpc::Error> {
Ok(())
}
+/// Disable the Mullvad VPN system service startup. This will not trigger the service to stop
+/// immediately, but it will prevent it from starting on the next system boot.
+#[cfg(target_os = "windows")]
+pub async fn disable_system_service_startup() -> Result<(), test_rpc::Error> {
+ let status = tokio::process::Command::new("powershell")
+ .args([
+ "-NoProfile",
+ "-Command",
+ "Set-Service -Name MullvadVPN -StartupType Disabled",
+ ])
+ .status()
+ .await
+ .map_err(|e| test_rpc::Error::ServiceChange(e.to_string()))?;
+
+ if !status.success() {
+ return Err(test_rpc::Error::ServiceChange(
+ "Failed to disable MullvadVPN service".to_string(),
+ ));
+ }
+
+ Ok(())
+}
+
+/// Enable the Mullvad VPN system service startup. This will configure the service to start automatically on system boot.
+#[cfg(target_os = "windows")]
+pub async fn enable_system_service_startup() -> Result<(), test_rpc::Error> {
+ let status = tokio::process::Command::new("powershell")
+ .args([
+ "-NoProfile",
+ "-Command",
+ "Set-Service -Name MullvadVPN -StartupType Automatic",
+ ])
+ .status()
+ .await
+ .map_err(|e| test_rpc::Error::ServiceChange(e.to_string()))?;
+
+ if !status.success() {
+ return Err(test_rpc::Error::ServiceChange(
+ "Failed to enable MullvadVPN service".to_string(),
+ ));
+ }
+
+ Ok(())
+}
+
/// Restart the Mullvad VPN application.
///
/// This function waits for the app to successfully start again.