- Provider: rimossi openai, Bedrock e GCP integrati e ogni fallback a OpenAI;
restano ollama, lmstudio e i provider personalizzati. Senza provider, exec e
TUI mostrano come configurarlo.
- Chiave per provider: api_key = "keyring", provider_api_key_store =
auto|keyring|file (fallback su file 0600 / ACL Windows); `codex login
--provider <id> --with-api-key`, `logout --provider`; login status e doctor
mostrano dove sta la chiave senza rivelarla.
- Modelli letti da GET {base_url}/models; contesto da config, poi dal server
(/props, meta.n_ctx), poi 32768; apply_patch come tool function; niente tool
ospitati; niente piu' avviso "metadata not found".
- Unione dei soli messaggi system/developer iniziali in un unico system;
quelli successivi restano al loro posto come user (cache del server
preservata: turno N prefisso esatto del turno N+1).
- Modelli ausiliari (memorie, guardian-v2) = modello di sessione se il
preferito gpt-* non e' nel catalogo.
- Ricerca web: crate web-tools, backend SearXNG con web_search e web_fetch
(protezione SSRF); senza backend nessuno strumento web.
- Skill: rimossa openai-docs; skill-installer punta a git.difonzo.net.
- apply_patch accetta gli header @@ -a,b +c,d @@ dei diff unificati.
- Rimossi resti: request_plugin_install, AppsInstructions, --cyber-access-program,
URL updater/realtime predefiniti.
- Fix: importazione sessioni con provider vuoto.
- Istruzioni di sistema invariate. Test: cancellati solo quelli del codice
rimosso, test di sicurezza adattati; restano solo fallimenti d'ambiente.
- Prova reale su imeAI + SearXNG: risposta, modifica file, web_search,
cache riusata, connessioni solo verso .25 e .57.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
115 lines
5.2 KiB
Rust
115 lines
5.2 KiB
Rust
//! Requirements reads report the authentication policy enforced by the running server.
|
|
|
|
use anyhow::Result;
|
|
use app_test_support::TestAppServer;
|
|
use codex_app_server_protocol::RequestId;
|
|
use codex_protocol::config_types::ForcedLoginMethod;
|
|
use pretty_assertions::assert_eq;
|
|
use serde_json::Value;
|
|
use serde_json::json;
|
|
use std::time::Duration;
|
|
use tempfile::TempDir;
|
|
use test_case::test_case;
|
|
use tokio::time::timeout;
|
|
|
|
const READ_TIMEOUT: Duration = Duration::from_secs(/*secs*/ 60);
|
|
|
|
async fn start_server(
|
|
config: &str,
|
|
requirements: Option<&str>,
|
|
) -> Result<(TempDir, TestAppServer)> {
|
|
let home = TempDir::new()?;
|
|
std::fs::write(home.path().join("config.toml"), config)?;
|
|
if let Some(requirements) = requirements {
|
|
std::fs::write(home.path().join("requirements.toml"), requirements)?;
|
|
}
|
|
let server = TestAppServer::builder()
|
|
.with_codex_home(home.path())
|
|
.build_initialized_with_timeout(READ_TIMEOUT)
|
|
.await?;
|
|
Ok((home, server))
|
|
}
|
|
|
|
async fn read_requirements(server: &mut TestAppServer) -> Result<Value> {
|
|
let id = server.send_config_requirements_read_request().await?;
|
|
timeout(READ_TIMEOUT, server.read_response(id)).await?
|
|
}
|
|
|
|
#[test_case(""; "no_requirements")]
|
|
#[test_case("forced_chatgpt_workspace_id = []"; "empty_forced_workspaces_are_unrestricted")]
|
|
#[test_case("forced_chatgpt_workspace_id = ['managed']"; "forced_workspace_does_not_exclude_api")]
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn config_requirements_read_preserves_unrestricted_default(config: &str) -> Result<()> {
|
|
let (_home, mut server) = start_server(config, /*requirements*/ None).await?;
|
|
assert_eq!(
|
|
read_requirements(&mut server).await?,
|
|
json!({"requirements": null, "supportsIndependentSpeedModes": true})
|
|
);
|
|
Ok(())
|
|
}
|
|
|
|
#[test_case("allow_remote_control = false", "", &[ForcedLoginMethod::Api, ForcedLoginMethod::Chatgpt]; "unrestricted_with_other_requirements")]
|
|
#[test_case("allowed_login_methods = ['api']", "", &[ForcedLoginMethod::Api]; "managed_api")]
|
|
#[test_case("allowed_login_methods = ['chatgpt']", "", &[ForcedLoginMethod::Chatgpt]; "managed_chatgpt")]
|
|
#[test_case("allowed_login_methods = ['chatgpt', 'api', 'api']", "", &[ForcedLoginMethod::Api, ForcedLoginMethod::Chatgpt]; "both_normalized")]
|
|
#[test_case("", "forced_login_method = 'api'", &[ForcedLoginMethod::Api]; "forced_api_without_requirements")]
|
|
#[test_case("", "forced_login_method = 'chatgpt'", &[ForcedLoginMethod::Chatgpt]; "forced_chatgpt_without_requirements")]
|
|
#[test_case("allowed_login_methods = ['chatgpt', 'api']", "forced_login_method = 'api'", &[ForcedLoginMethod::Api]; "forced_narrows_managed")]
|
|
#[test_case("allowed_chatgpt_workspaces = []", "", &[ForcedLoginMethod::Api]; "empty_managed_workspaces")]
|
|
#[test_case("allowed_chatgpt_workspaces = ['managed']", "forced_chatgpt_workspace_id = ['other']", &[ForcedLoginMethod::Api]; "disjoint_workspaces")]
|
|
#[test_case("allowed_chatgpt_workspaces = ['managed']", "forced_chatgpt_workspace_id = ['other', 'managed']", &[ForcedLoginMethod::Api, ForcedLoginMethod::Chatgpt]; "overlapping_workspaces")]
|
|
#[test_case("allowed_login_methods = ['api']\nallowed_chatgpt_workspaces = ['managed']", "forced_chatgpt_workspace_id = ['other']", &[ForcedLoginMethod::Api]; "api_only_ignores_workspace_mismatch")]
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn config_requirements_read_exposes_effective_login_methods(
|
|
requirements: &str,
|
|
config: &str,
|
|
expected: &[ForcedLoginMethod],
|
|
) -> Result<()> {
|
|
let (_home, mut server) = start_server(config, Some(requirements)).await?;
|
|
let wire = read_requirements(&mut server).await?;
|
|
assert_eq!(wire["requirements"]["allowedLoginMethods"], json!(expected));
|
|
if !expected.contains(&ForcedLoginMethod::Api) {
|
|
let id = server.send_login_account_api_key_request("sk-test").await?;
|
|
let error = timeout(
|
|
READ_TIMEOUT,
|
|
server.read_stream_until_error_message(RequestId::Integer(id)),
|
|
)
|
|
.await??;
|
|
assert!(error.error.message.contains("disabled"), "{error:?}");
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
#[test_case(""; "removed")]
|
|
#[test_case("allowed_login_methods = ['chatgpt']"; "changed")]
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn config_requirements_read_uses_running_auth_policy(refreshed: &str) -> Result<()> {
|
|
let (home, mut server) = start_server("", Some("allowed_login_methods = ['api']")).await?;
|
|
std::fs::write(home.path().join("requirements.toml"), refreshed)?;
|
|
assert_eq!(
|
|
read_requirements(&mut server).await?["requirements"]["allowedLoginMethods"],
|
|
json!(["api"])
|
|
);
|
|
Ok(())
|
|
}
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn config_requirements_read_rejects_invalid_login_method() -> Result<()> {
|
|
let (home, mut server) = start_server("", /*requirements*/ None).await?;
|
|
std::fs::write(
|
|
home.path().join("requirements.toml"),
|
|
"allowed_login_methods = ['saml']",
|
|
)?;
|
|
let id = server.send_config_requirements_read_request().await?;
|
|
let error = timeout(
|
|
READ_TIMEOUT,
|
|
server.read_stream_until_error_message(RequestId::Integer(id)),
|
|
)
|
|
.await??;
|
|
assert!(
|
|
error.error.message.contains("allowed_login_methods"),
|
|
"{error:?}"
|
|
);
|
|
Ok(())
|
|
}
|