deps-core 6.0.0

Core abstractions for deps-lsp: caching, errors, and traits
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
//! Generic "never surfaced via `Debug`/`Display`" wrapper for in-memory secrets.
//!
//! `deps_cargo::config::AuthToken`, `deps_nuget::config::NuGetAuth`, and
//! `deps_nuget::config::RedactedSecret` each hand-rolled the same single-field tuple struct: a
//! private/crate-visible constructor, an `as_str()` accessor documented "never logged,
//! printed, or otherwise surfaced", and hand-written `Debug`/`Display` impls that print `***`
//! (#573). [`Redacted<T>`] is the one place that pattern is implemented, so the call sites
//! cannot silently diverge on it and a new ecosystem crate needing the same guarantee does
//! not reinvent it — [`ApiToken`] (#1480 item 8) is this module's own generic token wrapper
//! built directly on [`Redacted<T>`], replacing what were previously independent hand-rolled
//! `AuthToken` copies in `deps_core::github` and `deps_gitlab_ci::client`.
//!
//! Placed beside [`crate::redact::redact_userinfo`], which owns the adjacent "a
//! credential must not leak via a log line" concern for URLs specifically, while this module
//! owns it for an owned secret value held in memory.
//!
//! Beyond redacting `Debug`/`Display`, [`Redacted<T>`] zeroizes its backing memory on drop
//! (issue #574) — after the value goes out of scope, a core dump or a read of freed/swapped
//! memory cannot recover the plaintext credential.
//!
//! That guarantee only holds for the wrapper itself: a caller that copies
//! [`Redacted::expose_secret`]'s result into a plain `String` (e.g. via `format!`) must not
//! let that copy outlive an unzeroized scope. The preferred fix (issue #672) is to format the
//! derived value — e.g. a `Bearer`/`Basic` `Authorization` header — once at construction time
//! and rewrap it in a new [`Redacted<T>`] right away, the way [`ApiToken`],
//! `deps_cargo::config::AuthToken`, and `deps_nuget::config::NuGetAuth` all do; reach for a
//! bare [`zeroize::Zeroizing`] only when that per-request re-derivation is unavoidable.
//!
//! [`digest_salt`] and [`auth_digest`] cover the adjacent "identify a credential for a cache
//! key without exposing it in a log line" concern (issue #1003): `deps-gitlab-ci` and
//! `deps-nuget` each used to carry their own copy of this salted-hash pair.

use std::hash::{Hash, Hasher};
use std::sync::OnceLock;

use zeroize::{Zeroize, Zeroizing};

/// A secret value whose `Debug`/`Display` output is always `***`, and whose backing memory
/// is zeroized when it is dropped.
///
/// Wrap any credential that must never reach a log line, a panic message, or a future
/// `#[derive(Debug)]` added to a struct embedding it. `T` defaults to `String`, the shape
/// every current call site needs; a caller that needs a different backing type must supply
/// one that implements [`Zeroize`] (e.g. secret bytes as `Vec<u8>`).
///
/// # Examples
///
/// ```
/// use deps_core::secret::Redacted;
///
/// let token = Redacted::new("super-secret-value".to_string());
/// assert_eq!(token.expose_secret(), "super-secret-value");
/// assert_eq!(format!("{token:?}"), "Redacted(***)");
/// assert_eq!(format!("{token}"), "***");
/// ```
#[derive(Clone)]
pub struct Redacted<T: Zeroize = String>(Zeroizing<T>);

impl<T: Zeroize> Redacted<T> {
    /// Wraps `value`. The only way to recover it is [`Self::expose_secret`] (for `T: AsRef<str>`).
    pub fn new(value: T) -> Self {
        Self(Zeroizing::new(value))
    }
}

impl<T: Zeroize + AsRef<str>> Redacted<T> {
    /// The raw secret value. Never pass this to anything but the one call site that needs
    /// it (e.g. attaching a header value to a request) — never to a log, error message, or
    /// anything `Debug`/`Display`-formatted downstream.
    ///
    /// Named `expose_secret()` rather than `as_str()` deliberately, mirroring the `secrecy`
    /// crate's `ExposeSecret::expose_secret()` convention: a name shared with hundreds of
    /// ordinary string-conversion methods across the workspace cannot be grepped for in
    /// isolation, while a distinctive name lets a reviewer or a future automated lint find
    /// every place a secret's plaintext crosses its wrapper boundary with a single search.
    #[must_use]
    pub fn expose_secret(&self) -> &str {
        self.0.as_ref()
    }
}

impl<T: Zeroize> std::fmt::Debug for Redacted<T> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str("Redacted(***)")
    }
}

impl<T: Zeroize> std::fmt::Display for Redacted<T> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str("***")
    }
}

impl<T: Zeroize + PartialEq> PartialEq for Redacted<T> {
    fn eq(&self, other: &Self) -> bool {
        *self.0 == *other.0
    }
}

impl<T: Zeroize + Eq> Eq for Redacted<T> {}

/// Hashes the wrapped value, not the redaction wrapper — so `Redacted<T>` can be used as (or
/// inside) a hash-map/set key exactly when `T` itself could be. Opt-in via `T: Hash`, same
/// shape as the `PartialEq`/`Eq` impls above: a caller that needs this must ask for it by
/// bounding on `Hash`, so embedding a secret in a hash key stays a deliberate choice at each
/// call site rather than something a blanket impl would make automatic.
impl<T: Zeroize + std::hash::Hash> std::hash::Hash for Redacted<T> {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        (*self.0).hash(state);
    }
}

/// Marker confirming [`Redacted<T>`] zeroizes its backing memory on drop — the actual
/// zeroing is performed by the wrapped [`Zeroizing<T>`] field's own [`Drop`] impl.
impl<T: Zeroize> zeroize::ZeroizeOnDrop for Redacted<T> {}

/// A per-process random salt, mixed into [`auth_digest`] so the digest cannot be
/// reconstructed offline from a known origin/secret pair.
///
/// An unsalted, non-cryptographic 64-bit hash of a credential value is a brute-force target if
/// it ever reaches a log line: an attacker who can enumerate candidate secrets offline can hash
/// each one and compare against the leaked digest, needing no access to the origin service at
/// all (issue #561). The salt closes that path — the digest cannot be reproduced without also
/// knowing this process's random salt, which is never logged, persisted, or exposed.
///
/// # Examples
///
/// ```
/// use deps_core::secret::digest_salt;
///
/// // Stable within one process, whatever its actual value is.
/// assert_eq!(digest_salt(), digest_salt());
/// ```
pub fn digest_salt() -> u64 {
    static SALT: OnceLock<u64> = OnceLock::new();
    *SALT.get_or_init(|| {
        use std::collections::hash_map::RandomState;
        use std::hash::BuildHasher;
        let mut hasher = RandomState::new().build_hasher();
        std::process::id().hash(&mut hasher);
        std::time::SystemTime::now().hash(&mut hasher);
        hasher.finish()
    })
}

/// A per-request auth identity for a cache key.
///
/// `None` when `secret` is `None`, otherwise a salted hash of `origin` and `secret`. Lets a
/// caller distinguish an authenticated response from an unauthenticated one (or one fetched
/// with a different credential) in a cache key without ever storing or logging the
/// credential itself.
///
/// # Examples
///
/// ```
/// use deps_core::secret::auth_digest;
///
/// assert_eq!(auth_digest("https://example.com", None), None);
///
/// let a = auth_digest("https://example.com", Some("token-a")).unwrap();
/// let b = auth_digest("https://other.example.com", Some("token-a")).unwrap();
/// assert_ne!(a, b, "different origins must digest differently");
///
/// let c = auth_digest("https://example.com", Some("token-b")).unwrap();
/// assert_ne!(a, c, "different secrets must digest differently");
/// ```
pub fn auth_digest(origin: &str, secret: Option<&str>) -> Option<u64> {
    let secret = secret?;
    let mut hasher = std::collections::hash_map::DefaultHasher::new();
    digest_salt().hash(&mut hasher);
    origin.hash(&mut hasher);
    secret.hash(&mut hasher);
    Some(hasher.finish())
}

/// A registry API bearer/private token, redacted everywhere except the one call site that
/// hands it to a request as a header value.
///
/// A thin wrapper over [`Redacted`] rather than a bare type alias: `Debug` prints
/// `ApiToken(***)`, not `Redacted(***)`, so a panic message or log line still names which
/// credential leaked its type. Extracted from `deps_core::github::AuthToken` and
/// `deps_gitlab_ci::client::AuthToken`, which had independently hand-rolled the identical
/// wrapper (#1480 item 8) — `deps_cargo::config::AuthToken` deliberately keeps its own
/// separate type, since its `pub(crate)` constructor is a provenance security boundary, not
/// just a redaction wrapper.
#[derive(Clone, PartialEq, Eq)]
pub struct ApiToken(Redacted);

impl ApiToken {
    /// Wraps `value`.
    #[must_use]
    pub fn new(value: String) -> Self {
        Self(Redacted::new(value))
    }

    /// The raw header value, for attaching to a request. Never logged, printed, or
    /// otherwise surfaced — callers must not pass this to anything but a header value.
    #[must_use]
    pub fn expose_secret(&self) -> &str {
        self.0.expose_secret()
    }

    /// The wrapped secret, for attaching to a request as a sensitive credential header.
    #[must_use]
    pub const fn as_redacted(&self) -> &Redacted {
        &self.0
    }
}

impl From<Redacted> for ApiToken {
    fn from(value: Redacted) -> Self {
        Self(value)
    }
}

impl std::fmt::Debug for ApiToken {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str("ApiToken(***)")
    }
}

impl std::fmt::Display for ApiToken {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str("***")
    }
}

/// The scheme of an [`AuthorizationValue`].
///
/// Exhaustive on purpose: adding a scheme forces every `match` on it to be revisited.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AuthScheme {
    /// `Basic base64(username:password)`.
    Basic,
    /// `Bearer <token>`.
    Bearer,
    /// The token as is, with no scheme prefix.
    Verbatim,
}

/// A pre-formatted `Authorization` header value, redacted everywhere except the one call site
/// that attaches it to a request.
///
/// Built only by [`basic_auth_header`], [`bearer_auth_header`] and [`cargo_token_header`], so a
/// request cannot carry an `Authorization` value whose scheme was assembled by hand.
///
/// # Examples
///
/// ```
/// use deps_core::secret::{AuthScheme, Redacted, bearer_auth_header};
///
/// let header = bearer_auth_header(&Redacted::new("t0k".to_string()));
/// assert_eq!(header.scheme(), AuthScheme::Bearer);
/// assert_eq!(header.expose_secret(), "Bearer t0k");
/// assert_eq!(format!("{header:?}"), "AuthorizationValue(Bearer, ***)");
/// ```
///
/// Its fields are private, so it cannot be built directly:
///
/// ```compile_fail
/// use deps_core::secret::{AuthScheme, AuthorizationValue, Redacted};
///
/// let _ = AuthorizationValue {
///     scheme: AuthScheme::Bearer,
///     value: Redacted::new("Bearer t0k".to_string()),
/// };
/// ```
#[derive(Clone)]
pub struct AuthorizationValue {
    scheme: AuthScheme,
    value: Redacted,
}

impl AuthorizationValue {
    /// The scheme this value was built with.
    #[must_use]
    pub const fn scheme(&self) -> AuthScheme {
        self.scheme
    }

    /// The full header value, scheme included. Never logged, printed, or otherwise surfaced;
    /// hand it to an `Authorization` header only.
    #[must_use]
    pub fn expose_secret(&self) -> &str {
        self.value.expose_secret()
    }
}

impl std::fmt::Debug for AuthorizationValue {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "AuthorizationValue({:?}, ***)", self.scheme)
    }
}

impl std::fmt::Display for AuthorizationValue {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str("***")
    }
}

/// Formats `username`/`password` into a `Basic base64(username:password)` `Authorization`
/// value.
///
/// Every intermediate (the raw `user:pass` string and its reversible base64 encoding) is held
/// in [`Zeroizing`] from the point of construction, so no un-zeroized plaintext copy outlives
/// the call. Shared by every ecosystem that builds a `Basic` header (NuGet, Swift), so the
/// encoding cannot diverge between them.
///
/// # Examples
///
/// ```
/// use deps_core::secret::basic_auth_header;
///
/// let header = basic_auth_header("user", "pass");
/// assert_eq!(header.expose_secret(), "Basic dXNlcjpwYXNz");
/// assert_eq!(format!("{header}"), "***");
/// ```
#[must_use]
pub fn basic_auth_header(username: &str, password: &str) -> AuthorizationValue {
    use base64::Engine;

    let mut user_pass = Zeroizing::new(String::with_capacity(username.len() + 1 + password.len()));
    user_pass.push_str(username);
    user_pass.push(':');
    user_pass.push_str(password);
    let encoded = Zeroizing::new(base64::engine::general_purpose::STANDARD.encode(&*user_pass));
    AuthorizationValue {
        scheme: AuthScheme::Basic,
        value: Redacted::new(format!("Basic {}", *encoded)),
    }
}

/// Formats `token` into a `Bearer <token>` `Authorization` value.
///
/// Takes a [`Redacted`], so only a value that already is a secret can become a credential
/// header.
///
/// # Examples
///
/// ```
/// use deps_core::secret::{Redacted, bearer_auth_header};
///
/// let token = Redacted::new("t0k".to_string());
/// assert_eq!(bearer_auth_header(&token).expose_secret(), "Bearer t0k");
/// ```
#[must_use]
pub fn bearer_auth_header(token: &Redacted) -> AuthorizationValue {
    AuthorizationValue {
        scheme: AuthScheme::Bearer,
        value: Redacted::new(format!("Bearer {}", token.expose_secret())),
    }
}

/// Formats a Cargo registry `token` into the `Authorization` value Cargo itself sends: the token
/// as is, with no `Bearer` prefix.
///
/// # Examples
///
/// ```
/// use deps_core::secret::{AuthScheme, Redacted, cargo_token_header};
///
/// let header = cargo_token_header(&Redacted::new("t0k".to_string()));
/// assert_eq!(header.scheme(), AuthScheme::Verbatim);
/// assert_eq!(header.expose_secret(), "t0k");
/// assert_eq!(format!("{header:?}"), "AuthorizationValue(Verbatim, ***)");
/// ```
#[must_use]
pub fn cargo_token_header(token: &Redacted) -> AuthorizationValue {
    AuthorizationValue {
        scheme: AuthScheme::Verbatim,
        value: Redacted::new(token.expose_secret().to_string()),
    }
}

/// Reads `var` from the environment, treating an unset or empty value as absent.
///
/// Returns a [`zeroize::Zeroizing`] wrapper so the raw token text is wiped from memory once
/// the caller drops it, mirroring [`Redacted`]'s own zeroize-on-drop guarantee. Does not log
/// anything itself — callers keep their own `tracing::info!("... detected, using
/// authenticated ... requests")` line, since only the caller knows which token/ecosystem it
/// is naming.
///
/// # Examples
///
/// ```
/// use deps_core::secret::token_from_env;
///
/// assert!(token_from_env("DEPS_CORE_DOCTEST_UNSET_TOKEN_VAR").is_none());
/// ```
#[must_use]
pub fn token_from_env(var: &str) -> Option<zeroize::Zeroizing<String>> {
    non_empty_token(std::env::var(var).ok())
}

/// Pure predicate behind [`token_from_env`] over an already-read `Option<String>`, mirroring
/// `crate::test_util::is_configured_token`'s split: `std::env::set_var` is `unsafe` (forbidden
/// workspace-wide), so no test can mutate the real environment to exercise the
/// present/empty-string branches directly — this lets them be tested without touching it.
fn non_empty_token(raw: Option<String>) -> Option<zeroize::Zeroizing<String>> {
    raw.map(zeroize::Zeroizing::new).filter(|t| !t.is_empty())
}

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

    #[test]
    fn debug_redacts() {
        let secret = Redacted::new("hunter2".to_string());
        assert_eq!(format!("{secret:?}"), "Redacted(***)");
    }

    #[test]
    fn display_redacts() {
        let secret = Redacted::new("hunter2".to_string());
        assert_eq!(format!("{secret}"), "***");
    }

    #[test]
    fn expose_secret_recovers_the_value() {
        let secret = Redacted::new("hunter2".to_string());
        assert_eq!(secret.expose_secret(), "hunter2");
    }

    #[test]
    fn equality_compares_the_wrapped_value() {
        assert_eq!(
            Redacted::new("hunter2".to_string()),
            Redacted::new("hunter2".to_string())
        );
        assert_ne!(
            Redacted::new("hunter2".to_string()),
            Redacted::new("other".to_string())
        );
    }

    #[test]
    fn embedding_in_a_debug_derive_still_redacts() {
        #[derive(Debug)]
        struct Wrapper {
            token: Redacted,
        }
        let wrapper = Wrapper {
            token: Redacted::new("hunter2".to_string()),
        };
        assert_eq!(wrapper.token.expose_secret(), "hunter2");
        let debug_output = format!("{wrapper:?}");
        assert!(debug_output.contains("Redacted(***)"), "{debug_output}");
        assert!(!debug_output.contains("hunter2"), "{debug_output}");
    }

    /// Compile-time proof `Redacted<T>` zeroizes on drop — inspecting freed memory
    /// portably isn't practical in a test, so this asserts the trait bound instead (the
    /// idiomatic pattern for the `zeroize` ecosystem).
    #[test]
    fn implements_zeroize_on_drop() {
        fn assert_zeroize_on_drop<T: zeroize::ZeroizeOnDrop>() {}
        assert_zeroize_on_drop::<Redacted<String>>();
    }

    #[test]
    fn api_token_debug_and_display_redact() {
        let token = super::ApiToken::new("hunter2".to_string());
        assert_eq!(format!("{token:?}"), "ApiToken(***)");
        assert_eq!(format!("{token}"), "***");
        assert_eq!(token.expose_secret(), "hunter2");
    }

    #[test]
    fn basic_auth_header_encodes_user_and_password() {
        assert_eq!(
            super::basic_auth_header("user", "pass").expose_secret(),
            "Basic dXNlcjpwYXNz"
        );
    }

    /// Joins `parts` at runtime so no credential-shaped literal reaches a header constructor.
    fn assemble(parts: &[&str]) -> String {
        parts.concat()
    }

    #[test]
    fn authorization_header_bytes_are_exact() {
        let empty = assemble(&[]);
        assert_eq!(
            super::basic_auth_header(&empty, &empty).expose_secret(),
            "Basic Og=="
        );
        assert_eq!(
            super::basic_auth_header(
                &assemble(&["us", ":", "er"]),
                &assemble(&["p", "\u{e4}", "ss"])
            )
            .expose_secret(),
            "Basic dXM6ZXI6cMOkc3M="
        );
        let token = Redacted::new(assemble(&["a b", "+/", "="]));
        assert_eq!(
            super::bearer_auth_header(&token).expose_secret(),
            "Bearer a b+/="
        );
    }

    #[test]
    fn authorization_values_carry_their_scheme_and_redact() {
        let basic = super::basic_auth_header(&assemble(&["us", "er"]), &assemble(&["pa", "ss"]));
        let bearer = super::bearer_auth_header(&Redacted::new(assemble(&["t0", "k"])));
        assert_eq!(basic.scheme(), super::AuthScheme::Basic);
        assert_eq!(bearer.scheme(), super::AuthScheme::Bearer);
        assert_eq!(bearer.expose_secret(), "Bearer t0k");
        for value in [&basic, &bearer] {
            let shown = format!("{value:?}{value}");
            assert!(
                !shown.contains("t0k") && !shown.contains("dXNlcjpwYXNz"),
                "{shown}"
            );
        }
    }

    #[test]
    fn token_from_env_absent_var_is_none() {
        assert!(super::token_from_env("DEPS_CORE_TEST_UNSET_TOKEN_VAR_XYZ").is_none());
    }

    #[test]
    fn non_empty_token_empty_string_is_none() {
        assert!(super::non_empty_token(Some(String::new())).is_none());
    }

    #[test]
    fn non_empty_token_present_value_is_some() {
        let token = super::non_empty_token(Some("hunter2".to_string())).unwrap();
        assert_eq!(*token, "hunter2");
    }

    #[test]
    fn cargo_token_header_is_verbatim_and_redacted() {
        let header = super::cargo_token_header(&Redacted::new("Bearer-ish token".to_string()));
        assert_eq!(header.scheme(), super::AuthScheme::Verbatim);
        assert_eq!(header.expose_secret(), "Bearer-ish token");
        assert!(!format!("{header:?}{header}").contains("token"));
    }

    #[test]
    fn auth_digest_no_secret_is_none() {
        assert_eq!(super::auth_digest("https://example.com", None), None);
    }

    #[test]
    fn auth_digest_same_origin_and_secret_is_stable_within_process() {
        let a = super::auth_digest("https://example.com", Some("token"));
        let b = super::auth_digest("https://example.com", Some("token"));
        assert_eq!(a, b);
        assert!(a.is_some());
    }

    #[test]
    fn auth_digest_different_origins_diverge() {
        let a = super::auth_digest("https://example.com", Some("token")).unwrap();
        let b = super::auth_digest("https://other.example.com", Some("token")).unwrap();
        assert_ne!(a, b);
    }

    #[test]
    fn auth_digest_different_secrets_diverge() {
        let a = super::auth_digest("https://example.com", Some("token-a")).unwrap();
        let b = super::auth_digest("https://example.com", Some("token-b")).unwrap();
        assert_ne!(a, b);
    }
}