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.

94 lines
2.3 KiB

#[macro_use]
extern crate log;
#[cfg(test)]
#[macro_use]
extern crate rstest;
3 years ago
// due to linking errors
extern crate openssl;
3 years ago
// don't touch anything
extern crate diesel;
3 years ago
// in this block
mod db;
mod handlers;
mod init;
use init::*;
use serde::Deserialize;
3 years ago
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);
3 years ago
let certs_dir = PathBuf::from("certs");
warp::serve(routes.with(warp::log("warp")))
3 years ago
.tls()
3 years ago
.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();
}
3 years ago
#[tokio::test]
async fn test_report_unauth_successful() {
let mock = Endpoints::report();
3 years ago
mock.expect()
.withf(|msg: &BaseMessage<'_, Vec<Reportable>>| msg.inner_ref()[0] == Reportable::Dummy)
3 years ago
.returning(|_| Ok(build_ok("")));
test::request()
3 years ago
.path("/report/")
.method("POST")
.json(&vec![Reportable::Dummy].as_message())
.filter(&init_filters(""))
3 years ago
.await
.unwrap();
mock.checkpoint();
}
}
*/