[APP-3801] implement remote environments auth (#9331)
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use super::super::proto::{Authenticate, Initialize};
|
||||
use super::super::protocol::RequestId;
|
||||
use super::{PendingFileOps, ServerModel};
|
||||
|
||||
fn test_model() -> ServerModel {
|
||||
ServerModel {
|
||||
connection_senders: HashMap::new(),
|
||||
snapshot_sent_roots_by_connection: HashMap::new(),
|
||||
grace_timer_cancel: None,
|
||||
in_progress: HashMap::new(),
|
||||
host_id: "test-host-id".to_string(),
|
||||
executors: HashMap::new(),
|
||||
pending_file_ops: PendingFileOps::new(),
|
||||
auth_token: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn request_id() -> RequestId {
|
||||
RequestId::from("test-request".to_string())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fresh_model_starts_without_auth_token() {
|
||||
let model = test_model();
|
||||
|
||||
assert_eq!(model.auth_token(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn initialize_with_auth_token_stores_token() {
|
||||
let mut model = test_model();
|
||||
|
||||
model.handle_initialize(
|
||||
Initialize {
|
||||
auth_token: "initial-token".to_string(),
|
||||
},
|
||||
&request_id(),
|
||||
);
|
||||
|
||||
assert_eq!(model.auth_token(), Some("initial-token"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_initialize_preserves_existing_auth_token() {
|
||||
let mut model = test_model();
|
||||
model.handle_initialize(
|
||||
Initialize {
|
||||
auth_token: "initial-token".to_string(),
|
||||
},
|
||||
&request_id(),
|
||||
);
|
||||
|
||||
model.handle_initialize(
|
||||
Initialize {
|
||||
auth_token: String::new(),
|
||||
},
|
||||
&request_id(),
|
||||
);
|
||||
|
||||
assert_eq!(model.auth_token(), Some("initial-token"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn authenticate_with_auth_token_replaces_auth_token() {
|
||||
let mut model = test_model();
|
||||
model.handle_initialize(
|
||||
Initialize {
|
||||
auth_token: "initial-token".to_string(),
|
||||
},
|
||||
&request_id(),
|
||||
);
|
||||
|
||||
model.handle_authenticate(Authenticate {
|
||||
auth_token: "rotated-token".to_string(),
|
||||
});
|
||||
|
||||
assert_eq!(model.auth_token(), Some("rotated-token"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_authenticate_preserves_existing_auth_token() {
|
||||
let mut model = test_model();
|
||||
model.handle_initialize(
|
||||
Initialize {
|
||||
auth_token: "initial-token".to_string(),
|
||||
},
|
||||
&request_id(),
|
||||
);
|
||||
|
||||
model.handle_authenticate(Authenticate {
|
||||
auth_token: String::new(),
|
||||
});
|
||||
|
||||
assert_eq!(model.auth_token(), Some("initial-token"));
|
||||
}
|
||||
Reference in New Issue
Block a user