diff options
author | Didier Wenzek <didier.wenzek@free.fr> | 2022-07-20 15:42:39 +0200 |
---|---|---|
committer | Didier Wenzek <didier.wenzek@free.fr> | 2022-07-20 15:42:39 +0200 |
commit | b9d61c8bf094cdd13246216705b625b795c1f903 (patch) | |
tree | 89969ea5ec00ff6de68a224e757cfb0b439c9e33 /crates/core | |
parent | c961fd51dbbcf5cfe781f6acdcea60034f01e520 (diff) |
Remove unused test
The test `create_certificate_as_root_should_switch_to_mosquitto` were
behind features and never triggered. As a consequence this test has not
been maintained and is no more aligned with the code base (the tedge config is
no more user dependent, there is --config-dir option, the tedge command
is no more running as tegde). Futhermore this test was using `sudo`.
Better to simply remove it.
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
Diffstat (limited to 'crates/core')
-rw-r--r-- | crates/core/tedge/Cargo.toml | 4 | ||||
-rw-r--r-- | crates/core/tedge/tests/main.rs | 2 | ||||
-rw-r--r-- | crates/core/tedge/tests/os_related/mod.rs | 5 | ||||
-rw-r--r-- | crates/core/tedge/tests/os_related/unix.rs | 122 |
4 files changed, 0 insertions, 133 deletions
diff --git a/crates/core/tedge/Cargo.toml b/crates/core/tedge/Cargo.toml index 1dcdcb52..30479893 100644 --- a/crates/core/tedge/Cargo.toml +++ b/crates/core/tedge/Cargo.toml @@ -45,7 +45,3 @@ tokio = { version = "1.12" } [features] integration-test = [] -mosquitto-available = [] # Enable tests requesting mosquitto installed -root-access = [] # Enable tests requesting root access -tedge-user = [] # Enable tests requesting a tedge user -openrc = [] # Enable usage of OpenRC diff --git a/crates/core/tedge/tests/main.rs b/crates/core/tedge/tests/main.rs index f0a711d6..0a22c504 100644 --- a/crates/core/tedge/tests/main.rs +++ b/crates/core/tedge/tests/main.rs @@ -1,5 +1,3 @@ -mod os_related; - mod tests { use predicates::prelude::*; use test_case::test_case; diff --git a/crates/core/tedge/tests/os_related/mod.rs b/crates/core/tedge/tests/os_related/mod.rs deleted file mode 100644 index 1539e0f4..00000000 --- a/crates/core/tedge/tests/os_related/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -#[cfg(target_os = "linux")] -pub mod unix; - -#[cfg(target_os = "linux")] -pub use unix::*; diff --git a/crates/core/tedge/tests/os_related/unix.rs b/crates/core/tedge/tests/os_related/unix.rs deleted file mode 100644 index d8bb699d..00000000 --- a/crates/core/tedge/tests/os_related/unix.rs +++ /dev/null @@ -1,122 +0,0 @@ -fn _command_as_root<I, S>( - home_dir: &str, - args: I, -) -> Result<std::process::Command, Box<dyn std::error::Error>> -where - I: IntoIterator<Item = S>, - S: AsRef<std::ffi::OsStr>, -{ - let sudo = which::which("sudo")?; - let mut command = std::process::Command::new(sudo); - command.env("HOME", home_dir).arg("-s").args(args); - - Ok(command) -} - -#[test] -#[cfg(feature = "mosquitto-available")] -#[cfg(feature = "root-access")] -#[cfg(feature = "tedge-user")] -fn create_certificate_as_root_should_switch_to_mosquitto() -> Result<(), Box<dyn std::error::Error>> -{ - let device_id = "test"; - let tedge_dir = tempfile::tempdir()?; - let mosquitto_dir = tempfile::tempdir()?; - let cert_path = _temp_path(&mosquitto_dir, "test-cert.pem"); - let key_path = _temp_path(&mosquitto_dir, "test-key.pem"); - let tedge_home = tedge_dir.path().to_str().unwrap(); - let mosquitto_home = mosquitto_dir.path().to_str().unwrap(); - - // We cannot easily test `sudo tedge` as long as the tedge command has no option to use a specific config. - // 1) sudo reset $HOME to be /root, and tedge expect than its config to be in "/root/.tedge/tedge.toml" - // 2) the plan for `sudo tedge` is to use a fix path "/etc/tedge/tedge.toml". - // In both cases, the tests break the system config. - // => The solution is to add a --config option to the tedge command. - let tedge_config_path = String::from("/root/.tedge/tedge.toml"); - - let tedge = env!("CARGO_BIN_EXE_tedge"); - - let mut chown_mosquitto = _command_as_root( - &mosquitto_home, - &["chown", "mosquitto:mosquitto", &mosquitto_home], - )?; - let mut chown_tedge = _command_as_root(&tedge_home, &["chown", "tedge:tedge", &tedge_home])?; - let mut set_cert_path_cmd = _command_as_root( - &tedge_home, - &[tedge, "config", "set", "device.cert.path", &cert_path], - )?; - let mut set_key_path_cmd = _command_as_root( - &tedge_home, - &[tedge, "config", "set", "device.key.path", &key_path], - )?; - - let mut create_cmd = _command_as_root( - &tedge_home, - &[tedge, "cert", "create", "--device-id", device_id], - )?; - - // Run the commands to configure tedge - assert!(chown_mosquitto.output()?.status.success()); - assert!(chown_tedge.output()?.status.success()); - assert!(set_cert_path_cmd.output()?.status.success()); - assert!(set_key_path_cmd.output()?.status.success()); - - // Create the certificate - assert!(create_cmd.output()?.status.success()); - - let cert_metadata = std::fs::metadata(cert_path)?; - let key_metadata = std::fs::metadata(key_path)?; - let config_metadata = std::fs::metadata(tedge_config_path)?; - - assert_eq!( - "mosquitto", - users::get_user_by_uid(cert_metadata.st_uid()) - .unwrap() - .name() - ); - assert_eq!( - "mosquitto", - users::get_group_by_gid(cert_metadata.st_gid()) - .unwrap() - .name() - ); - assert_eq!(0o444, _extract_mode(cert_metadata.st_mode())); - - assert_eq!( - "mosquitto", - users::get_user_by_uid(key_metadata.st_uid()) - .unwrap() - .name() - ); - assert_eq!( - "mosquitto", - users::get_group_by_gid(key_metadata.st_gid()) - .unwrap() - .name() - ); - assert_eq!(0o400, _extract_mode(key_metadata.st_mode())); - - assert_eq!( - "tedge", - users::get_user_by_uid(config_metadata.st_uid()) - .unwrap() - .name() - ); - assert_eq!( - "tedge", - users::get_group_by_gid(config_metadata.st_gid()) - .unwrap() - .name() - ); - assert_eq!(0o600, _extract_mode(config_metadata.st_mode())); - - Ok(()) -} - -fn _extract_mode(st_type_and_mode: u32) -> u32 { - st_type_and_mode % 0o1000 -} - -fn _temp_path(dir: &tempfile::TempDir, filename: &str) -> String { - String::from(dir.path().join(filename).to_str().unwrap()) -} |