use std::{collections::BTreeMap, sync::Arc};
use pretty_assertions::assert_eq;
use rho_providers::credentials::{CredentialStore, MemoryCredentialStore};
use super::*;
#[test]
fn a_probe_reads_through_its_stores_and_leaves_the_daemons_unchanged() {
let daemon = Arc::new(MemoryCredentialStore::default());
daemon
.set_secret("mcp-oauth:linear", "saved-tokens")
.unwrap();
daemon
.set_secret(&account_name("linear", "TOKEN"), "stored-token")
.unwrap();
daemon
.set_secret(&account_name("linear", "OTHER"), "stored-other")
.unwrap();
let scratch = ScratchTokens::new(daemon.clone());
let before = scratch.get_secret("mcp-oauth:linear").unwrap();
let deleted = scratch.delete_secret("mcp-oauth:linear").unwrap();
let after_delete = scratch.get_secret("mcp-oauth:linear").unwrap();
scratch
.set_secret("mcp-oauth:linear", "draft-tokens")
.unwrap();
let after_write = scratch.get_secret_fresh("mcp-oauth:linear").unwrap();
let served = Served::default();
let secrets = UnsavedFirst::new(
"linear",
BTreeMap::from([("TOKEN".to_owned(), "other".to_owned())]),
Some(daemon.clone()),
served.clone(),
);
let read = [
secrets
.get_secret_fresh(&account_name("linear", "TOKEN"))
.unwrap(),
secrets
.get_secret_fresh(&account_name("linear", "OTHER"))
.unwrap(),
];
let refused = [
secrets
.set_secret(&account_name("linear", "TOKEN"), "x")
.is_err(),
secrets
.delete_secret(&account_name("linear", "TOKEN"))
.is_err(),
];
assert_eq!(
(
(before, deleted, after_delete, after_write),
read,
refused,
served.redact("got other and stored-other"),
[
daemon.get_secret("mcp-oauth:linear").unwrap(),
daemon.get_secret(&account_name("linear", "TOKEN")).unwrap(),
],
),
(
(None, false, None, Some("draft-tokens".to_owned())),
[Some("other".to_owned()), Some("stored-other".to_owned())],
[true, true],
"got [redacted] and [redacted]".to_owned(),
[
Some("saved-tokens".to_owned()),
Some("stored-token".to_owned())
],
)
);
}