summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2017-06-17 23:22:07 -0400
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2017-06-17 23:22:07 -0400
commita1a820f60999c7db81731c0c92efcbb90932c0f6 (patch)
treeaf72d115ba1595344b6e78890db8fc56da3482c8
parent9bd1a176e4eb83ee54efc462b319537a5efe1603 (diff)
fix: Authentication unit test.
-rw-r--r--src/auth/mod.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/auth/mod.rs b/src/auth/mod.rs
index 2f4c313..723427c 100644
--- a/src/auth/mod.rs
+++ b/src/auth/mod.rs
@@ -19,9 +19,6 @@ pub fn encode(salt: &str, pw: &str) -> HashedPassword {
}
pub fn validate(pw: &str, enc: &HashedPassword) -> bool {
- // let cs = enc.split('$');
- // println("{:?}", cs.len());
- // let enc_pw = cs[3];
encode(enc.salt.as_str(), pw) == *enc
}
@@ -30,7 +27,12 @@ mod tests {
use super::*;
#[test]
fn it_validates() {
- assert_eq!(false, validate("hello", "123", "123"));
- assert_eq!(true, validate("hello", "123", &encode("hello", "123")));
+ assert_eq!(false,
+ validate("hello",
+ &HashedPassword {
+ salt: String::from("123"),
+ enc: String::from("123"),
+ }));
+ assert_eq!(true, validate("123", &encode("hello", "123")));
}
}