1 parent
d55640d37a
commit
fff8521a17
67 files changed
+11016
-16763
No files matched your search
+32
-19
@@ -1,8 +1,8 @@
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
|
||||
|
||||
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
|
||||
use base64::Engine;
|
||||
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
|
||||
use dashmap::DashMap;
|
||||
use rand::RngCore;
|
||||
|
||||
@@ -102,17 +102,8 @@ impl SessionStore {
|
||||
smtp_tls: bool,
|
||||
) -> (SessionId, AccountId) {
|
||||
self.add_account_to_browser_with_timeout(
|
||||
browser_id,
|
||||
email,
|
||||
password,
|
||||
user_hash,
|
||||
imap_host,
|
||||
imap_port,
|
||||
imap_tls,
|
||||
smtp_host,
|
||||
smtp_port,
|
||||
smtp_tls,
|
||||
None,
|
||||
browser_id, email, password, user_hash, imap_host, imap_port, imap_tls, smtp_host,
|
||||
smtp_port, smtp_tls, None,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -234,7 +225,11 @@ impl SessionStore {
|
||||
/// Store a display-only User-Agent string for active-session diagnostics.
|
||||
/// It is never used for authentication or authorization decisions.
|
||||
pub fn set_user_agent(&self, account_id: &str, user_agent: String) {
|
||||
let Some(session_id) = self.account_to_session.get(account_id).map(|entry| entry.clone()) else {
|
||||
let Some(session_id) = self
|
||||
.account_to_session
|
||||
.get(account_id)
|
||||
.map(|entry| entry.clone())
|
||||
else {
|
||||
return;
|
||||
};
|
||||
if let Some(mut session) = self.sessions.get_mut(&session_id) {
|
||||
@@ -267,7 +262,11 @@ impl SessionStore {
|
||||
|
||||
/// Revoke one session only when it belongs to the requested user.
|
||||
pub fn remove_user_session(&self, user_hash: &str, account_id: &str) -> bool {
|
||||
let Some(session_id) = self.account_to_session.get(account_id).map(|entry| entry.clone()) else {
|
||||
let Some(session_id) = self
|
||||
.account_to_session
|
||||
.get(account_id)
|
||||
.map(|entry| entry.clone())
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
let belongs_to_user = self
|
||||
@@ -890,7 +889,11 @@ mod tests {
|
||||
|
||||
// --- Consistency tests ---
|
||||
|
||||
fn add_test_account(store: &SessionStore, browser_id: &str, email: &str) -> (SessionId, AccountId) {
|
||||
fn add_test_account(
|
||||
store: &SessionStore,
|
||||
browser_id: &str,
|
||||
email: &str,
|
||||
) -> (SessionId, AccountId) {
|
||||
store.add_account_to_browser(
|
||||
browser_id,
|
||||
email.into(),
|
||||
@@ -1231,7 +1234,11 @@ mod tests {
|
||||
|
||||
store.purge_expired();
|
||||
|
||||
assert_eq!(store.sessions.len(), 1, "only the live session should remain");
|
||||
assert_eq!(
|
||||
store.sessions.len(),
|
||||
1,
|
||||
"only the live session should remain"
|
||||
);
|
||||
assert!(
|
||||
!store.account_to_session.contains_key(&account1),
|
||||
"expired account mapping should be gone"
|
||||
@@ -1299,7 +1306,11 @@ mod tests {
|
||||
|
||||
thread::sleep(Duration::from_millis(100));
|
||||
|
||||
assert!(store.get_account_session(&browser_id, &account_id, &token).is_none());
|
||||
assert!(
|
||||
store
|
||||
.get_account_session(&browser_id, &account_id, &token)
|
||||
.is_none()
|
||||
);
|
||||
|
||||
assert!(
|
||||
!store.account_to_session.contains_key(&account_id),
|
||||
@@ -1325,7 +1336,9 @@ mod tests {
|
||||
);
|
||||
|
||||
thread::sleep(Duration::from_millis(100));
|
||||
assert!(store.get(&token).is_some(), "remembered session should outlive default timeout");
|
||||
assert!(
|
||||
store.get(&token).is_some(),
|
||||
"remembered session should outlive default timeout"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user