parent
49a8e5c5a1
commit
1c1a823759
18
db/auth.rs
18
db/auth.rs
|
@ -809,18 +809,18 @@ mod tests {
|
||||||
(u.id, u.change())
|
(u.id, u.change())
|
||||||
};
|
};
|
||||||
let e = state.login_by_password(&conn, req.clone(), "slamb", "hunter2".to_owned(),
|
let e = state.login_by_password(&conn, req.clone(), "slamb", "hunter2".to_owned(),
|
||||||
b"nvr.example.com".to_vec(), 0).unwrap_err();
|
Some(b"nvr.example.com".to_vec()), 0).unwrap_err();
|
||||||
assert_eq!(format!("{}", e), "no password set for user \"slamb\"");
|
assert_eq!(format!("{}", e), "no password set for user \"slamb\"");
|
||||||
c.set_password("hunter2".to_owned());
|
c.set_password("hunter2".to_owned());
|
||||||
state.apply(&conn, c).unwrap();
|
state.apply(&conn, c).unwrap();
|
||||||
let e = state.login_by_password(&conn, req.clone(), "slamb",
|
let e = state.login_by_password(&conn, req.clone(), "slamb",
|
||||||
"hunter3".to_owned(),
|
"hunter3".to_owned(),
|
||||||
b"nvr.example.com".to_vec(), 0).unwrap_err();
|
Some(b"nvr.example.com".to_vec()), 0).unwrap_err();
|
||||||
assert_eq!(format!("{}", e), "incorrect password for user \"slamb\"");
|
assert_eq!(format!("{}", e), "incorrect password for user \"slamb\"");
|
||||||
let sid = {
|
let sid = {
|
||||||
let (sid, s) = state.login_by_password(&conn, req.clone(), "slamb",
|
let (sid, s) = state.login_by_password(&conn, req.clone(), "slamb",
|
||||||
"hunter2".to_owned(),
|
"hunter2".to_owned(),
|
||||||
b"nvr.example.com".to_vec(), 0).unwrap();
|
Some(b"nvr.example.com".to_vec()), 0).unwrap();
|
||||||
assert_eq!(s.user_id, uid);
|
assert_eq!(s.user_id, uid);
|
||||||
sid
|
sid
|
||||||
};
|
};
|
||||||
|
@ -859,7 +859,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
let sid = state.login_by_password(&conn, req.clone(), "slamb",
|
let sid = state.login_by_password(&conn, req.clone(), "slamb",
|
||||||
"hunter2".to_owned(),
|
"hunter2".to_owned(),
|
||||||
b"nvr.example.com".to_vec(), 0).unwrap().0;
|
Some(b"nvr.example.com".to_vec()), 0).unwrap().0;
|
||||||
state.authenticate_session(&conn, req.clone(), &sid.hash()).unwrap();
|
state.authenticate_session(&conn, req.clone(), &sid.hash()).unwrap();
|
||||||
|
|
||||||
// Reload.
|
// Reload.
|
||||||
|
@ -897,7 +897,7 @@ mod tests {
|
||||||
user_agent: Some(b"some ua".to_vec()),
|
user_agent: Some(b"some ua".to_vec()),
|
||||||
};
|
};
|
||||||
state.login_by_password(&conn, req.clone(), "slamb", "hunter2".to_owned(),
|
state.login_by_password(&conn, req.clone(), "slamb", "hunter2".to_owned(),
|
||||||
b"nvr.example.com".to_vec(), 0).unwrap();
|
Some(b"nvr.example.com".to_vec()), 0).unwrap();
|
||||||
let new_hash = {
|
let new_hash = {
|
||||||
// Password should have been automatically upgraded.
|
// Password should have been automatically upgraded.
|
||||||
let u = state.users_by_id().get(&uid).unwrap();
|
let u = state.users_by_id().get(&uid).unwrap();
|
||||||
|
@ -923,7 +923,7 @@ mod tests {
|
||||||
|
|
||||||
// Login should still work.
|
// Login should still work.
|
||||||
state.login_by_password(&conn, req.clone(), "slamb", "hunter2".to_owned(),
|
state.login_by_password(&conn, req.clone(), "slamb", "hunter2".to_owned(),
|
||||||
b"nvr.example.com".to_vec(), 0).unwrap();
|
Some(b"nvr.example.com".to_vec()), 0).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -946,7 +946,7 @@ mod tests {
|
||||||
// Get a session for later.
|
// Get a session for later.
|
||||||
let sid = state.login_by_password(&conn, req.clone(), "slamb",
|
let sid = state.login_by_password(&conn, req.clone(), "slamb",
|
||||||
"hunter2".to_owned(),
|
"hunter2".to_owned(),
|
||||||
b"nvr.example.com".to_vec(), 0).unwrap().0;
|
Some(b"nvr.example.com".to_vec()), 0).unwrap().0;
|
||||||
|
|
||||||
// Disable the user.
|
// Disable the user.
|
||||||
{
|
{
|
||||||
|
@ -958,7 +958,7 @@ mod tests {
|
||||||
// Fresh logins shouldn't work.
|
// Fresh logins shouldn't work.
|
||||||
let e = state.login_by_password(&conn, req.clone(), "slamb",
|
let e = state.login_by_password(&conn, req.clone(), "slamb",
|
||||||
"hunter2".to_owned(),
|
"hunter2".to_owned(),
|
||||||
b"nvr.example.com".to_vec(), 0).unwrap_err();
|
Some(b"nvr.example.com".to_vec()), 0).unwrap_err();
|
||||||
assert_eq!(format!("{}", e), "user \"slamb\" is disabled");
|
assert_eq!(format!("{}", e), "user \"slamb\" is disabled");
|
||||||
|
|
||||||
// Authenticating existing sessions shouldn't work either.
|
// Authenticating existing sessions shouldn't work either.
|
||||||
|
@ -992,7 +992,7 @@ mod tests {
|
||||||
// Get a session for later.
|
// Get a session for later.
|
||||||
let (sid, _) = state.login_by_password(&conn, req.clone(), "slamb",
|
let (sid, _) = state.login_by_password(&conn, req.clone(), "slamb",
|
||||||
"hunter2".to_owned(),
|
"hunter2".to_owned(),
|
||||||
b"nvr.example.com".to_vec(), 0).unwrap();
|
Some(b"nvr.example.com".to_vec()), 0).unwrap();
|
||||||
|
|
||||||
state.delete_user(&mut conn, uid).unwrap();
|
state.delete_user(&mut conn, uid).unwrap();
|
||||||
assert!(state.users_by_id().get(&uid).is_none());
|
assert!(state.users_by_id().get(&uid).is_none());
|
||||||
|
|
Loading…
Reference in New Issue