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",
]
[[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]]
name = "fallible-iterator"
version = "0.2.0"
@ -727,7 +716,6 @@ name = "server"
version = "0.1.0"
dependencies = [
"anyhow",
"fail",
"rand",
"rusqlite",
"serde",

View File

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

View File

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