Files
codex/codex-rs/rmcp-client/src/ema_auth_policy_tests.rs
T
Nick Steele 9b4a0f8a0a Add enterprise IdP identity resolution for MCP OAuth (#40739)
## What changed

- Resolve stored enterprise IdP sessions against discovered authorization
  metadata, requiring the configured issuer, public-client authentication, and
  supported ID-JAG token exchange capabilities.
- Bind OIDC identity claims and MCP resource indicators to their configured
  issuer, client, and server, and require reauthentication when pinned keyring
  credentials are removed or replaced.
- Hold the credential lock while rereading refresh tokens, and isolate
  enterprise credentials by reserved namespace and Codex home.

## Testing

- Cover metadata and claim validation, resource binding, credential replacement
  and keyring failures, refresh locking, expired ID tokens, and credential
  namespace isolation.

GitOrigin-RevId: edce3c6159f7d6831edf72e9608b3fc3f5823c83
2026-08-25 23:51:57 +00:00

52 lines
1.6 KiB
Rust

use pretty_assertions::assert_eq;
use serde_json::json;
use super::*;
#[test]
fn resource_origin_query_and_path_are_bound() {
let server = "https://mcp.example/enterprise/tools?tenant=one";
for (resource, valid) in [
("https://mcp.example/enterprise?tenant=one", true),
("https://other.example/enterprise?tenant=one", false),
("https://mcp.example/enterprise-admin?tenant=one", false),
("https://mcp.example/enterprise?tenant=two", false),
("https://mcp.example/enterprise", false),
("http://localhost:4000/enterprise?tenant=one", false),
] {
assert_eq!(
validate_ema_auth_resource(server, Some(resource)).is_ok(),
valid,
"{resource}"
);
}
for (server, valid) in [
("https://mcp.example/mcp", true),
("http://localhost:4000/mcp", true),
("http://127.0.0.1:4000/mcp", true),
("http://mcp.example/mcp", false),
] {
assert_eq!(
validate_ema_auth_resource(server, /*resource*/ None).is_ok(),
valid,
"{server}"
);
}
}
#[test]
fn public_clients_require_an_explicitly_advertised_auth_method() {
for (advertised, valid) in [
(None, false),
(Some(json!(["none"])), true),
(Some(json!(["client_secret_basic", "none"])), true),
(Some(json!(["private_key_jwt"])), false),
(Some(json!("none")), false),
] {
assert_eq!(
validate_ema_public_client_auth(advertised.as_ref(), "IdP").is_ok(),
valid
);
}
}