diff options
Diffstat (limited to 'src/test.rs')
| -rw-r--r-- | src/test.rs | 48 |
1 files changed, 17 insertions, 31 deletions
diff --git a/src/test.rs b/src/test.rs index 3d54d71..f9c6981 100644 --- a/src/test.rs +++ b/src/test.rs @@ -18,17 +18,17 @@ #[cfg(test)] mod core { use crate::{ - IOModule, cmd_add_user, cmd_authenticate_cookie, cmd_init, cmd_repo_user_control, + authentication::{ + IOModule, cmd_add_user, cmd_authenticate_cookie, cmd_init, cmd_repo_user_control, + }, datastructures::{Config, TestSuite, rand_str}, get_arg_matches, }; use argon2::{ Argon2, - password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, SaltString}, + password_hash::{PasswordHasher, PasswordVerifier, phc::PasswordHash}, }; use redis::AsyncCommands; - #[cfg(feature = "pam")] - use std::borrow::BorrowMut; use std::io::{Read, Write}; use std::path::Path; use std::path::PathBuf; @@ -37,13 +37,11 @@ mod core { #[test] fn test_argon2() { - use argon2::password_hash::rand_core::OsRng; let passwd = b"hunter2"; - let salt = SaltString::generate(&mut OsRng); let argon2 = Argon2::default(); - argon2.hash_password(passwd, &salt).unwrap(); + argon2.hash_password(passwd).unwrap(); } #[test] @@ -55,8 +53,9 @@ mod core { } async fn async_test_redis() -> anyhow::Result<()> { - let redis_conn = redis::Client::open("redis://127.0.0.1/")?; - let mut conn = redis_conn.get_multiplexed_async_connection().await?; + let mut conn = + crate::datastructures::get_redis_connection(crate::datastructures::DEFAULT_REDIS_URL) + .await?; let s = rand_str(crate::datastructures::COOKIE_LENGTH); conn.set_ex::<_, _, String>("auth_test", &s, 60).await?; @@ -99,10 +98,7 @@ mod core { "/?p=login", ])); let mut output = Vec::new(); - let mut module = IOModule { - reader: &correct_input[..], - writer: &mut output, - }; + let mut module = IOModule::new(&correct_input[..], &mut output); let cfg = Config::generate_test_config(); @@ -347,10 +343,15 @@ mod core { } async fn clear_redis_setting() -> anyhow::Result<()> { - let client = redis::Client::open("redis://127.0.0.1")?; - let mut conn = client.get_multiplexed_async_connection().await?; + let mut conn = + crate::datastructures::get_redis_connection(crate::datastructures::DEFAULT_REDIS_URL) + .await?; - for key in &["cgit_repo_test", "cgit_repo_repo"] { + for key in &[ + "cgit_repo_test", + "cgit_repo_repo", + "cgit_auth_failed_hunter2", + ] { conn.del::<_, i32>(*key).await?; } Ok(()) @@ -367,19 +368,4 @@ mod core { .block_on(clear_redis_setting()) .unwrap(); } - - #[cfg(feature = "pam")] - #[ignore] - #[test] - fn test_pam() { - let service = option_env!("pam_service").unwrap_or("system-auth"); - let user = option_env!("pam_user").unwrap_or("user"); - let password = option_env!("pam_password").unwrap_or("password"); - - let mut auth = pam::Client::with_password(service).unwrap(); - auth.conversation_mut() - .borrow_mut() - .set_credentials(user, password); - assert!(auth.authenticate().is_ok() && auth.open_session().is_ok()) - } } |
