Skip to content

Commit

Permalink
Add tests for ROBOCORP_HOME base
Browse files Browse the repository at this point in the history
CMK-20325
  • Loading branch information
jherbel committed Nov 26, 2024
1 parent 2bf4137 commit cb8544b
Showing 1 changed file with 64 additions and 4 deletions.
68 changes: 64 additions & 4 deletions tests/test_scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::helper::{await_plan_results, directory_entries, var};
use crate::rcc::read_configuration_diagnostics;
use anyhow::{bail, Result as AnyhowResult};
use assert_cmd::cargo::cargo_bin;
use assert_cmd::output::OutputOkExt;

Check failure on line 7 in tests/test_scheduler.rs

View workflow job for this annotation

GitHub Actions / tests / x86_64-unknown-linux-gnu (ubuntu-latest)

unused import: `assert_cmd::output::OutputOkExt`

Check warning on line 7 in tests/test_scheduler.rs

View workflow job for this annotation

GitHub Actions / tests / x86_64-unknown-linux-gnu (ubuntu-latest)

unused import: `assert_cmd::output::OutputOkExt`

Check failure on line 7 in tests/test_scheduler.rs

View workflow job for this annotation

GitHub Actions / tests / x86_64-unknown-linux-gnu (ubuntu-latest)

unused import: `assert_cmd::output::OutputOkExt`

Check warning on line 7 in tests/test_scheduler.rs

View workflow job for this annotation

GitHub Actions / tests / x86_64-unknown-linux-gnu (ubuntu-latest)

unused import: `assert_cmd::output::OutputOkExt`

Check warning on line 7 in tests/test_scheduler.rs

View workflow job for this annotation

GitHub Actions / system_tests / windows

unused import: `assert_cmd::output::OutputOkExt`

Check warning on line 7 in tests/test_scheduler.rs

View workflow job for this annotation

GitHub Actions / system_tests / linux

unused import: `assert_cmd::output::OutputOkExt`

Check warning on line 7 in tests/test_scheduler.rs

View workflow job for this annotation

GitHub Actions / system_tests / linux

unused import: `assert_cmd::output::OutputOkExt`

Check warning on line 7 in tests/test_scheduler.rs

View workflow job for this annotation

GitHub Actions / system_tests / windows

unused import: `assert_cmd::output::OutputOkExt`
use camino::{Utf8Path, Utf8PathBuf};
#[cfg(windows)]
use robotmk::config::UserSessionConfig;
Expand All @@ -19,6 +20,8 @@ use serde_json::to_string;
use std::ffi::OsStr;
use std::fs::{create_dir_all, remove_file, write};
use std::path::Path;
#[cfg(windows)]
use std::process::Output;
use std::time::Duration;
use tokio::{
process::Command,
Expand Down Expand Up @@ -115,6 +118,12 @@ async fn test_scheduler() -> AnyhowResult<()> {
.join("plans")
.join(&config.plan_groups[0].plans[1].id),
);
assert_robocorp_home(
&config.rcc_config.robocorp_home_base,
#[cfg(windows)]
&current_user_name,
)
.await?;

Ok(())
}
Expand Down Expand Up @@ -518,11 +527,19 @@ async fn assert_working_directory(
}

#[cfg(windows)]
async fn get_permissions(path: impl AsRef<OsStr>) -> AnyhowResult<String> {
async fn run_icacls<I, S>(args: I) -> std::io::Result<Output>
where
I: IntoIterator<Item = S>,
S: AsRef<OsStr>,
{
let mut icacls_command = Command::new("icacls.exe");
icacls_command.arg(path);
let permissions = String::from_utf8(icacls_command.output().await?.stdout)?;
Ok(permissions)
icacls_command.args(args);
icacls_command.output().await
}

#[cfg(windows)]
async fn get_permissions(path: impl AsRef<OsStr>) -> AnyhowResult<String> {
Ok(String::from_utf8(run_icacls(&[path]).await?.stdout)?)
}

#[cfg(windows)]
Expand Down Expand Up @@ -660,3 +677,46 @@ fn assert_sequentiality(
dir_entries_second_plan.sort();
assert!(dir_entries_first_plan[0] < dir_entries_second_plan[0]);
}

async fn assert_robocorp_home(
robocorp_home_base: &Utf8Path,
#[cfg(windows)] headed_user_name: &str,
) -> AnyhowResult<()> {
assert!(robocorp_home_base.is_dir());
assert_eq!(
directory_entries(robocorp_home_base, 1),
[
"current_user",
#[cfg(windows)]
&format!("user_{headed_user_name}"),
]
);
#[cfg(windows)]
{
let permissions_robocorp_home_base = get_permissions(robocorp_home_base).await?;
assert_eq!(
permissions_robocorp_home_base
.lines()
.collect::<Vec<&str>>()
.len(),
3 // Administrator group + empty line + success message (suppressing the latter with /q does not seem to work)
);
assert!(
run_icacls([robocorp_home_base.as_str(), "/findsid", "\"*S-1-5-32-544\""])
.await?
.status
.success()
);
assert!(
get_permissions(robocorp_home_base.join(format!("user_{headed_user_name}")))
.await?
.contains(&format!("{headed_user_name}:(OI)(CI)(F)",))
);
assert!(
get_permissions(robocorp_home_base.join(format!("user_{headed_user_name}")))
.await?
.contains(&format!("{headed_user_name}:(OI)(CI)(F)",))
);
}
Ok(())
}

0 comments on commit cb8544b

Please sign in to comment.