diff options
| author | Sebastian Holmin <sebastian.holmin@mullvad.net> | 2025-07-04 15:00:15 +0200 |
|---|---|---|
| committer | Sebastian Holmin <sebastian.holmin@mullvad.net> | 2025-07-11 10:15:29 +0200 |
| commit | 0f25b372d7dd0c9234f4f3edc28f8a0b0eba7afa (patch) | |
| tree | 11bb8233b5fca4a97d59c68d81431be815e8bf7c /test/test-runner/src | |
| parent | 1391bf030931ee44964702f5112e0bec5f18fea9 (diff) | |
| download | mullvadvpn-0f25b372d7dd0c9234f4f3edc28f8a0b0eba7afa.tar.xz mullvadvpn-0f25b372d7dd0c9234f4f3edc28f8a0b0eba7afa.zip | |
Add functions to toggle service startup
Diffstat (limited to 'test/test-runner/src')
| -rw-r--r-- | test/test-runner/src/main.rs | 25 | ||||
| -rw-r--r-- | test/test-runner/src/sys.rs | 45 |
2 files changed, 56 insertions, 14 deletions
diff --git a/test/test-runner/src/main.rs b/test/test-runner/src/main.rs index fec18255d7..843285eb33 100644 --- a/test/test-runner/src/main.rs +++ b/test/test-runner/src/main.rs @@ -319,19 +319,22 @@ impl Service for TestServer { } /// Disable the Mullvad VPN system service. - async fn disable_mullvad_daemon_service( - self, - _: context::Context, - ) -> Result<(), test_rpc::Error> { - sys::disable_system_service_startup().await + async fn disable_mullvad_daemon(self, _: context::Context) -> Result<(), test_rpc::Error> { + #[cfg(not(target_os = "windows"))] + unimplemented!("disable_mullvad_daemon is only implemented on Windows"); + #[cfg(target_os = "windows")] + { + sys::disable_system_service_startup().await + } } - /// Enable the Mullvad VPN system service. - async fn enable_mullvad_daemon_service( - self, - _: context::Context, - ) -> Result<(), test_rpc::Error> { - sys::enable_system_service_startup().await + async fn enable_mullvad_daemon(self, _: context::Context) -> Result<(), test_rpc::Error> { + #[cfg(not(target_os = "windows"))] + unimplemented!("enable_mullvad_daemon is only implemented on Windows"); + #[cfg(target_os = "windows")] + { + sys::enable_system_service_startup().await + } } async fn set_daemon_log_level( diff --git a/test/test-runner/src/sys.rs b/test/test-runner/src/sys.rs index 44ac2803ce..3490353b55 100644 --- a/test/test-runner/src/sys.rs +++ b/test/test-runner/src/sys.rs @@ -284,10 +284,49 @@ pub async fn start_app() -> Result<(), test_rpc::Error> { Ok(()) } -/// Disable the Mullvad VPN system service. +/// 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() -> Result<(), test_rpc::Error> { - todo!("sc.exe disable?") +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. |
