|
|
|
mod helpers;
|
|
|
|
|
|
|
|
use helpers::{AgentClient, Panel};
|
|
|
|
|
|
|
|
use serde_json::json;
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
type TestResult<R = ()> = Result<R, Box<dyn std::error::Error>>;
|
|
|
|
|
|
|
|
async fn register_agent() -> Uuid {
|
|
|
|
let cli = AgentClient::new();
|
|
|
|
let agent_uid = Uuid::new_v4();
|
|
|
|
let resp = cli.get(format!("get_agent_jobs/{}", agent_uid)).await;
|
|
|
|
let job_id = &resp["job_id"];
|
|
|
|
let resp = cli.get(format!("get_jobs/{}", job_id)).await;
|
|
|
|
assert_eq!(&resp["alias"], "agent_hello");
|
|
|
|
let agent_data = json! {
|
|
|
|
{"id": &agent_uid,"inner":[
|
|
|
|
{"Agent":
|
|
|
|
{"alias":null,
|
|
|
|
"hostname":"3b1030fa6324",
|
|
|
|
"id":&agent_uid,
|
|
|
|
"is_root":false,
|
|
|
|
"is_root_allowed":false,
|
|
|
|
"last_active":{"secs_since_epoch":1625271265,"nanos_since_epoch":92814921},
|
|
|
|
"platform":"x86_64-unknown-linux-gnu",
|
|
|
|
"regtime":{"secs_since_epoch":1625271265,"nanos_since_epoch":92814945},
|
|
|
|
"state":"New",
|
|
|
|
"token":null,
|
|
|
|
"username":"root"}
|
|
|
|
}]}
|
|
|
|
};
|
|
|
|
cli.post("report", &agent_data).await;
|
|
|
|
agent_uid
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_first_connection() -> TestResult {
|
|
|
|
let uid = register_agent().await;
|
|
|
|
let agents = Panel::check_output("agents list");
|
|
|
|
dbg!(&agents);
|
|
|
|
assert_eq!(agents.len(), 2);
|
|
|
|
let found = agents
|
|
|
|
.iter()
|
|
|
|
.find(|v| v["id"].as_str().unwrap() == uid.to_string());
|
|
|
|
assert!(found.is_some());
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_setup_tasks() -> TestResult {
|
|
|
|
register_agent().await;
|
|
|
|
Ok(())
|
|
|
|
}
|