Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 7aac0083 authored by Pierre Jarriges's avatar Pierre Jarriges
Browse files

fix appstate testing

parent a6f5b850
No related branches found
No related tags found
No related merge requests found
......@@ -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"),
}
}
}
......@@ -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)]
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment