faucet-core 1.12.0

Shared types, traits, and utilities for the faucet-stream ecosystem
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
//! Shared, connector-agnostic authentication abstraction.
//!
//! Multiple connectors that authenticate against the **same** system (e.g. four
//! matrix rows reading from one Snowflake account, or four endpoints of one REST
//! API) can share a single [`AuthProvider`]. A provider is a live entity that
//! owns the token cache and refresh lifecycle; connectors hold an [`Arc`] to it
//! and ask for the current [`Credential`] per request, so N connectors share one
//! token with single-flight refresh instead of racing to refresh it.
//!
//! - [`Credential`] — a resolved credential (bearer token, header, basic auth).
//! - [`AuthProvider`] — an object-safe trait yielding credentials, with
//!   single-flight refresh implemented by the provider.
//! - [`AuthSpec`] — a connector config field that is **either** inline auth
//!   `{ type, config }` **or** a `{ ref: <name> }` pointer to a shared provider.
//!
//! The HTTP-based provider implementations (OAuth2, token-endpoint) live in the
//! separate `faucet-auth` crate so `faucet-core` stays free of an HTTP-client
//! dependency.

use crate::FaucetError;
use async_trait::async_trait;
use schemars::JsonSchema;
use serde::{Deserialize, Deserializer, Serialize};
use std::sync::Arc;

/// A resolved credential produced by an [`AuthProvider`] or built from inline
/// auth config. Connectors map this onto their wire protocol (HTTP header, gRPC
/// metadata, …).
///
/// Intentionally **not** `#[non_exhaustive]`: connectors must map every variant,
/// so adding one should be a compile error that forces correct handling rather
/// than a silently-ignored fallback.
#[derive(Clone, PartialEq, Eq)]
pub enum Credential {
    /// `Authorization: Bearer <token>`.
    Bearer(String),
    /// An explicit header name + value.
    Header {
        /// Header name (e.g. `Authorization`, `X-Api-Key`).
        name: String,
        /// Header value.
        value: String,
    },
    /// HTTP Basic credentials.
    Basic {
        /// Username.
        username: String,
        /// Password.
        password: String,
    },
    /// A raw token for connector-specific assembly (e.g. gRPC `authorization`
    /// metadata, Snowflake's `Authorization` with a token-type header).
    Token(String),
}

// `Debug` is hand-written (not derived) so a `{:?}` of a credential — or of any
// struct that embeds one, e.g. a logged connector config or a `StaticProvider` —
// never prints the secret in clear. The secret-bearing fields render as `"***"`;
// the non-secret identifiers (header name, basic-auth username) stay visible so
// the output is still useful for diagnostics. `Credential` is a 1.0-frozen public
// type, so this redaction is part of its contract.
impl std::fmt::Debug for Credential {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Credential::Bearer(_) => f.debug_tuple("Bearer").field(&"***").finish(),
            Credential::Header { name, .. } => f
                .debug_struct("Header")
                .field("name", name)
                .field("value", &"***")
                .finish(),
            Credential::Basic { username, .. } => f
                .debug_struct("Basic")
                .field("username", username)
                .field("password", &"***")
                .finish(),
            Credential::Token(_) => f.debug_tuple("Token").field(&"***").finish(),
        }
    }
}

impl Credential {
    /// The value to use for an `Authorization` header, when this credential maps
    /// to one. Returns `None` for credentials that are applied differently
    /// (e.g. [`Credential::Basic`], which connectors apply via basic-auth, or
    /// [`Credential::Header`], which carries its own name).
    pub fn authorization_value(&self) -> Option<String> {
        match self {
            Credential::Bearer(t) => Some(format!("Bearer {t}")),
            Credential::Token(t) => Some(t.clone()),
            Credential::Header { .. } | Credential::Basic { .. } => None,
        }
    }
}

/// One placement of a captured credential into an outgoing HTTP request,
/// produced by [`AuthProvider::request_auth`]. Unlike [`Credential`] (which is
/// header/bearer-shaped), a placement can target a query parameter, cookie, or
/// JSON body field — the shapes multi-step auth flows (#511) need.
///
/// `#[non_exhaustive]` so new placement kinds can be added as a minor change.
#[derive(Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum CredentialPlacement {
    /// An HTTP header `name: value`.
    Header {
        /// Header name.
        name: String,
        /// Header value.
        value: String,
    },
    /// A query-string parameter `?name=value`.
    Query {
        /// Parameter name.
        name: String,
        /// Parameter value.
        value: String,
    },
    /// A cookie `name=value` (sent via the `Cookie` header).
    Cookie {
        /// Cookie name.
        name: String,
        /// Cookie value.
        value: String,
    },
    /// A top-level field of the JSON request body.
    BodyField {
        /// Field name.
        name: String,
        /// Field value (string).
        value: String,
    },
}

// Hand-written `Debug` redacts the secret-bearing `value` while keeping the
// non-secret `name` visible — same contract as `Credential`.
impl std::fmt::Debug for CredentialPlacement {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let (kind, name) = match self {
            CredentialPlacement::Header { name, .. } => ("Header", name),
            CredentialPlacement::Query { name, .. } => ("Query", name),
            CredentialPlacement::Cookie { name, .. } => ("Cookie", name),
            CredentialPlacement::BodyField { name, .. } => ("BodyField", name),
        };
        f.debug_struct(kind)
            .field("name", name)
            .field("value", &"***")
            .finish()
    }
}

/// The per-request auth a provider contributes beyond a single [`Credential`]:
/// zero or more [`CredentialPlacement`]s plus an optional dynamic base-URL that
/// overrides the connector's configured one (captured from a login response —
/// Bullhorn `restUrl`, Zoho region host, #511).
///
/// A connector that receives a non-[`is_empty`](RequestAuth::is_empty)
/// `RequestAuth` uses it **instead of** the plain [`credential`](AuthProvider::credential)
/// path for that request. `#[non_exhaustive]`: construct via [`RequestAuth::new`]
/// and the builder methods so fields can be added as a minor change.
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct RequestAuth {
    /// Credential placements to apply to the request.
    pub placements: Vec<CredentialPlacement>,
    /// Optional per-session base-URL override.
    pub base_url: Option<String>,
    /// Values captured by a multi-step login (name → value), exposed so a
    /// connector can substitute `${name}` tokens into a **raw request body**
    /// (or header) string — an XML/SOAP gateway that must carry a captured
    /// `sessionid` inside its body, which no [`CredentialPlacement`] can express
    /// (#567). These are the same captured values the flow's `apply` placements
    /// draw from; secret-bearing, so a connector must treat them as sensitive.
    pub captured: std::collections::BTreeMap<String, String>,
}

impl RequestAuth {
    /// An empty `RequestAuth` (no placements, no base-URL override).
    pub fn new() -> Self {
        Self::default()
    }

    /// Add a credential placement (builder).
    #[must_use]
    pub fn with_placement(mut self, placement: CredentialPlacement) -> Self {
        self.placements.push(placement);
        self
    }

    /// Set the dynamic base-URL override (builder).
    #[must_use]
    pub fn with_base_url(mut self, base_url: impl Into<String>) -> Self {
        self.base_url = Some(base_url.into());
        self
    }

    /// Attach the captured login values (name → value) for `${name}` body/header
    /// substitution (builder, #567).
    #[must_use]
    pub fn with_captured(mut self, captured: std::collections::BTreeMap<String, String>) -> Self {
        self.captured = captured;
        self
    }

    /// True when the provider contributed nothing (the connector then falls back
    /// to the plain [`credential`](AuthProvider::credential) path).
    pub fn is_empty(&self) -> bool {
        self.placements.is_empty() && self.base_url.is_none() && self.captured.is_empty()
    }
}

// Redacting `Debug`: placements redact their own values; the base-URL is passed
// through `redact_uri_credentials` so any embedded userinfo is scrubbed.
impl std::fmt::Debug for RequestAuth {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("RequestAuth")
            .field("placements", &self.placements)
            .field(
                "base_url",
                &self
                    .base_url
                    .as_deref()
                    .map(crate::util::redact_uri_credentials),
            )
            .finish()
    }
}

/// A live, shareable source of credentials.
///
/// One instance is shared (via [`Arc`]) across all connectors that reference it,
/// giving single-flight refresh: concurrent callers during a refresh await the
/// one in-flight fetch rather than each refreshing independently.
///
/// Object-safe — no generics or associated types, so it can be held as
/// `Arc<dyn AuthProvider>` ([`SharedAuthProvider`]).
#[async_trait]
pub trait AuthProvider: Send + Sync + std::fmt::Debug {
    /// Return a currently-valid credential, refreshing if needed.
    async fn credential(&self) -> Result<Credential, FaucetError>;

    /// Force a refresh **iff** the cached credential still equals `stale`
    /// (compare-and-swap). Multiple connectors that hit a `401` with the same
    /// token collapse into a single refresh; callers holding an already-rotated
    /// token get the new one without triggering another fetch.
    ///
    /// The default delegates to [`AuthProvider::credential`]; providers that
    /// support refresh override it.
    async fn invalidate(&self, _stale: &Credential) -> Result<Credential, FaucetError> {
        self.credential().await
    }

    /// Per-request signing hook (OAuth1 and similar, #496).
    ///
    /// Most providers issue a **reusable** credential via [`credential`](Self::credential);
    /// they return `Ok(None)` here (the default) and the connector applies the
    /// cached credential. A provider that must sign **each request individually**
    /// (e.g. OAuth1, whose signature covers the HTTP method, URL, and query
    /// parameters) overrides this to compute a fresh [`Credential`] — typically a
    /// [`Credential::Header`] carrying the `Authorization` signature — from the
    /// request. When it returns `Some`, the connector uses it **instead of**
    /// `credential()` for that request.
    ///
    /// `query` is the request's query parameters (the connector's, before the
    /// HTTP client appends them), which OAuth1 folds into its signature base
    /// string. Object-safe: no generics, all args are borrowed primitives.
    async fn sign_request(
        &self,
        _method: &str,
        _url: &str,
        _query: &std::collections::BTreeMap<String, String>,
    ) -> Result<Option<Credential>, FaucetError> {
        Ok(None)
    }

    /// Richer per-request auth for multi-step flows (#511): credential
    /// placements across header / query / cookie / body plus an optional
    /// dynamic base-URL override.
    ///
    /// Most providers issue a single [`Credential`] and return an empty
    /// [`RequestAuth`] here (the default); the connector then applies the plain
    /// [`credential`](Self::credential) path. A provider that must place a
    /// captured value somewhere other than a header, place several values at
    /// once, or redirect the request to a captured base-URL overrides this. When
    /// it returns a non-[`is_empty`](RequestAuth::is_empty) value, the connector
    /// applies the placements **instead of** `credential()` for that request.
    ///
    /// `query` is the request's query parameters before the HTTP client appends
    /// them (some flows fold them into a signature). Object-safe: no generics,
    /// all args are borrowed primitives.
    async fn request_auth(
        &self,
        _method: &str,
        _url: &str,
        _query: &std::collections::BTreeMap<String, String>,
    ) -> Result<RequestAuth, FaucetError> {
        Ok(RequestAuth::new())
    }

    /// HTTP status codes on which the connector should force a re-auth
    /// (via [`invalidate`](Self::invalidate)) and retry the request once.
    ///
    /// The default is empty — connectors keep their built-in `401` handling.
    /// A multi-step flow (#511) whose session cookie/token can expire mid-run
    /// returns the statuses (e.g. `[401]`, `[401, 403]`) that mean "log in again".
    fn reauth_statuses(&self) -> &[u16] {
        &[]
    }

    /// Stable, non-empty name for diagnostics and metrics.
    fn provider_name(&self) -> &'static str;
}

/// A shared [`AuthProvider`] handle. Cloning it shares the one live provider
/// (and its single token cache) across connectors.
pub type SharedAuthProvider = Arc<dyn AuthProvider>;

/// A `{ ref: <name> }` pointer to a named provider in the top-level `auth:`
/// catalog. The only permitted key is `ref`.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct AuthReference {
    /// Name of the provider in the top-level `auth:` catalog.
    #[serde(rename = "ref")]
    pub name: String,
}

/// A connector's `auth:` field: **either** an inline auth definition `A`
/// (the `{ type, config }` shape), **or** a `{ ref: <name> }` reference to a
/// shared provider defined in the top-level `auth:` catalog.
///
/// `ref` is mutually exclusive with inline fields — supplying both is a
/// deserialization error.
#[derive(Debug, Clone, Serialize, JsonSchema)]
#[serde(untagged)]
pub enum AuthSpec<A> {
    /// Inline auth, spelled out on the connector.
    Inline(A),
    /// A reference to a shared provider in the top-level `auth:` catalog.
    Reference(AuthReference),
}

impl<A: Default> Default for AuthSpec<A> {
    fn default() -> Self {
        AuthSpec::Inline(A::default())
    }
}

impl<A> AuthSpec<A> {
    /// The inline auth, if this is not a reference.
    pub fn inline(&self) -> Option<&A> {
        match self {
            AuthSpec::Inline(a) => Some(a),
            AuthSpec::Reference(_) => None,
        }
    }

    /// The referenced provider name, if this is a reference.
    pub fn reference_name(&self) -> Option<&str> {
        match self {
            AuthSpec::Reference(r) => Some(&r.name),
            AuthSpec::Inline(_) => None,
        }
    }
}

// Manual `Deserialize` enforces the `ref`-XOR-inline rule, which a plain
// `#[serde(untagged)]` derive cannot (it would silently ignore extra keys).
impl<'de, A> Deserialize<'de> for AuthSpec<A>
where
    A: serde::de::DeserializeOwned,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: Deserializer<'de>,
    {
        let value = serde_json::Value::deserialize(deserializer)?;
        let has_ref = value.get("ref").is_some();
        if has_ref {
            let has_other = value
                .as_object()
                .map(|o| o.keys().any(|k| k != "ref"))
                .unwrap_or(false);
            if has_other {
                return Err(serde::de::Error::custom(
                    "auth: `ref` cannot be combined with inline auth fields (type/config)",
                ));
            }
            let r: AuthReference =
                serde_json::from_value(value).map_err(serde::de::Error::custom)?;
            return Ok(AuthSpec::Reference(r));
        }
        let inner: A = serde_json::from_value(value).map_err(serde::de::Error::custom)?;
        Ok(AuthSpec::Inline(inner))
    }
}

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

    #[derive(Debug, Deserialize, PartialEq)]
    #[serde(tag = "type", content = "config", rename_all = "snake_case")]
    enum StubAuth {
        None,
        Bearer { token: String },
    }

    #[derive(Debug)]
    struct MinimalProvider;

    #[async_trait]
    impl AuthProvider for MinimalProvider {
        async fn credential(&self) -> Result<Credential, FaucetError> {
            Ok(Credential::Bearer("t".into()))
        }
        fn provider_name(&self) -> &'static str {
            "minimal"
        }
    }

    #[test]
    fn credential_placement_debug_redacts_value_keeps_name() {
        let cases = [
            CredentialPlacement::Header {
                name: "X-Tok".into(),
                value: "secret".into(),
            },
            CredentialPlacement::Query {
                name: "access_token".into(),
                value: "secret".into(),
            },
            CredentialPlacement::Cookie {
                name: "sid".into(),
                value: "secret".into(),
            },
            CredentialPlacement::BodyField {
                name: "auth".into(),
                value: "secret".into(),
            },
        ];
        for p in cases {
            let s = format!("{p:?}");
            assert!(s.contains("***"), "value must be redacted: {s}");
            assert!(!s.contains("secret"), "secret leaked: {s}");
        }
    }

    #[test]
    fn request_auth_builders_and_is_empty() {
        let empty = RequestAuth::new();
        assert!(empty.is_empty());

        let ra = RequestAuth::new()
            .with_placement(CredentialPlacement::Query {
                name: "t".into(),
                value: "v".into(),
            })
            .with_base_url("https://host");
        assert!(!ra.is_empty());
        assert_eq!(ra.placements.len(), 1);
        assert_eq!(ra.base_url.as_deref(), Some("https://host"));

        // base-URL alone (no placements) is still non-empty.
        assert!(!RequestAuth::new().with_base_url("https://h").is_empty());
        assert!(RequestAuth::default().is_empty());

        // Captured values alone (no placements / base-URL) also make it
        // non-empty, and are exposed for `${name}` body substitution (#567).
        let mut cap = std::collections::BTreeMap::new();
        cap.insert("session_id".to_string(), "SID".to_string());
        let ra = RequestAuth::new().with_captured(cap);
        assert!(!ra.is_empty());
        assert_eq!(
            ra.captured.get("session_id").map(String::as_str),
            Some("SID")
        );
    }

    #[test]
    fn request_auth_debug_redacts_placements_and_base_url() {
        let ra = RequestAuth::new()
            .with_placement(CredentialPlacement::Header {
                name: "Authorization".into(),
                value: "topsecret".into(),
            })
            .with_base_url("https://user:pw@host/path");
        let s = format!("{ra:?}");
        assert!(!s.contains("topsecret"), "placement value leaked: {s}");
        assert!(!s.contains("pw"), "base-url userinfo leaked: {s}");
    }

    #[tokio::test]
    async fn default_request_auth_is_empty_and_reauth_is_empty() {
        let p = MinimalProvider;
        assert!(matches!(
            p.credential().await.unwrap(),
            Credential::Bearer(_)
        ));
        assert_eq!(p.provider_name(), "minimal");
        let ra = p
            .request_auth("GET", "https://x", &std::collections::BTreeMap::new())
            .await
            .unwrap();
        assert!(ra.is_empty());
        assert!(p.reauth_statuses().is_empty());
        // The default sign_request also contributes nothing.
        assert!(
            p.sign_request("GET", "https://x", &std::collections::BTreeMap::new())
                .await
                .unwrap()
                .is_none()
        );
    }

    #[test]
    fn credential_authorization_value() {
        assert_eq!(
            Credential::Bearer("abc".into()).authorization_value(),
            Some("Bearer abc".to_string())
        );
        assert_eq!(
            Credential::Token("Custom xyz".into()).authorization_value(),
            Some("Custom xyz".to_string())
        );
        assert_eq!(
            Credential::Basic {
                username: "u".into(),
                password: "p".into()
            }
            .authorization_value(),
            None
        );
        assert_eq!(
            Credential::Header {
                name: "X-Api-Key".into(),
                value: "k".into()
            }
            .authorization_value(),
            None
        );
    }

    #[test]
    fn authspec_parses_inline() {
        let j = serde_json::json!({"type": "bearer", "config": {"token": "t"}});
        let s: AuthSpec<StubAuth> = serde_json::from_value(j).unwrap();
        match s {
            AuthSpec::Inline(StubAuth::Bearer { token }) => assert_eq!(token, "t"),
            other => panic!("expected inline bearer, got {other:?}"),
        }
    }

    #[test]
    fn authspec_parses_inline_unit_variant() {
        let j = serde_json::json!({"type": "none"});
        let s: AuthSpec<StubAuth> = serde_json::from_value(j).unwrap();
        assert!(matches!(s, AuthSpec::Inline(StubAuth::None)));
    }

    #[test]
    fn authspec_parses_ref() {
        let j = serde_json::json!({"ref": "sf"});
        let s: AuthSpec<StubAuth> = serde_json::from_value(j).unwrap();
        assert_eq!(s.reference_name(), Some("sf"));
    }

    #[test]
    fn authspec_rejects_ref_plus_inline() {
        let j = serde_json::json!({"ref": "sf", "type": "bearer"});
        let r: Result<AuthSpec<StubAuth>, _> = serde_json::from_value(j);
        assert!(r.is_err(), "ref + inline must be rejected");
    }

    #[derive(Debug)]
    struct Fixed(Credential);

    #[async_trait]
    impl AuthProvider for Fixed {
        async fn credential(&self) -> Result<Credential, FaucetError> {
            Ok(self.0.clone())
        }
        fn provider_name(&self) -> &'static str {
            "fixed"
        }
    }

    #[test]
    fn credential_debug_redacts_secrets() {
        // Bearer / Token fully redact the secret value.
        let b = format!("{:?}", Credential::Bearer("supersecrettoken".into()));
        assert!(!b.contains("supersecrettoken"), "bearer token leaked: {b}");
        assert!(b.contains("***"), "bearer token not masked: {b}");

        let t = format!("{:?}", Credential::Token("tok-supersecretxyz".into()));
        assert!(!t.contains("tok-supersecretxyz"), "raw token leaked: {t}");
        assert!(t.contains("***"), "raw token not masked: {t}");

        // Basic redacts the password but keeps the (non-secret) username.
        let basic = format!(
            "{:?}",
            Credential::Basic {
                username: "alice".into(),
                password: "hunter2secret".into(),
            }
        );
        assert!(!basic.contains("hunter2secret"), "password leaked: {basic}");
        assert!(
            basic.contains("alice"),
            "username should stay visible for diagnostics: {basic}"
        );

        // Header redacts the value but keeps the (non-secret) header name.
        let header = format!(
            "{:?}",
            Credential::Header {
                name: "X-Api-Key".into(),
                value: "secretkeyvalue".into(),
            }
        );
        assert!(
            !header.contains("secretkeyvalue"),
            "header value leaked: {header}"
        );
        assert!(
            header.contains("X-Api-Key"),
            "header name should stay visible for diagnostics: {header}"
        );
    }

    #[tokio::test]
    async fn auth_provider_default_invalidate_returns_current() {
        let p = Fixed(Credential::Bearer("x".into()));
        assert_eq!(
            p.credential().await.unwrap(),
            Credential::Bearer("x".into())
        );
        // Default invalidate just returns the current credential.
        assert_eq!(
            p.invalidate(&Credential::Bearer("old".into()))
                .await
                .unwrap(),
            Credential::Bearer("x".into())
        );
    }
}