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:
andrea.difonzo
2026-11-10 06:00:44 +01:00
parent 82347a58ed
commit 231e8cd136
661 changed files with 4924 additions and 64817 deletions

View File

@@ -1,42 +1,30 @@
//! Provider and authentication dimensions that partition model catalogs.
use super::*;
use base64::Engine;
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
use pretty_assertions::assert_eq;
fn chatgpt_auth(email: &str, user: &str, account: &str, plan: &str, signature: &str) -> CodexAuth {
let claims = serde_json::json!({
"email": email,
"https://api.openai.com/auth": {"chatgpt_user_id": user}
});
let payload = URL_SAFE_NO_PAD.encode(serde_json::to_vec(&claims).unwrap());
CodexAuth::from_external_chatgpt_tokens(
&format!("e30.{payload}.{signature}"),
account,
Some(plan),
)
.unwrap()
}
#[test]
fn cache_identity_tracks_account_email_user_plan_and_auth_mode_but_not_token_refresh() {
fn cache_identity_tracks_credential_kind_and_value() {
let mut provider = ModelProviderInfo::create_openai_provider(/*base_url*/ None);
// The endpoint residency test temporarily sets the process default to US.
provider.http_headers = Some(std::collections::HashMap::from([(
codex_login::default_client::RESIDENCY_HEADER_NAME.to_string(),
"us".into(),
)]));
let initial = chatgpt_auth("one@example.com", "user", "account", "team", "first");
let initial = CodexAuth::from_api_key("api-key");
let key = identity(&provider, Some(&initial)).unwrap();
let refreshed = chatgpt_auth("one@example.com", "user", "account", "team", "second");
assert_eq!(identity(&provider, Some(&refreshed)).unwrap(), key);
assert_eq!(
identity(&provider, Some(&CodexAuth::from_api_key("api-key"))).unwrap(),
key
);
for auth in [
chatgpt_auth("two@example.com", "user", "account", "team", "first"),
chatgpt_auth("one@example.com", "other", "account", "team", "first"),
chatgpt_auth("one@example.com", "user", "other", "team", "first"),
chatgpt_auth("one@example.com", "user", "account", "plus", "first"),
CodexAuth::from_api_key("api-key"),
CodexAuth::from_api_key("rotated-api-key"),
CodexAuth::Headers(codex_login::AuthHeaders::new(http::HeaderMap::from_iter([
(
http::header::AUTHORIZATION,
http::HeaderValue::from_static("Bearer api-key"),
),
]))),
] {
assert_ne!(identity(&provider, Some(&auth)).unwrap(), key);
}
@@ -77,27 +65,13 @@ fn cache_identity_tracks_provider_routing_and_effective_api_credentials() {
}
#[test]
fn cache_identity_distinguishes_auth_requirements_and_unknown_plans() {
fn cache_identity_distinguishes_auth_requirements() {
let mut provider =
ModelProviderInfo::create_openai_provider(Some("https://example.com/v1".into()));
let first = chatgpt_auth(
"one@example.com",
"user",
"account",
"future-plan-one",
"first",
);
let second = chatgpt_auth(
"one@example.com",
"user",
"account",
"future-plan-two",
"first",
);
let key = identity(&provider, Some(&first)).unwrap();
assert_ne!(key, identity(&provider, Some(&second)).unwrap());
let auth = CodexAuth::from_api_key("api-key");
let key = identity(&provider, Some(&auth)).unwrap();
provider.requires_openai_auth = false;
assert_ne!(key, identity(&provider, Some(&first)).unwrap());
assert_ne!(key, identity(&provider, Some(&auth)).unwrap());
}
#[test]
@@ -127,7 +101,7 @@ fn provider_key_catalog_identity_does_not_depend_on_unused_login() {
provider.experimental_bearer_token = Some("provider-key".into());
let identity_without_login = identity(&provider, /*auth*/ None).unwrap();
let selected_key = CodexAuth::from_api_key("provider-key");
let unused_login = chatgpt_auth("user@example.com", "user", "workspace", "team", "token");
let unused_login = CodexAuth::from_api_key("unused-login-key");
for auth in [&selected_key, &unused_login] {
assert_eq!(
identity(&provider, Some(auth)).unwrap(),