[APP-3801] implement remote environments auth (#9331)

This commit is contained in:
Moira Huang
2026-04-28 21:31:23 -05:00
committed by GitHub
parent c325d146ab
commit f0c8b7f723
21 changed files with 685 additions and 69 deletions
@@ -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"));
}