aKode fase 1: niente sync plugin OpenAI, CDN pets, CIMD chatgpt.com, npm registry; pulizia codice morto

This commit is contained in:
Andrea
2026-11-09 12:06:16 +01:00
parent 5b5b83964d
commit 39a103d16f
34 changed files with 136 additions and 4668 deletions

View File

@@ -127,68 +127,28 @@ async fn authorization(
Ok((state, query))
}
// aKode: CIMD (a ChatGPT-hosted client metadata document) is never offered; automatic
// registration always uses DCR, even when the server advertises CIMD support.
#[tokio::test]
async fn automatic_cimd_uses_stable_or_callback_specific_identity() -> Result<()> {
for (host, supports_issuer, expected_client_id, expected_redirect) in [
async fn automatic_registration_uses_dcr_even_when_cimd_is_advertised() -> Result<()> {
for (host, supports_issuer, expected_redirect) in [
(
"127.0.0.1",
false,
"https://chatgpt.com/oauth/codex/abc123ABC_-x/client.json",
"http://127.0.0.1:43123/callback/abc123ABC_-x",
),
(
"localhost",
false,
"https://chatgpt.com/oauth/codex/abc123ABC_-x/client.json",
"http://localhost:43123/callback/abc123ABC_-x",
),
(
"127.0.0.1",
true,
"https://chatgpt.com/oauth/codex/client.json",
"http://127.0.0.1:43123/callback",
),
("127.0.0.1", true, "http://127.0.0.1:43123/callback"),
] {
let server = oauth_server(json!({
"authorization_response_iss_parameter_supported": supports_issuer,
}))
.await;
let redirect = format!("http://{host}:43123/callback");
let (mut state, query) =
let (_, query) =
authorization(&server, &redirect, McpOAuthClientRegistration::Auto).await?;
assert_eq!(query["client_id"], expected_client_id);
assert_eq!(query["client_id"], "dcr-client");
assert_eq!(query["redirect_uri"], expected_redirect);
assert_eq!(query["code_challenge_method"], "S256");
assert_eq!(query["scope"], "read offline_access");
state
.handle_callback_with_issuer(
"valid-authorization-code",
&query["state"],
supports_issuer
.then(|| format!("{}/mcp", server.uri()))
.as_deref(),
)
.await?;
let token_requests = requests_to(&server, "/token").await;
assert_eq!(token_requests.len(), 1);
let request = &token_requests[0];
let body: HashMap<_, _> = url::form_urlencoded::parse(&request.body)
.into_owned()
.collect();
assert_eq!(body["client_id"], expected_client_id);
assert_eq!(body["redirect_uri"], expected_redirect);
assert_eq!(body["grant_type"], "authorization_code");
assert!(body.contains_key("code_verifier"));
assert!(!body.contains_key("client_secret"));
assert!(!request.headers.contains_key("authorization"));
assert!(requests_to(&server, "/register").await.is_empty());
assert_eq!(
requests_to(&server, "/.well-known/oauth-authorization-server/mcp")
.await
.len(),
1
);
assert_eq!(requests_to(&server, "/register").await.len(), 1);
}
Ok(())
@@ -510,57 +470,21 @@ async fn resource_headers_follow_same_origin_registration_redirect_and_sdk_auth_
}
#[tokio::test]
async fn invalid_cimd_metadata_and_redirects_fail_without_dynamic_registration() {
async fn explicit_cimd_is_rejected_without_contacting_the_server() {
let valid = "http://127.0.0.1:43123/callback/abc123ABC_-x";
for (metadata, redirect, expected_error) in [
(
json!({
"authorization_response_iss_parameter_supported": true,
"issuer": null,
}),
valid,
"issuer-bound callbacks require an authorization server issuer",
),
(
json!({"token_endpoint_auth_methods_supported": ["private_key_jwt"]}),
valid,
"token endpoint auth method `none`",
),
(
json!({}),
"http://127.0.0.1.evil.example:43123/callback/abc123ABC_-x",
"ephemeral loopback callback",
),
(
json!({}),
"http://127.0.0.1/callback/abc123ABC_-x",
"ephemeral loopback callback",
),
(
json!({}),
"http://127.0.0.1:43123/callback/wrong-id",
"ephemeral loopback callback",
),
(
json!({}),
"http://127.0.0.1:43123/callback/abc123ABC_-x?unexpected=true",
"ephemeral loopback callback",
),
(
json!({}),
"http://[::1]:43123/callback/abc123ABC_-x",
"ephemeral loopback callback",
),
] {
let server = oauth_server(metadata).await;
let error = authorization(&server, redirect, McpOAuthClientRegistration::Cimd)
let server = oauth_server(json!({})).await;
let error = authorization(&server, valid, McpOAuthClientRegistration::Cimd)
.await
.err()
.expect("CIMD should be rejected");
assert!(error.to_string().contains("CIMD client registration is not supported"));
assert!(
server
.received_requests()
.await
.err()
.expect("invalid CIMD metadata or callback should fail");
assert!(error.to_string().contains(expected_error));
assert!(requests_to(&server, "/register").await.is_empty());
assert!(requests_to(&server, "/token").await.is_empty());
}
.expect("mock server should record requests")
.is_empty()
);
let server = oauth_server(json!({"registration_endpoint": null})).await;
let error = authorization(&server, valid, McpOAuthClientRegistration::Dcr)