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:
@@ -41,7 +41,6 @@ use wiremock::matchers::header;
|
||||
use wiremock::matchers::method;
|
||||
use wiremock::matchers::path;
|
||||
|
||||
const CHATGPT_ACCOUNT_ID: &str = "workspace-one";
|
||||
const INITIAL_ACCESS_TOKEN: &str = "header.e30.initial";
|
||||
const REFRESHED_ACCESS_TOKEN: &str = "header.e30.refreshed";
|
||||
|
||||
@@ -60,26 +59,21 @@ impl ExternalAuth for ScriptedExternalAuth {
|
||||
Box::pin(async move { auth })
|
||||
}
|
||||
|
||||
fn refresh(&self, context: ExternalAuthRefreshContext) -> ExternalAuthFuture<'_, CodexAuth> {
|
||||
let auth = if context.previous_account_id.as_deref() != Some(CHATGPT_ACCOUNT_ID) {
|
||||
Err(std::io::Error::other(
|
||||
"external auth refresh changed the ChatGPT workspace",
|
||||
))
|
||||
} else {
|
||||
self.current
|
||||
.lock()
|
||||
.map_err(|_| std::io::Error::other("external auth lock is poisoned"))
|
||||
.map(|mut current| {
|
||||
*current = self.refreshed.clone();
|
||||
self.refreshed.clone()
|
||||
})
|
||||
};
|
||||
fn refresh(&self, _context: ExternalAuthRefreshContext) -> ExternalAuthFuture<'_, CodexAuth> {
|
||||
let auth = self
|
||||
.current
|
||||
.lock()
|
||||
.map_err(|_| std::io::Error::other("external auth lock is poisoned"))
|
||||
.map(|mut current| {
|
||||
*current = self.refreshed.clone();
|
||||
self.refreshed.clone()
|
||||
});
|
||||
Box::pin(async move { auth })
|
||||
}
|
||||
}
|
||||
|
||||
fn external_chatgpt_auth(access_token: &str) -> std::io::Result<CodexAuth> {
|
||||
CodexAuth::from_external_chatgpt_tokens(access_token, CHATGPT_ACCOUNT_ID, Some("enterprise"))
|
||||
fn external_bearer_auth(access_token: &str) -> CodexAuth {
|
||||
CodexAuth::from_api_key(access_token)
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
@@ -722,7 +716,7 @@ async fn amazon_bedrock_aws_auth_refresh_resigns() -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn external_auth_401_retry_uses_refreshed_chatgpt_headers() -> anyhow::Result<()> {
|
||||
async fn external_auth_401_retry_uses_refreshed_headers() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = start_mock_server().await;
|
||||
@@ -732,7 +726,6 @@ async fn external_auth_401_retry_uses_refreshed_chatgpt_headers() -> anyhow::Res
|
||||
"authorization",
|
||||
format!("Bearer {INITIAL_ACCESS_TOKEN}"),
|
||||
))
|
||||
.and(header("chatgpt-account-id", CHATGPT_ACCOUNT_ID))
|
||||
.respond_with(ResponseTemplate::new(401).set_body_string("unauthorized"))
|
||||
.expect(1)
|
||||
.mount(&server)
|
||||
@@ -743,7 +736,6 @@ async fn external_auth_401_retry_uses_refreshed_chatgpt_headers() -> anyhow::Res
|
||||
"authorization",
|
||||
format!("Bearer {REFRESHED_ACCESS_TOKEN}"),
|
||||
))
|
||||
.and(header("chatgpt-account-id", CHATGPT_ACCOUNT_ID))
|
||||
.respond_with(
|
||||
ResponseTemplate::new(200)
|
||||
.insert_header("content-type", "text/event-stream")
|
||||
@@ -788,8 +780,8 @@ async fn install_scripted_external_auth(
|
||||
test: &core_test_support::test_codex::TestCodex,
|
||||
) -> anyhow::Result<()> {
|
||||
let external_auth = Arc::new(ScriptedExternalAuth {
|
||||
current: Mutex::new(external_chatgpt_auth(INITIAL_ACCESS_TOKEN)?),
|
||||
refreshed: external_chatgpt_auth(REFRESHED_ACCESS_TOKEN)?,
|
||||
current: Mutex::new(external_bearer_auth(INITIAL_ACCESS_TOKEN)),
|
||||
refreshed: external_bearer_auth(REFRESHED_ACCESS_TOKEN),
|
||||
});
|
||||
test.thread_manager
|
||||
.auth_manager()
|
||||
|
||||
Reference in New Issue
Block a user