mirror of
https://github.com/openai/codex.git
synced 2026-11-13 14:46:14 +00:00
fix: auth.json leak in tests (#18657)
Before this some tests were leaking an auth.json file into `codex-rs/core`. This just fixes it
This commit is contained in:
1 parent
19e2f21827
commit
e53e6bc48f
2 files changed
+35
-1
No files matched your search
@@ -230,6 +230,33 @@ fn chatgpt_auth_persists_agent_identity_for_workspace() {
|
|||||||
assert_eq!(auth.get_agent_identity("account-123"), None);
|
assert_eq!(auth.get_agent_identity("account-123"), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn dummy_chatgpt_auth_does_not_create_cwd_auth_json_when_identity_is_set() {
|
||||||
|
let cwd_auth = std::env::current_dir()
|
||||||
|
.expect("current dir")
|
||||||
|
.join("auth.json");
|
||||||
|
let had_auth_json_before_test = cwd_auth.exists();
|
||||||
|
let auth = CodexAuth::create_dummy_chatgpt_auth_for_testing();
|
||||||
|
let record = AgentIdentityAuthRecord {
|
||||||
|
workspace_id: "account_id".to_string(),
|
||||||
|
chatgpt_user_id: None,
|
||||||
|
agent_runtime_id: "agent_123".to_string(),
|
||||||
|
agent_private_key: "pkcs8-base64".to_string(),
|
||||||
|
registered_at: "2026-04-13T12:00:00Z".to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
auth.set_agent_identity(record.clone())
|
||||||
|
.expect("set agent identity");
|
||||||
|
|
||||||
|
assert_eq!(auth.get_agent_identity("account_id"), Some(record));
|
||||||
|
if !had_auth_json_before_test {
|
||||||
|
assert!(
|
||||||
|
!cwd_auth.exists(),
|
||||||
|
"dummy ChatGPT auth must not write auth.json in the test process cwd"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unauthorized_recovery_reports_mode_and_step_names() {
|
fn unauthorized_recovery_reports_mode_and_step_names() {
|
||||||
let dir = tempdir().unwrap();
|
let dir = tempdir().unwrap();
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ use std::path::PathBuf;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
|
use std::sync::atomic::AtomicU64;
|
||||||
|
use std::sync::atomic::Ordering;
|
||||||
use tokio::sync::Mutex as AsyncMutex;
|
use tokio::sync::Mutex as AsyncMutex;
|
||||||
use tokio::sync::watch;
|
use tokio::sync::watch;
|
||||||
|
|
||||||
@@ -96,6 +98,7 @@ const REFRESH_TOKEN_URL: &str = "https://auth.openai.com/oauth/token";
|
|||||||
pub(super) const REVOKE_TOKEN_URL: &str = "https://auth.openai.com/oauth/revoke";
|
pub(super) const REVOKE_TOKEN_URL: &str = "https://auth.openai.com/oauth/revoke";
|
||||||
pub const REFRESH_TOKEN_URL_OVERRIDE_ENV_VAR: &str = "CODEX_REFRESH_TOKEN_URL_OVERRIDE";
|
pub const REFRESH_TOKEN_URL_OVERRIDE_ENV_VAR: &str = "CODEX_REFRESH_TOKEN_URL_OVERRIDE";
|
||||||
pub const REVOKE_TOKEN_URL_OVERRIDE_ENV_VAR: &str = "CODEX_REVOKE_TOKEN_URL_OVERRIDE";
|
pub const REVOKE_TOKEN_URL_OVERRIDE_ENV_VAR: &str = "CODEX_REVOKE_TOKEN_URL_OVERRIDE";
|
||||||
|
static NEXT_DUMMY_AUTH_ID: AtomicU64 = AtomicU64::new(1);
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum RefreshTokenError {
|
pub enum RefreshTokenError {
|
||||||
@@ -442,7 +445,11 @@ impl CodexAuth {
|
|||||||
auth_dot_json: Arc::new(Mutex::new(Some(auth_dot_json))),
|
auth_dot_json: Arc::new(Mutex::new(Some(auth_dot_json))),
|
||||||
client,
|
client,
|
||||||
};
|
};
|
||||||
let storage = create_auth_storage(PathBuf::new(), AuthCredentialsStoreMode::File);
|
let dummy_auth_id = NEXT_DUMMY_AUTH_ID.fetch_add(1, Ordering::Relaxed);
|
||||||
|
let storage = create_auth_storage(
|
||||||
|
PathBuf::from(format!("dummy-chatgpt-auth-{dummy_auth_id}")),
|
||||||
|
AuthCredentialsStoreMode::Ephemeral,
|
||||||
|
);
|
||||||
Self::Chatgpt(ChatgptAuth { state, storage })
|
Self::Chatgpt(ChatgptAuth { state, storage })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user