camel-api 0.35.0

Core traits and interfaces for rust-camel
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
use std::sync::Arc;

use async_trait::async_trait;
use serde::{Deserialize, Serialize};

use crate::{CamelError, Exchange};

/// Represents an authenticated principal extracted from token claims.
///
/// Provider-neutral: the `ClaimsMapper` trait in `camel-auth` is responsible
/// for mapping provider-specific claim shapes into this structure.
#[derive(Clone, PartialEq, Serialize, Deserialize)]
pub struct Principal {
    pub subject: String,
    #[serde(default)]
    pub issuer: String,
    #[serde(default)]
    pub audience: Vec<String>,
    pub scopes: Vec<String>,
    pub roles: Vec<String>,
    pub claims: serde_json::Value,
}

impl Principal {
    /// Check if the principal has a specific role.
    pub fn has_role(&self, role: &str) -> bool {
        self.roles.iter().any(|r| r == role)
    }

    /// Check if the principal has a specific scope.
    pub fn has_scope(&self, scope: &str) -> bool {
        self.scopes.iter().any(|s| s == scope)
    }
}

// Manual Debug redacts untrusted `claims` (PII leak fix rc-yv1m).
// Do NOT add `Debug` to the #[derive(...)] above — it would reintroduce the leak.
impl std::fmt::Debug for Principal {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("Principal")
            .field("subject", &self.subject)
            .field("issuer", &self.issuer)
            .field("audience", &self.audience)
            .field("scopes", &self.scopes)
            .field("roles", &self.roles)
            .field("claims", &"[REDACTED]")
            .finish()
    }
}

#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum AuthorizationDecision {
    /// Access granted.
    ///
    /// `principal` is the policy's advisory asserted principal, stored to
    /// exchange properties for observability. It is NOT the authentication
    /// identity; that always comes from the [`AuthContext`] principal.
    Granted { principal: Principal },
    Denied {
        reason: String,
        required: Vec<String>,
        actual: Vec<String>,
    },
}

impl std::fmt::Display for AuthorizationDecision {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Granted { principal } => {
                write!(f, "Access granted for {}", principal.subject)
            }
            Self::Denied { reason, .. } => write!(f, "Access denied: {reason}"),
        }
    }
}

/// Transport kinds that can host a server route.
///
/// Closed set: `http:`, `ws:`, `grpc:`, `mcp:`, and `wasm:` (source
/// routes hosting an http-listener) are the only transports that
/// terminate requests and run authorization.
///
/// exhaustive-by-contract: closed transport set; a new transport is an
/// architectural change, not additive growth.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum TransportId {
    Http,
    Ws,
    Grpc,
    Mcp,
    Wasm,
}

/// Read-only view of the principal minted by the authentication path.
///
/// camel-api must never name a `camel-auth` type (no dependency cycle), so the
/// concrete `AuthenticatedPrincipal` lives in `camel-auth` and this crate
/// consumes it through this trait.
pub trait AuthPrincipal: Send + Sync {
    /// The authenticated principal.
    fn principal(&self) -> &Principal;
    /// The identifier of the provider that minted this principal.
    fn provider_id(&self) -> &str;
}

/// Authentication context handed to a [`SecurityPolicy`] during evaluation.
///
/// Carries the authenticated principal and the transport that carried the
/// request. The `AuthContext` principal is the authentication identity; a
/// policy's `Granted { principal }` value is advisory only.
pub struct AuthContext<'a> {
    pub principal: &'a dyn AuthPrincipal,
    pub transport: TransportId,
}

#[async_trait]
pub trait SecurityPolicy: Send + Sync {
    async fn evaluate(
        &self,
        exchange: &mut Exchange,
        auth: &AuthContext<'_>,
    ) -> Result<AuthorizationDecision, CamelError>;
}

/// Name of the input header camel-http uses to carry the raw HTTP query string.
///
/// camel-http stores the request query (the part after `?`) as a string header
/// under this exact name (`crates/components/camel-http/src/lib.rs`).
/// camel-auth cannot depend on camel-http, so this contract constant lives in
/// camel-api. `QueryParam` extraction reads the raw query from this header.
pub const CAMEL_HTTP_QUERY_HEADER: &str = "CamelHttpQuery";

/// Source from which a token can be extracted.
///
/// exhaustive-by-contract: closed source set; out-of-crate camel-auth
/// extraction matches all variants, so adding a source must update every
/// match site by review.
#[derive(Clone, PartialEq, Eq)]
pub enum CredentialSource {
    /// Extract from the `Authorization` header (Bearer scheme).
    AuthorizationHeader,
    /// Extract from a query parameter with the given name.
    QueryParam { param: String },
    /// Extract from a cookie with the given name.
    Cookie { name: String },
    /// Extract from a named request header (API-key style).
    ///
    /// The extracted value flows into the same constant-time
    /// `NativeCredentialStore::lookup` as every other source.
    Header { name: String },
}

impl CredentialSource {
    /// Returns the variant name without exposing sensitive values.
    pub fn variant_name(&self) -> &'static str {
        match self {
            CredentialSource::AuthorizationHeader => "AuthorizationHeader",
            CredentialSource::QueryParam { .. } => "QueryParam",
            CredentialSource::Cookie { .. } => "Cookie",
            CredentialSource::Header { .. } => "Header",
        }
    }
}

impl std::fmt::Debug for CredentialSource {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            CredentialSource::AuthorizationHeader => f.write_str("AuthorizationHeader"),
            CredentialSource::QueryParam { param } => {
                write!(f, "QueryParam {{ param: {:?} }}", param) // allow-secret
            }
            CredentialSource::Cookie { name } => {
                write!(f, "Cookie {{ name: {:?} }}", name) // allow-secret
            }
            CredentialSource::Header { name } => {
                write!(f, "Header {{ name: {:?} }}", name) // allow-secret
            }
        }
    }
}

pub struct SecurityPolicyConfig {
    pub policy: Arc<dyn SecurityPolicy>,
    /// Extraction sources for the route's credential, in declared order.
    /// Defaults to header-only (fail-closed, ADR-0033).
    pub credential_sources: Vec<CredentialSource>,
}

impl SecurityPolicyConfig {
    pub fn new(policy: impl SecurityPolicy + 'static) -> Self {
        Self {
            policy: Arc::new(policy),
            credential_sources: vec![CredentialSource::AuthorizationHeader],
        }
    }

    pub fn from_arc(policy: Arc<dyn SecurityPolicy>) -> Self {
        Self {
            policy,
            credential_sources: vec![CredentialSource::AuthorizationHeader],
        }
    }

    pub fn with_credential_sources(mut self, sources: Vec<CredentialSource>) -> Self {
        self.credential_sources = sources;
        self
    }
}

impl Clone for SecurityPolicyConfig {
    fn clone(&self) -> Self {
        Self {
            policy: Arc::clone(&self.policy),
            credential_sources: self.credential_sources.clone(),
        }
    }
}

impl std::fmt::Debug for SecurityPolicyConfig {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("SecurityPolicyConfig")
            .field("policy", &"<SecurityPolicy>")
            .field("credential_sources", &self.credential_sources)
            .finish()
    }
}

/// Access classification for a compiled route.
///
/// `Public` needs no authentication. `Authenticated` requires a principal but
/// no authorization policy. `Authorized` runs a policy against the
/// authenticated principal.
///
/// exhaustive-by-contract: closed enforcement model; modes are kernel
/// semantics, additions are deliberate breaking changes.
pub enum AccessMode {
    Public,
    Authenticated,
    Authorized(Arc<dyn SecurityPolicy>),
}

impl Clone for AccessMode {
    fn clone(&self) -> Self {
        match self {
            Self::Public => Self::Public,
            Self::Authenticated => Self::Authenticated,
            Self::Authorized(policy) => Self::Authorized(Arc::clone(policy)),
        }
    }
}

impl std::fmt::Debug for AccessMode {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Public => f.write_str("Public"),
            Self::Authenticated => f.write_str("Authenticated"),
            Self::Authorized(_) => f.write_str("Authorized(<SecurityPolicy>)"),
        }
    }
}

/// Accepted issuer and audience set for a route's authentication.
///
/// Reserved in Phase 1; enforcement and cache-key participation arrive in
/// Phase 3. Every configured accepted audience is kept.
#[derive(Clone, Debug, PartialEq)]
pub struct AudienceBinding {
    pub issuers: Vec<String>,
    pub audiences: Vec<String>,
}

/// Compiled security plan for a single server route.
///
/// Produced at staging time, before any listener binds. `access_mode`
/// classifies the route; `provider_ref` is mandatory for
/// `Authenticated`/`Authorized` and absent for `Public`.
pub struct RouteSecurityPlan {
    pub access_mode: AccessMode,
    pub provider_ref: Option<String>,
    pub transport: TransportId,
    pub credential_sources: Vec<CredentialSource>,
    pub audience_binding: Option<AudienceBinding>,
}

impl Clone for RouteSecurityPlan {
    fn clone(&self) -> Self {
        Self {
            access_mode: self.access_mode.clone(),
            provider_ref: self.provider_ref.clone(),
            transport: self.transport,
            credential_sources: self.credential_sources.clone(),
            audience_binding: self.audience_binding.clone(),
        }
    }
}

impl std::fmt::Debug for RouteSecurityPlan {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("RouteSecurityPlan")
            .field("access_mode", &self.access_mode)
            .field("provider_ref", &self.provider_ref)
            .field("transport", &self.transport)
            .field("credential_sources", &self.credential_sources)
            .field("audience_binding", &self.audience_binding)
            .finish()
    }
}

// --- Principal property storage helpers ---

/// Exchange property key for the principal's subject.
pub const PRINCIPAL_SUBJECT_KEY: &str = "camel.auth.subject";
/// Exchange property key for the principal's roles (JSON array).
pub const PRINCIPAL_ROLES_KEY: &str = "camel.auth.roles";
/// Exchange property key for the principal's scopes (JSON array).
pub const PRINCIPAL_SCOPES_KEY: &str = "camel.auth.scopes";
/// Exchange property key for the principal's issuer.
pub const PRINCIPAL_ISSUER_KEY: &str = "camel.auth.issuer";
/// Exchange property key for the principal's raw claims (JSON object).
pub const PRINCIPAL_CLAIMS_KEY: &str = "camel.auth.claims";
/// Exchange property key for the principal's audience (JSON array).
pub const PRINCIPAL_AUDIENCE_KEY: &str = "camel.auth.audience";
/// Exchange property key for the full serialized principal.
pub const PRINCIPAL_KEY: &str = "camel.auth.principal";

/// Store all principal properties as exchange properties under well-known keys.
pub fn store_principal_properties(exchange: &mut Exchange, principal: &Principal) {
    exchange.set_property(PRINCIPAL_SUBJECT_KEY, principal.subject.clone());
    exchange.set_property(
        PRINCIPAL_ROLES_KEY,
        serde_json::to_string(&principal.roles).unwrap_or_default(),
    );
    exchange.set_property(
        PRINCIPAL_SCOPES_KEY,
        serde_json::to_string(&principal.scopes).unwrap_or_default(),
    );
    exchange.set_property(PRINCIPAL_ISSUER_KEY, principal.issuer.clone());
    exchange.set_property(
        PRINCIPAL_CLAIMS_KEY,
        serde_json::to_string(&principal.claims).unwrap_or_default(),
    );
    exchange.set_property(
        PRINCIPAL_AUDIENCE_KEY,
        serde_json::to_string(&principal.audience).unwrap_or_default(),
    );
    exchange.set_property(
        PRINCIPAL_KEY,
        serde_json::to_string(principal).unwrap_or_default(),
    );
}

pub fn principal_from_exchange(exchange: &Exchange) -> Option<Principal> {
    exchange
        .property(PRINCIPAL_KEY)
        .and_then(|v| v.as_str())
        .and_then(|s| serde_json::from_str(s).ok())
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::Body;

    fn test_principal(roles: Vec<&str>, scopes: Vec<&str>) -> Principal {
        Principal {
            subject: "user1".into(),
            issuer: "test".into(),
            audience: vec![],
            scopes: scopes.into_iter().map(String::from).collect(),
            roles: roles.into_iter().map(String::from).collect(),
            claims: serde_json::Value::Null,
        }
    }

    /// A `SecurityPolicy` that always grants to `test_principal(vec![], vec![])`.
    fn grant_policy() -> impl SecurityPolicy + 'static {
        struct GrantPolicy;

        #[async_trait]
        impl SecurityPolicy for GrantPolicy {
            async fn evaluate(
                &self,
                _exchange: &mut Exchange,
                _auth: &AuthContext<'_>,
            ) -> Result<AuthorizationDecision, CamelError> {
                Ok(AuthorizationDecision::Granted {
                    principal: test_principal(vec![], vec![]),
                })
            }
        }

        GrantPolicy
    }

    #[test]
    fn principal_has_role_is_case_sensitive() {
        let p = test_principal(vec!["Admin", "User"], vec![]);
        assert!(!p.has_role("admin"));
        assert!(!p.has_role("ADMIN"));
        assert!(p.has_role("User"));
        assert!(!p.has_role("guest"));
    }

    #[test]
    fn principal_has_scope() {
        let p = test_principal(vec![], vec!["read", "write"]);
        assert!(p.has_scope("read"));
        assert!(!p.has_scope("delete"));
    }

    #[test]
    fn authorization_decision_granted_display() {
        let p = test_principal(vec![], vec![]);
        let d = AuthorizationDecision::Granted { principal: p };
        assert!(format!("{d}").contains("user1"));
    }

    #[test]
    fn authorization_decision_denied_display() {
        let d = AuthorizationDecision::Denied {
            reason: "missing role".into(),
            required: vec!["admin".into()],
            actual: vec![],
        };
        assert!(format!("{d}").contains("missing role"));
    }

    #[test]
    fn security_policy_config_debug_redacts_policy() {
        let config = SecurityPolicyConfig::new(grant_policy());
        let debug = format!("{config:?}");
        assert!(debug.contains("SecurityPolicyConfig"));
        assert!(debug.contains("<SecurityPolicy>"));
    }

    #[test]
    fn security_policy_config_new_is_header_only() {
        let config = SecurityPolicyConfig::new(grant_policy());
        assert_eq!(
            config.credential_sources,
            vec![CredentialSource::AuthorizationHeader]
        );
    }

    #[test]
    fn store_principal_properties_populates_all_keys() {
        let principal = Principal {
            subject: "alice".into(),
            issuer: "keycloak".into(),
            audience: vec!["api".into()],
            scopes: vec!["read".into(), "write".into()],
            roles: vec!["admin".into()],
            claims: serde_json::json!({"sub": "alice", "custom": true}),
        };
        let mut exchange = Exchange::new(crate::Message::new(Body::Empty));
        store_principal_properties(&mut exchange, &principal);

        assert_eq!(
            exchange.property(PRINCIPAL_SUBJECT_KEY).unwrap(),
            &serde_json::Value::String("alice".into())
        );
        assert_eq!(
            exchange.property(PRINCIPAL_ISSUER_KEY).unwrap(),
            &serde_json::Value::String("keycloak".into())
        );
        let roles: Vec<String> = serde_json::from_str(
            exchange
                .property(PRINCIPAL_ROLES_KEY)
                .unwrap()
                .as_str()
                .unwrap(),
        )
        .unwrap();
        assert_eq!(roles, vec!["admin"]);
        let scopes: Vec<String> = serde_json::from_str(
            exchange
                .property(PRINCIPAL_SCOPES_KEY)
                .unwrap()
                .as_str()
                .unwrap(),
        )
        .unwrap();
        assert_eq!(scopes, vec!["read", "write"]);
        let audience: Vec<String> = serde_json::from_str(
            exchange
                .property(PRINCIPAL_AUDIENCE_KEY)
                .unwrap()
                .as_str()
                .unwrap(),
        )
        .unwrap();
        assert_eq!(audience, vec!["api"]);
        let claims: serde_json::Value = serde_json::from_str(
            exchange
                .property(PRINCIPAL_CLAIMS_KEY)
                .unwrap()
                .as_str()
                .unwrap(),
        )
        .unwrap();
        assert!(claims.as_object().unwrap().contains_key("custom"));
        let full: serde_json::Value =
            serde_json::from_str(exchange.property(PRINCIPAL_KEY).unwrap().as_str().unwrap())
                .unwrap();
        assert_eq!(full["subject"], "alice");
    }

    #[test]
    fn security_policy_config_clone() {
        let config = SecurityPolicyConfig::new(grant_policy());
        let cloned = config.clone();
        // Both point to same Arc
        assert!(Arc::ptr_eq(&config.policy, &cloned.policy));
    }

    #[test]
    fn test_principal_from_exchange_round_trip() {
        let principal = Principal {
            subject: "bob".into(),
            issuer: "keycloak".into(),
            audience: vec!["api".into()],
            scopes: vec!["read".into()],
            roles: vec!["user".into()],
            claims: serde_json::json!({"sub": "bob"}),
        };
        let mut exchange = Exchange::new(crate::Message::new(Body::Empty));
        store_principal_properties(&mut exchange, &principal);

        let recovered = principal_from_exchange(&exchange).expect("principal should be recovered");
        assert_eq!(recovered.subject, "bob");
        assert_eq!(recovered.issuer, "keycloak");
        assert_eq!(recovered.audience, vec!["api"]);
        assert_eq!(recovered.scopes, vec!["read"]);
        assert_eq!(recovered.roles, vec!["user"]);
    }

    #[test]
    fn principal_debug_redacts_claims_compact() {
        let principal = Principal {
            subject: "subj-1".into(),
            issuer: "iss".into(),
            audience: vec!["a1".into()],
            scopes: vec!["s1".into()],
            roles: vec!["r1".into()],
            claims: serde_json::json!({"piid": "SENTINEL_CLAIM_VALUE_9kq2"}),
        };
        let s = format!("{principal:?}");
        assert!(
            s.contains("claims: \"[REDACTED]\""),
            "compact debug should show [REDACTED] for claims"
        );
        assert!(
            !s.contains("SENTINEL_CLAIM_VALUE_9kq2"),
            "compact debug should NOT contain raw claim value"
        );
        assert!(s.contains("subj-1"), "compact debug should contain subject");
        assert!(s.contains("iss"), "compact debug should contain issuer");
        assert!(s.contains("a1"), "compact debug should contain audience");
        assert!(s.contains("s1"), "compact debug should contain scopes");
        assert!(s.contains("r1"), "compact debug should contain roles");
    }

    #[test]
    fn principal_debug_redacts_claims_pretty() {
        let principal = Principal {
            subject: "subj-1".into(),
            issuer: "iss".into(),
            audience: vec!["a1".into()],
            scopes: vec!["s1".into()],
            roles: vec!["r1".into()],
            claims: serde_json::json!({"piid": "SENTINEL_CLAIM_VALUE_9kq2"}),
        };
        let s = format!("{principal:#?}");
        assert!(
            s.contains("[REDACTED]"),
            "pretty debug should show [REDACTED]"
        );
        assert!(
            !s.contains("SENTINEL_CLAIM_VALUE_9kq2"),
            "pretty debug should NOT contain raw claim value"
        );
    }

    #[test]
    fn principal_serialize_preserves_claims() {
        let principal = Principal {
            subject: "subj-1".into(),
            issuer: "iss".into(),
            audience: vec!["a1".into()],
            scopes: vec!["s1".into()],
            roles: vec!["r1".into()],
            claims: serde_json::json!({"piid": "SENTINEL_CLAIM_VALUE_9kq2"}),
        };
        let s = serde_json::to_string(&principal).unwrap();
        assert!(
            s.contains("SENTINEL_CLAIM_VALUE_9kq2"),
            "serialization should preserve raw claim value"
        );
    }

    #[test]
    fn access_mode_debug_redacts_policy() {
        let mode = AccessMode::Authorized(Arc::new(grant_policy()));
        let debug = format!("{mode:?}");
        assert!(debug.contains("<SecurityPolicy>"));
        assert!(!debug.contains("GrantPolicy"));
    }

    #[test]
    fn transport_id_derives_all() {
        fn name(t: TransportId) -> &'static str {
            match t {
                TransportId::Http => "http",
                TransportId::Ws => "ws",
                TransportId::Grpc => "grpc",
                TransportId::Mcp => "mcp",
                TransportId::Wasm => "wasm",
            }
        }
        assert_eq!(name(TransportId::Http), "http");
        assert_eq!(name(TransportId::Ws), "ws");
        assert_eq!(name(TransportId::Grpc), "grpc");
        assert_eq!(name(TransportId::Mcp), "mcp");
        assert_eq!(name(TransportId::Wasm), "wasm");
    }

    #[test]
    fn route_security_plan_clone_debug() {
        let plan = RouteSecurityPlan {
            access_mode: AccessMode::Authenticated,
            provider_ref: Some("idp-a".to_string()),
            transport: TransportId::Http,
            credential_sources: vec![CredentialSource::AuthorizationHeader],
            audience_binding: None,
        };
        let cloned = plan.clone();
        assert_eq!(cloned.provider_ref, plan.provider_ref);
        assert_eq!(cloned.transport, plan.transport);
        assert_eq!(cloned.credential_sources, plan.credential_sources);
        assert!(matches!(cloned.access_mode, AccessMode::Authenticated));
        assert!(cloned.audience_binding.is_none());

        let debug = format!("{plan:?}");
        assert!(debug.contains(r#"provider_ref: Some("idp-a")"#));
        assert!(!debug.contains("GrantPolicy"));
    }
}