|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
#[macro_use]
|
|
|
|
extern crate rstest;
|
|
|
|
|
|
|
|
// due to linking errors
|
|
|
|
extern crate openssl;
|
|
|
|
// don't touch anything
|
|
|
|
extern crate diesel;
|
|
|
|
// in this block
|
|
|
|
|
|
|
|
mod db;
|
|
|
|
mod handlers;
|
|
|
|
mod init;
|
|
|
|
|
|
|
|
use init::*;
|
|
|
|
use serde::Deserialize;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use u_lib::{config::MASTER_PORT, utils::load_env};
|
|
|
|
use warp::Filter;
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
struct ServEnv {
|
|
|
|
admin_auth_token: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: tracing-subscriber
|
|
|
|
pub async fn serve() -> Result<(), String> {
|
|
|
|
init_logger();
|
|
|
|
prefill_jobs();
|
|
|
|
|
|
|
|
let env = load_env::<ServEnv>().map_err(|e| e.to_string())?;
|
|
|
|
let routes = init_filters(&env.admin_auth_token);
|
|
|
|
let certs_dir = PathBuf::from("certs");
|
|
|
|
warp::serve(routes.with(warp::log("warp")))
|
|
|
|
.tls()
|
|
|
|
.cert_path(certs_dir.join("server.crt"))
|
|
|
|
.key_path(certs_dir.join("server.key"))
|
|
|
|
.client_auth_required_path(certs_dir.join("ca.crt"))
|
|
|
|
.run(([0, 0, 0, 0], MASTER_PORT))
|
|
|
|
.await;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
use crate::handlers::Endpoints;
|
|
|
|
use handlers::build_ok;
|
|
|
|
use u_lib::messaging::{AsMsg, BaseMessage, Reportable};
|
|
|
|
use uuid::Uuid;
|
|
|
|
use warp::test;
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
#[case(Some(Uuid::new_v4()))]
|
|
|
|
#[should_panic]
|
|
|
|
#[case(None)]
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_get_agent_jobs_unauthorized(#[case] uid: Option<Uuid>) {
|
|
|
|
let mock = Endpoints::faux();
|
|
|
|
when!(mock.get_agent_jobs).then_return(Ok(build_ok("")));
|
|
|
|
//mock.expect().with(eq(uid)).returning(|_| Ok(build_ok("")));
|
|
|
|
test::request()
|
|
|
|
.path(&format!(
|
|
|
|
"/get_agent_jobs/{}",
|
|
|
|
uid.map(|u| u.simple().to_string()).unwrap_or(String::new())
|
|
|
|
))
|
|
|
|
.method("GET")
|
|
|
|
.filter(&init_filters(""))
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_report_unauth_successful() {
|
|
|
|
let mock = Endpoints::report();
|
|
|
|
mock.expect()
|
|
|
|
.withf(|msg: &BaseMessage<'_, Vec<Reportable>>| msg.inner_ref()[0] == Reportable::Dummy)
|
|
|
|
.returning(|_| Ok(build_ok("")));
|
|
|
|
test::request()
|
|
|
|
.path("/report/")
|
|
|
|
.method("POST")
|
|
|
|
.json(&vec![Reportable::Dummy].as_message())
|
|
|
|
.filter(&init_filters(""))
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
mock.checkpoint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|