WIP fase 2b-3: rimozione sottosistemi solo-ChatGPT (plugin remoti, image gen, daybreak, cyber, attestation, cloud config, app/connettori) - test in corso
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
//! Exercises the MCP-to-core ceremony without depending on biometric hardware.
|
||||
//! Verifies that MCP user-verification ceremonies are never honored for a user-configured
|
||||
//! server: the capability is stripped and any request is refused without prompting.
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
@@ -7,24 +8,15 @@ use anyhow::Result;
|
||||
use axum::Router;
|
||||
use codex_config::Constrained;
|
||||
use codex_core::StartThreadOptions;
|
||||
use codex_core::config::Config;
|
||||
use codex_extension_api::ExtensionFuture;
|
||||
use codex_extension_api::ExtensionRegistryBuilder;
|
||||
use codex_extension_api::McpServerContribution;
|
||||
use codex_extension_api::McpServerContributionContext;
|
||||
use codex_extension_api::McpServerContributor;
|
||||
use codex_mcp::CODEX_APPS_MCP_SERVER_NAME;
|
||||
use codex_protocol::approvals::ElicitationRequest;
|
||||
use codex_protocol::mcp::ClientMcpExtensions;
|
||||
use codex_protocol::mcp::OPENAI_ELICITATION_EXTENSION_ID;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use codex_protocol::protocol::ElicitationAction;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::Op;
|
||||
use core_test_support::apps_test_server::apps_enabled_builder;
|
||||
use core_test_support::mcp_test_server::MCP_TEST_SERVER_NAME;
|
||||
use core_test_support::mcp_test_server::MCP_TEST_SERVER_PATH;
|
||||
use core_test_support::mcp_test_server::mcp_server_builder;
|
||||
use core_test_support::responses::start_mock_server;
|
||||
use core_test_support::wait_for_event;
|
||||
use pretty_assertions::assert_eq;
|
||||
use rmcp::ServerHandler;
|
||||
use rmcp::model::CallToolRequestParams;
|
||||
@@ -50,26 +42,7 @@ use tokio_util::task::AbortOnDropHandle;
|
||||
#[derive(Clone)]
|
||||
struct VerificationServer {
|
||||
response: Arc<Mutex<Option<Value>>>,
|
||||
}
|
||||
|
||||
struct HostedVerificationServer(codex_config::McpServerConfig);
|
||||
|
||||
impl McpServerContributor<Config> for HostedVerificationServer {
|
||||
fn id(&self) -> &'static str {
|
||||
"user-verification-integration-test"
|
||||
}
|
||||
|
||||
fn contribute<'a>(
|
||||
&'a self,
|
||||
_context: McpServerContributionContext<'a, Config>,
|
||||
) -> ExtensionFuture<'a, Vec<McpServerContribution>> {
|
||||
Box::pin(async move {
|
||||
vec![McpServerContribution::HostedApps {
|
||||
config: Box::new(self.0.clone()),
|
||||
protocol_mode: None,
|
||||
}]
|
||||
})
|
||||
}
|
||||
elicitation_extension: Arc<Mutex<Option<Option<Value>>>>,
|
||||
}
|
||||
|
||||
impl ServerHandler for VerificationServer {
|
||||
@@ -82,13 +55,12 @@ impl ServerHandler for VerificationServer {
|
||||
_request: CallToolRequestParams,
|
||||
context: RequestContext<RoleServer>,
|
||||
) -> Result<CallToolResponse, rmcp::ErrorData> {
|
||||
assert_eq!(
|
||||
*self.elicitation_extension.lock().await = Some(
|
||||
context
|
||||
.client_capabilities()
|
||||
.and_then(|capabilities| capabilities.extensions)
|
||||
.and_then(|extensions| extensions.get(OPENAI_ELICITATION_EXTENSION_ID).cloned())
|
||||
.map(Value::Object),
|
||||
Some(json!({"userVerification": {}})),
|
||||
);
|
||||
let result = context
|
||||
.peer
|
||||
@@ -102,22 +74,25 @@ impl ServerHandler for VerificationServer {
|
||||
"_meta": {"example/display": {"label": "Operation"}},
|
||||
})),
|
||||
)))
|
||||
.await
|
||||
.map_err(|error| {
|
||||
.await;
|
||||
let outcome = match result {
|
||||
Ok(result) => serde_json::to_value(result).map_err(|error| {
|
||||
rmcp::ErrorData::internal_error(error.to_string(), /*data*/ None)
|
||||
})?;
|
||||
*self.response.lock().await = Some(serde_json::to_value(result).map_err(|error| {
|
||||
rmcp::ErrorData::internal_error(error.to_string(), /*data*/ None)
|
||||
})?);
|
||||
Ok(CallToolResult::success(vec![ContentBlock::text("verified")]).into())
|
||||
})?,
|
||||
Err(error) => json!({ "error": error.to_string() }),
|
||||
};
|
||||
*self.response.lock().await = Some(outcome);
|
||||
Ok(CallToolResult::success(vec![ContentBlock::text("unverified")]).into())
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
||||
async fn user_verification_mcp_round_trip_requires_proof_in_full_access() -> Result<()> {
|
||||
async fn user_verification_mcp_request_is_cancelled_without_prompt_in_full_access() -> Result<()> {
|
||||
let received = Arc::new(Mutex::new(None));
|
||||
let elicitation_extension = Arc::new(Mutex::new(None));
|
||||
let server = VerificationServer {
|
||||
response: Arc::clone(&received),
|
||||
elicitation_extension: Arc::clone(&elicitation_extension),
|
||||
};
|
||||
let service = StreamableHttpService::new(
|
||||
move || Ok(server.clone()),
|
||||
@@ -126,18 +101,12 @@ async fn user_verification_mcp_round_trip_requires_proof_in_full_access() -> Res
|
||||
);
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await?;
|
||||
let base_url = format!("http://{}", listener.local_addr()?);
|
||||
let router = Router::new().nest_service("/api/codex/ps/mcp", service);
|
||||
let router = Router::new().nest_service(MCP_TEST_SERVER_PATH, service);
|
||||
let _server = AbortOnDropHandle::new(tokio::spawn(async move {
|
||||
axum::serve(listener, router).await.unwrap();
|
||||
}));
|
||||
let model_server = start_mock_server().await;
|
||||
let mut extensions = ExtensionRegistryBuilder::new();
|
||||
let plugin_service_config = serde_json::from_value(json!({
|
||||
"url": format!("{base_url}/api/codex/ps/mcp"),
|
||||
}))?;
|
||||
extensions.mcp_server_contributor(Arc::new(HostedVerificationServer(plugin_service_config)));
|
||||
let test = apps_enabled_builder(base_url)
|
||||
.with_extensions(Arc::new(extensions.build()))
|
||||
let test = mcp_server_builder(base_url)
|
||||
.with_config(|config| {
|
||||
config.permissions.approval_policy = Constrained::allow_any(AskForApproval::Never);
|
||||
config
|
||||
@@ -147,8 +116,8 @@ async fn user_verification_mcp_round_trip_requires_proof_in_full_access() -> Res
|
||||
})
|
||||
.build_with_auto_env(&model_server)
|
||||
.await?;
|
||||
// Supply the trusted host capability through the public core API. The production
|
||||
// app-server only activates it for supported in-process UIs with biometric hardware.
|
||||
// Even a host that declares the user-verification capability must not grant it to an
|
||||
// ordinary user-configured MCP server.
|
||||
let thread = test
|
||||
.thread_manager
|
||||
.start_thread(StartThreadOptions {
|
||||
@@ -165,55 +134,54 @@ async fn user_verification_mcp_round_trip_requires_proof_in_full_access() -> Res
|
||||
let call = AbortOnDropHandle::new(tokio::spawn(async move {
|
||||
caller
|
||||
.call_mcp_tool(
|
||||
CODEX_APPS_MCP_SERVER_NAME,
|
||||
MCP_TEST_SERVER_NAME,
|
||||
"verify_action",
|
||||
/*arguments*/ None,
|
||||
/*meta*/ None,
|
||||
)
|
||||
.await
|
||||
}));
|
||||
let EventMsg::ElicitationRequest(request) = wait_for_event(&thread, |event| {
|
||||
matches!(event, EventMsg::ElicitationRequest(_))
|
||||
})
|
||||
.await
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
assert_eq!(request.server_name, CODEX_APPS_MCP_SERVER_NAME);
|
||||
assert_eq!(
|
||||
request.request,
|
||||
ElicitationRequest::UserVerification {
|
||||
meta: Some(json!({"example/display": {"label": "Operation"}})),
|
||||
title: "Approve purchase".into(),
|
||||
description: "Pay $200 to Example Store".into(),
|
||||
challenge: "AAECA_7_".into(),
|
||||
}
|
||||
);
|
||||
assert!(received.lock().await.is_none());
|
||||
assert!(!call.is_finished());
|
||||
let proof = json!({"credentialId": "AQID", "signature": "BAUG"});
|
||||
thread
|
||||
.submit(Op::ResolveElicitation {
|
||||
server_name: request.server_name,
|
||||
request_id: request.id,
|
||||
decision: ElicitationAction::Accept,
|
||||
content: Some(proof.clone()),
|
||||
meta: Some(json!({"untrusted": "discarded"})),
|
||||
})
|
||||
.await?;
|
||||
// The ceremony is refused without surfacing a prompt, so the call completes unattended.
|
||||
assert_eq!(
|
||||
timeout(Duration::from_secs(/*secs*/ 10), call).await???,
|
||||
codex_protocol::mcp::CallToolResult {
|
||||
content: vec![json!({"type": "text", "text": "verified"})],
|
||||
content: vec![json!({"type": "text", "text": "unverified"})],
|
||||
structured_content: None,
|
||||
is_error: Some(false),
|
||||
meta: None,
|
||||
},
|
||||
);
|
||||
assert_eq!(
|
||||
*received.lock().await,
|
||||
Some(json!({"action": "accept", "content": proof})),
|
||||
// Without the capability the client rejects the request outright; it never returns a
|
||||
// proof or an acceptance.
|
||||
let outcome = received
|
||||
.lock()
|
||||
.await
|
||||
.clone()
|
||||
.expect("server recorded the verification outcome");
|
||||
let error = outcome["error"]
|
||||
.as_str()
|
||||
.unwrap_or_else(|| panic!("user verification must not succeed: {outcome}"));
|
||||
assert!(error.contains("-32601"), "{error}");
|
||||
let advertised = elicitation_extension
|
||||
.lock()
|
||||
.await
|
||||
.clone()
|
||||
.expect("tool call recorded the client capabilities");
|
||||
assert!(
|
||||
advertised
|
||||
.as_ref()
|
||||
.and_then(|settings| settings.get("userVerification"))
|
||||
.is_none(),
|
||||
"user verification capability leaked to the server: {advertised:?}"
|
||||
);
|
||||
while let Ok(Ok(event)) =
|
||||
timeout(Duration::from_millis(/*millis*/ 200), thread.next_event()).await
|
||||
{
|
||||
assert!(
|
||||
!matches!(event.msg, EventMsg::ElicitationRequest(_)),
|
||||
"user verification must not prompt: {event:?}"
|
||||
);
|
||||
}
|
||||
thread.shutdown_and_wait().await?;
|
||||
test.codex.shutdown_and_wait().await?;
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user