This commit is contained in:
celia-oai
2026-06-09 13:32:28 -07:00
parent 9ad1a16856
commit 1af6dad41d
2 changed files with 42 additions and 1 deletions

View File

@@ -262,6 +262,7 @@ impl AuthStorageBackend for DirectKeyringAuthStorage {
#[derive(Clone)]
struct SecretsKeyringAuthStorage {
codex_home: PathBuf,
direct_storage: DirectKeyringAuthStorage,
secrets_manager: SecretsManager,
}
@@ -275,6 +276,8 @@ impl Debug for SecretsKeyringAuthStorage {
impl SecretsKeyringAuthStorage {
fn new(codex_home: PathBuf, keyring_store: Arc<dyn KeyringStore>) -> Self {
let direct_storage =
DirectKeyringAuthStorage::new(codex_home.clone(), Arc::clone(&keyring_store));
let secrets_manager = SecretsManager::new_with_keyring_store(
codex_home.clone(),
SecretsBackendKind::Local,
@@ -282,6 +285,7 @@ impl SecretsKeyringAuthStorage {
);
Self {
codex_home,
direct_storage,
secrets_manager,
}
}
@@ -332,7 +336,8 @@ impl AuthStorageBackend for SecretsKeyringAuthStorage {
))
})?;
let file_removed = delete_file_if_exists(&self.codex_home)?;
Ok(keyring_removed || file_removed)
let direct_removed = self.direct_storage.delete()?;
Ok(keyring_removed || file_removed || direct_removed)
}
}

View File

@@ -506,6 +506,42 @@ fn secrets_keyring_auth_storage_delete_removes_keyring_and_file() -> anyhow::Res
Ok(())
}
#[test]
fn secrets_keyring_auth_storage_delete_removes_legacy_direct_keyring_entry() -> anyhow::Result<()> {
let codex_home = tempdir()?;
let mock_keyring = MockKeyringStore::default();
let direct_storage = DirectKeyringAuthStorage::new(
codex_home.path().to_path_buf(),
Arc::new(mock_keyring.clone()),
);
direct_storage.save(&auth_with_prefix("legacy-direct"))?;
let storage = SecretsKeyringAuthStorage::new(
codex_home.path().to_path_buf(),
Arc::new(mock_keyring.clone()),
);
let auth = auth_with_prefix("to-delete");
let auth_file = seed_secrets_backend_and_fallback_auth_file_for_delete(
&mock_keyring,
codex_home.path(),
&auth,
)?;
let removed = storage.delete()?;
assert!(removed, "delete should report removal");
assert_eq!(storage.load()?, None, "encrypted auth should be removed");
assert_eq!(
direct_storage.load()?,
None,
"legacy direct keyring auth should be removed"
);
assert!(
!auth_file.exists(),
"fallback auth.json should be removed after keyring delete"
);
Ok(())
}
#[test]
fn auto_auth_storage_load_prefers_keyring_value() -> anyhow::Result<()> {
let codex_home = tempdir()?;