From 5e2f651400971d610ef76918e6f6366b01071e60 Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Sun, 9 Oct 2022 19:41:15 +0200 Subject: Add first integration test. --- tests/password_generation.rs | 76 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/password_generation.rs (limited to 'tests') diff --git a/tests/password_generation.rs b/tests/password_generation.rs new file mode 100644 index 0000000..45c6afa --- /dev/null +++ b/tests/password_generation.rs @@ -0,0 +1,76 @@ +use passwordmaker_rs::{PasswordMaker, Hasher, HasherList, HashAlgorithm}; +use digest::Digest; +use md4; +use md5; +use sha1; +use sha2; +use ripemd; + +struct Md4; +struct Md5; +struct Sha1; +struct Sha256; +struct RipeMD160; +impl Hasher for Md4{ + type Output = [u8;16]; + fn hash(data : &[u8]) -> Self::Output { + md4::Md4::digest(data).into() + } +} +impl Hasher for Md5{ + type Output = [u8;16]; + fn hash(data : &[u8]) -> Self::Output { + md5::Md5::digest(data).into() + } +} +impl Hasher for Sha1{ + type Output = [u8;20]; + fn hash(data : &[u8]) -> Self::Output { + sha1::Sha1::digest(data).into() + } +} +impl Hasher for Sha256{ + type Output = [u8;32]; + fn hash(data : &[u8]) -> Self::Output { + sha2::Sha256::digest(data).into() + } +} +impl Hasher for RipeMD160{ + type Output = [u8;20]; + fn hash(data : &[u8]) -> Self::Output { + ripemd::Ripemd160::digest(data).into() + } +} + +impl passwordmaker_rs::Md4 for Md4{} +impl passwordmaker_rs::Md5 for Md5{} +impl passwordmaker_rs::Sha1 for Sha1{} +impl passwordmaker_rs::Sha256 for Sha256{} +impl passwordmaker_rs::Ripemd160 for RipeMD160{} + +struct Hashes{} +impl HasherList for Hashes { + type MD4 = Md4; + type MD5 = Md5; + type SHA1 = Sha1; + type SHA256 = Sha256; + type RIPEMD160 = RipeMD160; +} + +type Pwm<'a> = PasswordMaker<'a, Hashes>; + +#[test] +fn default_settings() { + let pwm = Pwm::new( + HashAlgorithm::Md5, + passwordmaker_rs::UseLeetWhenGenerating::NotAtAll, + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./", + "", + "", + 8, + "", + "" + ).unwrap(); + let result = pwm.generate(".abcdefghij".to_owned(), "1".to_owned()).unwrap(); + assert_eq!(result, "J3>'1F\"/"); +} \ No newline at end of file -- cgit v1.2.3