You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.6 KiB
82 lines
2.6 KiB
use crate::fixtures::agent::*; |
|
use crate::helpers::{jobs::retry_with_interval, Panel}; |
|
|
|
use rstest::rstest; |
|
use serde_json::to_string; |
|
use u_lib::config::AGENT_ITERATION_INTERVAL; |
|
use u_lib::models::*; |
|
use uuid::Uuid; |
|
|
|
#[rstest] |
|
#[tokio::test] |
|
async fn registration(registered_agent: &RegisteredAgent) { |
|
let agents: Vec<Agent> = Panel::check_output("agents read"); |
|
let found = agents.iter().find(|v| v.id == registered_agent.id); |
|
assert!(found.is_some()); |
|
Panel::check_status(format!("agents delete {}", registered_agent.id)); |
|
} |
|
|
|
#[tokio::test] |
|
async fn setup_tasks() { |
|
let agents: Vec<Agent> = Panel::check_output("agents read"); |
|
let agent_id = agents[0].id; |
|
let job_alias = "passwd_contents"; |
|
let job = RawJob::builder() |
|
.with_alias(job_alias) |
|
.with_raw_payload("cat /etc/passwd") |
|
.with_shell("/bin/bash {}") |
|
.with_target_platforms("*linux*") |
|
.build() |
|
.unwrap(); |
|
|
|
Panel::check_status(["jobs", "create", &to_string(&RawJob::from(job)).unwrap()]); |
|
|
|
let cmd = format!("map create {agent_id} {job_alias}"); |
|
let assigned_ids: Vec<Uuid> = Panel::check_output(cmd); |
|
|
|
retry_with_interval(5, AGENT_ITERATION_INTERVAL, || { |
|
let result = |
|
Panel::check_output::<Vec<AssignedJob>>(format!("map read {}", assigned_ids[0])) |
|
.remove(0); |
|
if result.state == JobState::Finished { |
|
eprintln!("{}", result.to_str_result()); |
|
assert!(result.to_str_result().contains("root:x:0:0")); |
|
Ok(()) |
|
} else { |
|
Err("job didn't finish") |
|
} |
|
}) |
|
.await; |
|
} |
|
|
|
#[tokio::test] |
|
async fn large_payload() { |
|
let agent = &Panel::check_output::<Vec<Agent>>("agents read")[0]; |
|
let agent_id = agent.id; |
|
let job_alias = "large_payload"; |
|
let job = RawJob::builder() |
|
.with_alias(job_alias) |
|
.with_payload_path("./tests/bin/echoer") |
|
.with_shell("{} type echo") |
|
.with_target_platforms(&agent.platform) |
|
.build() |
|
.unwrap(); |
|
|
|
Panel::check_status(["jobs", "create", &to_string(&RawJob::from(job)).unwrap()]); |
|
|
|
let cmd = format!("map create {agent_id} {job_alias}"); |
|
let assigned_ids: Vec<Uuid> = Panel::check_output(cmd); |
|
|
|
retry_with_interval(5, AGENT_ITERATION_INTERVAL, || { |
|
let result = |
|
Panel::check_output::<Vec<AssignedJob>>(format!("map read {}", assigned_ids[0])) |
|
.remove(0); |
|
if result.state == JobState::Finished { |
|
assert_eq!(result.to_str_result(), "type echo\n"); |
|
Ok(()) |
|
} else { |
|
Err("job didn't finish") |
|
} |
|
}) |
|
.await; |
|
}
|
|
|