fix: persist auth cookies on close in native mode (#650)
This commit is contained in:
@@ -1293,3 +1293,115 @@ async fn e2e_error_handling() {
|
||||
let resp = execute_command(&json!({ "id": "99", "action": "close" }), &mut state).await;
|
||||
assert_success(&resp);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Profile cookie persistence across restarts
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn e2e_profile_cookie_persistence() {
|
||||
let profile_dir = std::env::temp_dir().join(format!(
|
||||
"agent-browser-e2e-profile-{}",
|
||||
uuid::Uuid::new_v4()
|
||||
));
|
||||
|
||||
// Session 1: launch with profile, set a cookie, close
|
||||
{
|
||||
let mut state = DaemonState::new();
|
||||
|
||||
let resp = execute_command(
|
||||
&json!({
|
||||
"id": "1",
|
||||
"action": "launch",
|
||||
"headless": true,
|
||||
"profile": profile_dir.to_str().unwrap()
|
||||
}),
|
||||
&mut state,
|
||||
)
|
||||
.await;
|
||||
assert_success(&resp);
|
||||
|
||||
let resp = execute_command(
|
||||
&json!({ "id": "2", "action": "navigate", "url": "https://example.com" }),
|
||||
&mut state,
|
||||
)
|
||||
.await;
|
||||
assert_success(&resp);
|
||||
|
||||
let resp = execute_command(
|
||||
&json!({
|
||||
"id": "3",
|
||||
"action": "cookies_set",
|
||||
"name": "persist_test",
|
||||
"value": "should_survive_restart",
|
||||
"domain": ".example.com",
|
||||
"path": "/",
|
||||
"expires": 2000000000
|
||||
}),
|
||||
&mut state,
|
||||
)
|
||||
.await;
|
||||
assert_success(&resp);
|
||||
|
||||
// Verify cookie is set
|
||||
let resp =
|
||||
execute_command(&json!({ "id": "4", "action": "cookies_get" }), &mut state).await;
|
||||
assert_success(&resp);
|
||||
let cookies = get_data(&resp)["cookies"].as_array().unwrap();
|
||||
let found = cookies
|
||||
.iter()
|
||||
.any(|c| c["name"] == "persist_test" && c["value"] == "should_survive_restart");
|
||||
assert!(found, "Cookie should exist before close");
|
||||
|
||||
let resp = execute_command(&json!({ "id": "5", "action": "close" }), &mut state).await;
|
||||
assert_success(&resp);
|
||||
}
|
||||
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
|
||||
|
||||
// Session 2: reopen with the same profile, verify cookie persisted
|
||||
{
|
||||
let mut state = DaemonState::new();
|
||||
|
||||
let resp = execute_command(
|
||||
&json!({
|
||||
"id": "10",
|
||||
"action": "launch",
|
||||
"headless": true,
|
||||
"profile": profile_dir.to_str().unwrap()
|
||||
}),
|
||||
&mut state,
|
||||
)
|
||||
.await;
|
||||
assert_success(&resp);
|
||||
|
||||
let resp = execute_command(
|
||||
&json!({ "id": "11", "action": "navigate", "url": "https://example.com" }),
|
||||
&mut state,
|
||||
)
|
||||
.await;
|
||||
assert_success(&resp);
|
||||
|
||||
let resp =
|
||||
execute_command(&json!({ "id": "12", "action": "cookies_get" }), &mut state).await;
|
||||
assert_success(&resp);
|
||||
let cookies = get_data(&resp)["cookies"].as_array().unwrap();
|
||||
let found = cookies
|
||||
.iter()
|
||||
.any(|c| c["name"] == "persist_test" && c["value"] == "should_survive_restart");
|
||||
assert!(
|
||||
found,
|
||||
"Cookie should persist across restart with --profile. Cookies found: {:?}",
|
||||
cookies
|
||||
.iter()
|
||||
.map(|c| c["name"].as_str().unwrap_or("?"))
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
|
||||
let resp = execute_command(&json!({ "id": "99", "action": "close" }), &mut state).await;
|
||||
assert_success(&resp);
|
||||
}
|
||||
|
||||
let _ = std::fs::remove_dir_all(&profile_dir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user