WIP fase 2b-2: rimosso login ChatGPT/OAuth/device code, agent/workload identity, backend-client; resta solo chiave API (test non tutti verdi)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -203,118 +203,6 @@ wire_api = 'responses'
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
enum StdinTokenStartup {
|
||||
SkipPolicy,
|
||||
LoadPolicy,
|
||||
RejectAccount,
|
||||
CloseDuringPolicy,
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test_case::test_case("pro", Some("endor"), StdinTokenStartup::SkipPolicy; "personal_skips_policy")]
|
||||
#[test_case::test_case("enterprise", Some("endor"), StdinTokenStartup::LoadPolicy; "enterprise_loads_policy")]
|
||||
#[test_case::test_case("pro", None, StdinTokenStartup::LoadPolicy; "unbound_account_loads_policy")]
|
||||
#[test_case::test_case("unknown", Some("endor"), StdinTokenStartup::LoadPolicy; "unknown_plan_loads_policy")]
|
||||
#[test_case::test_case("pro", Some("alderaan"), StdinTokenStartup::RejectAccount; "mismatched_account_never_registers")]
|
||||
#[test_case::test_case("enterprise", Some("endor"), StdinTokenStartup::CloseDuringPolicy; "stdin_close_cancels_pending_policy")]
|
||||
#[tokio::test]
|
||||
async fn stdin_token_startup(
|
||||
plan: &str,
|
||||
claimed_id: Option<&str>,
|
||||
expected: StdinTokenStartup,
|
||||
) -> Result<()> {
|
||||
use StdinTokenStartup::*;
|
||||
use anyhow::Context;
|
||||
use std::process::Stdio;
|
||||
use std::time::Duration;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use wiremock::matchers::header;
|
||||
|
||||
skip_if_no_network!(Ok(()));
|
||||
let home = tempdir()?;
|
||||
std::fs::write(
|
||||
home.path().join("requirements.toml"),
|
||||
"allowed_chatgpt_workspaces = ['endor']",
|
||||
)?;
|
||||
let registry = MockServer::start().await;
|
||||
let (origin, ca, _tls) = https_mock_server(home.path(), ®istry).await?;
|
||||
let timeout = Duration::from_secs(60);
|
||||
let mut claims = app_test_support::ChatGptIdTokenClaims::new().plan_type(plan);
|
||||
claims.chatgpt_account_id = claimed_id.map(str::to_owned);
|
||||
let token = app_test_support::encode_id_token(&claims)?;
|
||||
let authenticated = |route| {
|
||||
Mock::given(path(route))
|
||||
.and(header("authorization", format!("Bearer {token}")))
|
||||
.and(header("chatgpt-account-id", "endor"))
|
||||
};
|
||||
let policy_response = match expected {
|
||||
LoadPolicy => ResponseTemplate::new(200).set_body_json(serde_json::json!({})),
|
||||
CloseDuringPolicy => ResponseTemplate::new(200).set_delay(timeout),
|
||||
SkipPolicy | RejectAccount => ResponseTemplate::new(400)
|
||||
.set_body_json(serde_json::json!({"detail": "No active workspace"})),
|
||||
};
|
||||
let policy = authenticated("/api/codex/config/bundle")
|
||||
.respond_with(policy_response)
|
||||
.expect(u64::from(matches!(
|
||||
expected,
|
||||
LoadPolicy | CloseDuringPolicy
|
||||
)))
|
||||
.mount_as_scoped(®istry)
|
||||
.await;
|
||||
let register = authenticated("/cloud/environment/env/register")
|
||||
.respond_with(ResponseTemplate::new(200).set_delay(timeout))
|
||||
.expect(u64::from(matches!(expected, SkipPolicy | LoadPolicy)))
|
||||
.mount_as_scoped(®istry)
|
||||
.await;
|
||||
let mut child = tokio::process::Command::new(codex_utils_cargo_bin::cargo_bin("codex")?)
|
||||
.current_dir(home.path())
|
||||
.env("CODEX_HOME", home.path())
|
||||
.env("CODEX_CA_CERTIFICATE", ca)
|
||||
.env("NO_PROXY", "127.0.0.1")
|
||||
.args(["-c", &format!("chatgpt_base_url={origin:?}")])
|
||||
.arg("exec-server")
|
||||
.args(["--remote", &origin])
|
||||
.args(["--environment-id", "env"])
|
||||
.args(["--chatgpt-token-stdin", "--exit-on-stdin-close"])
|
||||
.args(["--chatgpt-account-id", "endor"])
|
||||
.stdin(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.kill_on_drop(true)
|
||||
.spawn()?;
|
||||
let mut stdin = child.stdin.take().context("exec-server stdin")?;
|
||||
stdin.write_all(format!("{token}\n").as_bytes()).await?;
|
||||
let (pending, exit_timeout) = match expected {
|
||||
RejectAccount => {
|
||||
let output = tokio::time::timeout(timeout, child.wait_with_output()).await??;
|
||||
assert!(!output.status.success());
|
||||
assert!(
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
.contains("--chatgpt-account-id does not match the token")
|
||||
);
|
||||
assert!(
|
||||
registry
|
||||
.received_requests()
|
||||
.await
|
||||
.context("request recording")?
|
||||
.is_empty()
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
CloseDuringPolicy => (&policy, Duration::from_secs(5)),
|
||||
SkipPolicy | LoadPolicy => (®ister, timeout),
|
||||
};
|
||||
tokio::time::timeout(timeout, pending.wait_until_satisfied()).await?;
|
||||
drop(stdin);
|
||||
assert!(
|
||||
tokio::time::timeout(exit_timeout, child.wait())
|
||||
.await??
|
||||
.success()
|
||||
);
|
||||
assert!(!home.path().join("auth.json").exists());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn https_mock_server(
|
||||
home: &Path,
|
||||
policy: &MockServer,
|
||||
|
||||
Reference in New Issue
Block a user