()
| 2572 | |
| 2573 | #[test] |
| 2574 | fn parse_mcp_rules_to_runtime_fields() { |
| 2575 | let yaml = r" |
| 2576 | version: 1 |
| 2577 | network_policies: |
| 2578 | mcp: |
| 2579 | name: mcp |
| 2580 | endpoints: |
| 2581 | - host: mcp.example.com |
| 2582 | port: 443 |
| 2583 | path: /mcp |
| 2584 | protocol: mcp |
| 2585 | enforcement: enforce |
| 2586 | mcp: |
| 2587 | max_body_bytes: 131072 |
| 2588 | strict_tool_names: false |
| 2589 | rules: |
| 2590 | - allow: |
| 2591 | method: initialize |
| 2592 | - allow: |
| 2593 | method: tools/list |
| 2594 | - allow: |
| 2595 | method: tools/call |
| 2596 | tool: |
| 2597 | any: [search_web, list_tools] |
| 2598 | deny_rules: |
| 2599 | - method: tools/call |
| 2600 | tool: send_email |
| 2601 | binaries: |
| 2602 | - path: /usr/bin/curl |
| 2603 | "; |
| 2604 | let proto = parse_sandbox_policy(yaml).expect("parse failed"); |
| 2605 | let ep = &proto.network_policies["mcp"].endpoints[0]; |
| 2606 | |
| 2607 | assert_eq!(ep.protocol, "mcp"); |
| 2608 | assert_eq!(ep.json_rpc_max_body_bytes, 131_072); |
| 2609 | assert_eq!( |
| 2610 | ep.mcp |
| 2611 | .as_ref() |
| 2612 | .and_then(|options| options.strict_tool_names), |
| 2613 | Some(false) |
| 2614 | ); |
| 2615 | assert_eq!(ep.rules.len(), 3); |
| 2616 | assert_eq!(ep.rules[2].allow.as_ref().unwrap().method, "tools/call"); |
| 2617 | assert_eq!( |
| 2618 | ep.rules[2].allow.as_ref().unwrap().params["name"].any, |
| 2619 | vec!["search_web".to_string(), "list_tools".to_string()] |
| 2620 | ); |
| 2621 | assert_eq!(ep.deny_rules.len(), 1); |
| 2622 | assert_eq!(ep.deny_rules[0].method, "tools/call"); |
| 2623 | assert_eq!(ep.deny_rules[0].params["name"].glob, "send_email"); |
| 2624 | } |
| 2625 | |
| 2626 | #[test] |
| 2627 | fn round_trip_mcp_policy_serializes_mcp_expression() { |
nothing calls this directly
no test coverage detected