fix(gpclient): honor the requested username when reusing cookies (#732)

This commit is contained in:
Kevin Yue authored and GitHub committed 2026-11-30 20:05:21 +08:00
1 parent 69155d04b9
commit fe3125ec61
3 files changed
+65 -8

No files matched your search

+43
View File
@@ -129,6 +129,49 @@ async fn cached_tunnel_authentication_does_not_require_portal_discovery() {
);
}
#[tokio::test]
async fn explicit_user_skips_another_users_cached_gateway_and_portal_credentials() {
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let origin = format!("http://{}", listener.local_addr().unwrap());
let directory = tempfile::tempdir().unwrap();
let cache = directory.path().join("cookie.json");
let args = TestArgs::parse_from([
"test",
&origin,
"--user",
"bob",
"--cookie-cache",
cache.to_str().unwrap(),
])
.connect;
let lock = directory.path().join("client.pid");
let verbose = gpapi::clap::InfoLevelVerbosity::new(0, 0);
let shared = SharedArgs {
ignore_tls_errors: true,
lock_file: &lock,
verbose: &verbose,
log_format: LogFormat::Text,
};
let handler = ConnectHandler::new(&args, &shared);
cookie_store::save(
&cache,
&StoredCookie::new(
args.server.clone(),
"alice".into(),
handler.os_profile.borrow().host_identity().host_id().into(),
origin,
AuthCookieCredential::new("alice", "portal-cookie", ""),
),
)
.unwrap();
assert!(handler.cached_portal_credential(&args.server).is_none());
tokio::select! {
result = handler.try_cached_cookie(&args.server) => assert!(result.is_none()),
_ = listener.accept() => panic!("a mismatched cache entry must be skipped before contacting the gateway"),
}
}
#[tokio::test]
async fn unreachable_gateway_keeps_cached_cookie() {
// Nothing listens here: the cached gateway login gets no answer at all.