mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2024-12-26 15:15:56 -05:00
fix a couple compile errors in 422cd2a
I just ran a "cargo test" on this after a round of tweaks, not "cargo test --all", so I missed compile errors in the db crate, and a Javascript lint config error. travis-ci caught these.
This commit is contained in:
parent
422cd2a75e
commit
4daf618c29
@ -16,6 +16,6 @@
|
|||||||
"no-shadow": ["error", { "builtinGlobals": false, "hoist": "functions", "allow": [] }],
|
"no-shadow": ["error", { "builtinGlobals": false, "hoist": "functions", "allow": [] }],
|
||||||
"no-shadow-restricted-names": ["error"],
|
"no-shadow-restricted-names": ["error"],
|
||||||
"no-undef": ["error", {"typeof": true}],
|
"no-undef": ["error", {"typeof": true}],
|
||||||
"no-unused-vars": ["error", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }],
|
"no-unused-vars": ["error", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
62
db/auth.rs
62
db/auth.rs
@ -767,32 +767,27 @@ mod tests {
|
|||||||
"hunter3".to_owned(),
|
"hunter3".to_owned(),
|
||||||
b"nvr.example.com".to_vec(), 0).unwrap_err();
|
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, csrf) = {
|
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();
|
b"nvr.example.com".to_vec(), 0).unwrap();
|
||||||
assert_eq!(s.user_id, uid);
|
assert_eq!(s.user_id, uid);
|
||||||
(sid, s.csrf())
|
sid
|
||||||
};
|
};
|
||||||
|
|
||||||
let e = state.authenticate_session(&conn, req.clone(), &sid,
|
{
|
||||||
&SessionHash::default()).unwrap_err();
|
let (_, u) = state.authenticate_session(&conn, req.clone(), &sid.hash()).unwrap();
|
||||||
assert_eq!(format!("{}", e), "s and sc cookies are inconsistent");
|
|
||||||
|
|
||||||
let sid_hash = {
|
|
||||||
let (hash, u) = state.authenticate_session(&conn, req.clone(), &sid, &csrf).unwrap();
|
|
||||||
assert_eq!(u.id, uid);
|
assert_eq!(u.id, uid);
|
||||||
hash
|
}
|
||||||
};
|
|
||||||
state.revoke_session(&conn, RevocationReason::LoggedOut, None, req.clone(),
|
state.revoke_session(&conn, RevocationReason::LoggedOut, None, req.clone(),
|
||||||
sid_hash).unwrap();
|
&sid.hash()).unwrap();
|
||||||
let e = state.authenticate_session(&conn, req.clone(), &sid, &csrf).unwrap_err();
|
let e = state.authenticate_session(&conn, req.clone(), &sid.hash()).unwrap_err();
|
||||||
assert_eq!(format!("{}", e), "session is no longer valid (reason=1)");
|
assert_eq!(format!("{}", e), "session is no longer valid (reason=1)");
|
||||||
|
|
||||||
// Everything should persist across reload.
|
// Everything should persist across reload.
|
||||||
drop(state);
|
drop(state);
|
||||||
let mut state = State::init(&conn).unwrap();
|
let mut state = State::init(&conn).unwrap();
|
||||||
let e = state.authenticate_session(&conn, req, &sid, &csrf).unwrap_err();
|
let e = state.authenticate_session(&conn, req, &sid.hash()).unwrap_err();
|
||||||
assert_eq!(format!("{}", e), "session is no longer valid (reason=1)");
|
assert_eq!(format!("{}", e), "session is no longer valid (reason=1)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -812,20 +807,17 @@ mod tests {
|
|||||||
c.set_password("hunter2".to_owned());
|
c.set_password("hunter2".to_owned());
|
||||||
state.apply(&conn, c).unwrap();
|
state.apply(&conn, c).unwrap();
|
||||||
};
|
};
|
||||||
let (sid, csrf) = {
|
let sid = 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().0;
|
||||||
b"nvr.example.com".to_vec(), 0).unwrap();
|
state.authenticate_session(&conn, req.clone(), &sid.hash()).unwrap();
|
||||||
(sid, s.csrf())
|
|
||||||
};
|
|
||||||
state.authenticate_session(&conn, req.clone(), &sid, &csrf).unwrap();
|
|
||||||
|
|
||||||
// Reload.
|
// Reload.
|
||||||
drop(state);
|
drop(state);
|
||||||
let mut state = State::init(&conn).unwrap();
|
let mut state = State::init(&conn).unwrap();
|
||||||
state.revoke_session(&conn, RevocationReason::LoggedOut, None, req.clone(),
|
state.revoke_session(&conn, RevocationReason::LoggedOut, None, req.clone(),
|
||||||
sid.hash()).unwrap();
|
&sid.hash()).unwrap();
|
||||||
let e = state.authenticate_session(&conn, req, &sid, &csrf).unwrap_err();
|
let e = state.authenticate_session(&conn, req, &sid.hash()).unwrap_err();
|
||||||
assert_eq!(format!("{}", e), "session is no longer valid (reason=1)");
|
assert_eq!(format!("{}", e), "session is no longer valid (reason=1)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -902,12 +894,9 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Get a session for later.
|
// Get a session for later.
|
||||||
let (sid, csrf) = {
|
let sid = 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().0;
|
||||||
b"nvr.example.com".to_vec(), 0).unwrap();
|
|
||||||
(sid, s.csrf())
|
|
||||||
};
|
|
||||||
|
|
||||||
// Disable the user.
|
// Disable the user.
|
||||||
{
|
{
|
||||||
@ -923,13 +912,13 @@ mod tests {
|
|||||||
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.
|
||||||
let e = state.authenticate_session(&conn, req.clone(), &sid, &csrf).unwrap_err();
|
let e = state.authenticate_session(&conn, req.clone(), &sid.hash()).unwrap_err();
|
||||||
assert_eq!(format!("{}", e), "user \"slamb\" is disabled");
|
assert_eq!(format!("{}", e), "user \"slamb\" is disabled");
|
||||||
|
|
||||||
// The user should still be disabled after reload.
|
// The user should still be disabled after reload.
|
||||||
drop(state);
|
drop(state);
|
||||||
let mut state = State::init(&conn).unwrap();
|
let mut state = State::init(&conn).unwrap();
|
||||||
let e = state.authenticate_session(&conn, req, &sid, &csrf).unwrap_err();
|
let e = state.authenticate_session(&conn, req, &sid.hash()).unwrap_err();
|
||||||
assert_eq!(format!("{}", e), "user \"slamb\" is disabled");
|
assert_eq!(format!("{}", e), "user \"slamb\" is disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -951,23 +940,20 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Get a session for later.
|
// Get a session for later.
|
||||||
let (sid, csrf) = {
|
let (sid, _) = 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();
|
||||||
b"nvr.example.com".to_vec(), 0).unwrap();
|
|
||||||
(sid, s.csrf())
|
|
||||||
};
|
|
||||||
|
|
||||||
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());
|
||||||
let e = state.authenticate_session(&conn, req.clone(), &sid, &csrf).unwrap_err();
|
let e = state.authenticate_session(&conn, req.clone(), &sid.hash()).unwrap_err();
|
||||||
assert_eq!(format!("{}", e), "no such session");
|
assert_eq!(format!("{}", e), "no such session");
|
||||||
|
|
||||||
// The user should still be deleted after reload.
|
// The user should still be deleted after reload.
|
||||||
drop(state);
|
drop(state);
|
||||||
let mut state = State::init(&conn).unwrap();
|
let mut state = State::init(&conn).unwrap();
|
||||||
assert!(state.users_by_id().get(&uid).is_none());
|
assert!(state.users_by_id().get(&uid).is_none());
|
||||||
let e = state.authenticate_session(&conn, req.clone(), &sid, &csrf).unwrap_err();
|
let e = state.authenticate_session(&conn, req.clone(), &sid.hash()).unwrap_err();
|
||||||
assert_eq!(format!("{}", e), "no such session");
|
assert_eq!(format!("{}", e), "no such session");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user