diff --git a/src/app/args.rs b/src/app/args.rs index 8fa78ef3728913f442ba67d5a66db071e558a570..a11ca92bc75ba38271de064cb4ea7834519955b2 100644 --- a/src/app/args.rs +++ b/src/app/args.rs @@ -33,3 +33,21 @@ pub struct AppArgs { #[structopt(long = "admin_cookie_name", default_value = "krustacea_admin_auth")] pub admin_cookie_name: String, } + +impl AppArgs { + #[cfg(test)] + pub fn testing() -> Self { + AppArgs { + context: String::from("debug"), + app_storage_root: None, + load: None, + host: String::from("localhost"), + port: 8080, + port_tls: 8443, + ssl_certs_dir: PathBuf::from("/etc/letsencrypt/live"), + admin_username: String::from("admin"), + admin_pwd: String::from("password"), + admin_cookie_name: String::from("krustacea_admin_auth"), + } + } +} diff --git a/src/app/state.rs b/src/app/state.rs index a6c29afd572942030bbd2273fdfceaaa7bb0b117..5b4347cc48dd41d7f514292ecf3db5bc9139d0e9 100644 --- a/src/app/state.rs +++ b/src/app/state.rs @@ -20,6 +20,17 @@ impl AppState { admin_auth_token: AdminAuthToken::new(admin_cookie_name), } } + + #[cfg(test)] + pub fn testing() -> Self { + let config = AppConfig::new(AppArgs::testing()); + let admin_cookie_name = config.admin_cookie_name.to_owned(); + AppState { + config, + preferences: AppPreferences {}, + admin_auth_token: AdminAuthToken::new(admin_cookie_name), + } + } } #[derive(Clone)] diff --git a/src/service/files.rs b/src/service/files.rs index f6972e333bce0c7284f5dc7260d39d0a7eb75c18..ced55d23c201022fe3dce733bee30a27efa8870a 100644 --- a/src/service/files.rs +++ b/src/service/files.rs @@ -172,7 +172,7 @@ mod test_static_files_services { #[actix_web::test] async fn post_files_unauthenticated_should_be_unauthorized() { - let app_state = AppState::new(); + let app_state = AppState::testing(); let static_dir = std::path::PathBuf::from("./test"); let ws = WebSiteBuilder::testing(&static_dir); @@ -180,6 +180,7 @@ mod test_static_files_services { App::new() .app_data(web::Data::new(RwLock::new(app_state.clone()))) .app_data(web::Data::new(RwLock::new(ws.clone()))) + .wrap(crate::middleware::AuthService {}) .service(post_files), ) .await;