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
// Copyright (c) 2025 salus developers
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. All files in the project carrying such notice may not be copied,
// modified, or distributed except according to those terms.
//! A process-local, in-memory keyring backend for tests.
//!
//! Production code reaches the keyring through `keyring`'s `v1` API
//! ([`keyring::Entry`]). The first `Entry::new` in a process installs the
//! platform-native store (Secret Service / Keychain) as `keyring_core`'s
//! default via a private `Once`. Left to its own devices that would route the
//! tests at the *real* OS keyring — mutating (and reading stale state from) the
//! developer's actual credentials.
//!
//! [`guard`] defuses that: it fires the `Once` once with a throwaway entry, then
//! installs a fresh `keyring-core` [`mock::Store`] as the default. The mock keys
//! credentials by `(service, account)` in a per-instance map, so the new
//! `Entry` that `keystore` opens for each operation still round-trips a write
//! through a later read. Installing a brand-new mock per call clears any state a
//! prior test left behind, and the returned guard serializes keyring-touching
//! tests so they cannot collide on the process-global default store.
use ;
use ;
/// Install a fresh in-memory keyring (clearing any prior contents) and
/// serialize keyring-touching tests for the lifetime of the returned guard.