Remove the fallibility testing code

It's being handled in a different branch
This commit is contained in:
Savanni D'Gerinel 2022-11-25 12:49:26 -05:00
parent 064b754786
commit deb3415c30
4 changed files with 10 additions and 88 deletions

12
server/Cargo.lock generated
View File

@ -103,17 +103,6 @@ dependencies = [
"crypto-common", "crypto-common",
] ]
[[package]]
name = "fail"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe5e43d0f78a42ad591453aedb1d7ae631ce7ee445c7643691055a9ed8d3b01c"
dependencies = [
"log",
"once_cell",
"rand",
]
[[package]] [[package]]
name = "fallible-iterator" name = "fallible-iterator"
version = "0.2.0" version = "0.2.0"
@ -727,7 +716,6 @@ name = "server"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"fail",
"rand", "rand",
"rusqlite", "rusqlite",
"serde", "serde",

View File

@ -8,7 +8,6 @@ default-run = "server"
[dependencies] [dependencies]
anyhow = { version = "1" } anyhow = { version = "1" }
fail = { version = "0.5" }
rand = { version = "0.8" } rand = { version = "0.8" }
rusqlite = { version = "0.26" } rusqlite = { version = "0.26" }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }

View File

@ -1,5 +1,4 @@
use crate::errors::{error, fatal, ok, AppResult, FatalError}; use crate::errors::{error, fatal, ok, AppResult, FatalError};
use fail::fail_point;
use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ValueRef}; use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ValueRef};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashMap; use std::collections::HashMap;
@ -7,9 +6,6 @@ use std::{convert::Infallible, str::FromStr};
use thiserror::Error; use thiserror::Error;
use uuid::{adapter::Hyphenated, Uuid}; use uuid::{adapter::Hyphenated, Uuid};
#[cfg(test)]
use crate::errors::maybe_fail;
#[derive(Debug, Error, PartialEq)] #[derive(Debug, Error, PartialEq)]
pub enum AuthenticationError { pub enum AuthenticationError {
#[error("username already exists")] #[error("username already exists")]
@ -180,8 +176,6 @@ pub struct MemoryAuth {
impl AuthenticationDB for MemoryAuth { impl AuthenticationDB for MemoryAuth {
fn create_user(&mut self, username: Username) -> AppResult<UserId, AuthenticationError> { fn create_user(&mut self, username: Username) -> AppResult<UserId, AuthenticationError> {
fail_point!("create-user", |_| Err(FatalError::DiskFull));
if self.users.contains_key(&username) { if self.users.contains_key(&username) {
return Ok(Err(AuthenticationError::DuplicateUsername)); return Ok(Err(AuthenticationError::DuplicateUsername));
} }
@ -194,9 +188,6 @@ impl AuthenticationDB for MemoryAuth {
} }
fn create_invitation(&mut self, user: &UserId) -> AppResult<Invitation, AuthenticationError> { fn create_invitation(&mut self, user: &UserId) -> AppResult<Invitation, AuthenticationError> {
#[cfg(test)]
let _ = maybe_fail::<AuthenticationError>(vec![])?;
if !self.inverse_users.contains_key(&user) { if !self.inverse_users.contains_key(&user) {
return error::<Invitation, AuthenticationError>(AuthenticationError::UserNotFound); return error::<Invitation, AuthenticationError>(AuthenticationError::UserNotFound);
} }
@ -211,9 +202,6 @@ impl AuthenticationDB for MemoryAuth {
&mut self, &mut self,
invitation: Invitation, invitation: Invitation,
) -> AppResult<SessionToken, AuthenticationError> { ) -> AppResult<SessionToken, AuthenticationError> {
#[cfg(test)]
let _ = maybe_fail::<AuthenticationError>(vec![])?;
if let Some(user) = self.invitations.get(&invitation) { if let Some(user) = self.invitations.get(&invitation) {
let session_token = let session_token =
SessionToken::from(format!("{}", Hyphenated::from_uuid(Uuid::new_v4())).as_str()); SessionToken::from(format!("{}", Hyphenated::from_uuid(Uuid::new_v4())).as_str());
@ -226,9 +214,6 @@ impl AuthenticationDB for MemoryAuth {
} }
fn delete_session(&mut self, session: SessionToken) -> AppResult<(), AuthenticationError> { fn delete_session(&mut self, session: SessionToken) -> AppResult<(), AuthenticationError> {
#[cfg(test)]
let _ = maybe_fail::<AuthenticationError>(vec![])?;
if let Some(_) = self.sessions.remove(&session) { if let Some(_) = self.sessions.remove(&session) {
ok(()) ok(())
} else { } else {
@ -237,9 +222,6 @@ impl AuthenticationDB for MemoryAuth {
} }
fn delete_invitation(&mut self, invitation: Invitation) -> AppResult<(), AuthenticationError> { fn delete_invitation(&mut self, invitation: Invitation) -> AppResult<(), AuthenticationError> {
#[cfg(test)]
let _ = maybe_fail::<AuthenticationError>(vec![])?;
if let Some(_) = self.invitations.remove(&invitation) { if let Some(_) = self.invitations.remove(&invitation) {
ok(()) ok(())
} else { } else {
@ -248,9 +230,6 @@ impl AuthenticationDB for MemoryAuth {
} }
fn delete_user(&mut self, user: UserId) -> AppResult<(), AuthenticationError> { fn delete_user(&mut self, user: UserId) -> AppResult<(), AuthenticationError> {
#[cfg(test)]
let _ = maybe_fail::<AuthenticationError>(vec![])?;
if let Some(username) = self.inverse_users.remove(&user) { if let Some(username) = self.inverse_users.remove(&user) {
let _ = self.users.remove(&username); let _ = self.users.remove(&username);
self.invitations = self self.invitations = self
@ -310,7 +289,6 @@ impl AuthenticationDB for MemoryAuth {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use fail::FailScenario;
use std::panic; use std::panic;
fn with_memory_db<F>(test: F) fn with_memory_db<F>(test: F)
@ -321,19 +299,6 @@ mod test {
test(authdb); test(authdb);
} }
fn with_failpoints<F>(failpoints: Vec<&str>, test: F)
where
F: Fn() -> () + panic::UnwindSafe,
{
let scenario = FailScenario::setup();
for fp in failpoints {
fail::cfg(fp, "return()").unwrap();
}
let result = panic::catch_unwind(test);
scenario.teardown();
assert!(result.is_ok())
}
#[test] #[test]
fn it_can_create_a_user() { fn it_can_create_a_user() {
fn test_case(mut authdb: Box<dyn AuthenticationDB>) { fn test_case(mut authdb: Box<dyn AuthenticationDB>) {
@ -347,7 +312,7 @@ mod test {
assert!(authdb.list_users().unwrap().unwrap().contains(&userid)); assert!(authdb.list_users().unwrap().unwrap().contains(&userid));
} }
with_failpoints(vec![], || with_memory_db(test_case)); with_memory_db(test_case);
} }
#[test] #[test]
@ -363,7 +328,7 @@ mod test {
Err(AuthenticationError::DuplicateUsername) Err(AuthenticationError::DuplicateUsername)
); );
} }
with_failpoints(vec![], || with_memory_db(test_case)); with_memory_db(test_case);
} }
#[test] #[test]
@ -383,7 +348,7 @@ mod test {
.expect("no fatal errors") .expect("no fatal errors")
.expect("to receive a session token"); .expect("to receive a session token");
} }
with_failpoints(vec![], || with_memory_db(test_case)); with_memory_db(test_case);
} }
#[test] #[test]
@ -413,7 +378,7 @@ mod test {
(garrus, garrus_id) (garrus, garrus_id)
); );
} }
with_failpoints(vec![], || with_memory_db(test_case)); with_memory_db(test_case);
} }
#[test] #[test]
@ -429,7 +394,7 @@ mod test {
authdb.authenticate(invite1).unwrap().unwrap(); authdb.authenticate(invite1).unwrap().unwrap();
authdb.authenticate(invite2).unwrap().unwrap(); authdb.authenticate(invite2).unwrap().unwrap();
} }
with_failpoints(vec![], || with_memory_db(test_case)); with_memory_db(test_case);
} }
#[test] #[test]
@ -455,7 +420,7 @@ mod test {
(username, userid) (username, userid)
); );
} }
with_failpoints(vec![], || with_memory_db(test_case)); with_memory_db(test_case);
} }
#[test] #[test]
@ -477,7 +442,7 @@ mod test {
let reuse_result = authdb.authenticate(invitation).expect("no fatal errors"); let reuse_result = authdb.authenticate(invitation).expect("no fatal errors");
assert_eq!(reuse_result, Err(AuthenticationError::InvalidInvitation)); assert_eq!(reuse_result, Err(AuthenticationError::InvalidInvitation));
} }
with_failpoints(vec![], || with_memory_db(test_case)); with_memory_db(test_case);
} }
#[test] #[test]
@ -509,7 +474,7 @@ mod test {
Err(AuthenticationError::InvalidInvitation) Err(AuthenticationError::InvalidInvitation)
); );
} }
with_failpoints(vec![], || with_memory_db(test_case)); with_memory_db(test_case);
} }
#[test] #[test]
@ -532,7 +497,7 @@ mod test {
Err(AuthenticationError::InvalidSession) Err(AuthenticationError::InvalidSession)
); );
} }
with_failpoints(vec![], || with_memory_db(test_case)); with_memory_db(test_case);
} }
#[test] #[test]
@ -557,6 +522,6 @@ mod test {
Err(AuthenticationError::InvalidInvitation) Err(AuthenticationError::InvalidInvitation)
); );
} }
with_failpoints(vec![], || with_memory_db(test_case)); with_memory_db(test_case);
} }
} }

View File

@ -1,4 +1,3 @@
use rand::prelude::Distribution;
use thiserror::Error; use thiserror::Error;
/// This struct covers *fatal* errors for the application. Cross-functional things like full disks, /// This struct covers *fatal* errors for the application. Cross-functional things like full disks,
@ -14,11 +13,6 @@ pub enum FatalError {
Io(std::io::Error), Io(std::io::Error),
} }
/*
#[cfg(test)]
const FATAL_ERRORS: [FatalError; 2] = [FatalError::DatabaseInconsistency, FatalError::DiskFull];
*/
pub type AppResult<A, E> = Result<Result<A, E>, FatalError>; pub type AppResult<A, E> = Result<Result<A, E>, FatalError>;
pub fn ok<A, E>(val: A) -> AppResult<A, E> { pub fn ok<A, E>(val: A) -> AppResult<A, E> {
@ -32,27 +26,3 @@ pub fn error<A, E>(err: E) -> AppResult<A, E> {
pub fn fatal<A, E>(err: FatalError) -> AppResult<A, E> { pub fn fatal<A, E>(err: FatalError) -> AppResult<A, E> {
Err(err) Err(err)
} }
/*
#[cfg(test)]
use rand::{distributions::Uniform, thread_rng, Rng};
*/
#[cfg(test)]
pub fn maybe_fail<E>(_module_errors: Vec<E>) -> AppResult<(), E> {
/*
let percentage = Uniform::new(0, 100);
let module_error_dist = Uniform::new(0, module_errors.len());
let fatal_error_dist = Uniform::new(0, FATAL_ERRORS.len());
if thread_rng().sample(percentage) < 10 {
if module_errors.len() > 0 && thread_rng().sample(percentage) < 75 {
// return Ok(Err(module_errors[thread_rng().sample(module_error_dist)]));
return ok(());
} else {
return Err(FATAL_ERRORS[thread_rng().sample(fatal_error_dist)]);
}
}
*/
ok(())
}