The module documents of keystore.rs are rewritten to the rule of open question 10 (accounts design, answered 2026-10-24): a sign-out keeps the device key unbound whether it predates the account or the client made it for the account (bound_existing_key is the client's wording and no rule reads it), the identities only this device holds are unbound and kept, and "Forget this device's identity" is the only deletion of a key of the device: signed in it is sign_out with DeviceKeyChoice::Forget(uid), signed out it is KeyStore::remove (a TeamSpeak identity: Store::delete_identity). The store has no export call; the docs say where the UI reads the bytes (voelin_key + to_pkcs8, Store::identity + ts::identity::export) before it forgets, which also serves the delete-account dialog's export of the device keys. What a sign-out still deletes is not a key of the device, and the docs now say so truthfully: the synced copies of integration secrets (private keys, scrubbed from the file and its log like any deleted key), the account record (no secret), and with Forget the device key. That is why SignOutPass stays: the trait's sign-out removes those rows, and the log is still truncated once after the last step, not per row, and not at all when nothing was deleted. The refusal of a synced device key stays and is reworded: the sign-out keeps the device key, but its first step deletes every synced copy before it reads the record, so a device key stored synced would be deleted all the same. Tests (the turned-around ones are in the previous commit): the device key's whole row is unchanged by a sign-out, with and without the flag; a key that carries a device-only binding is unbound and nothing else of its row changes; a sign-out scrubs what it deletes and leaves the kept keys in the file; the blocked-checkpoint test counts exactly one blocked checkpoint for four removals (Forget, so the removals are four as before), through a TRACE-level capture in tests/support; a sign-out that deletes nothing does not checkpoint; a key kept by a sign-out is exported, forgotten with no trace in the file or the log, and restored from the export. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
85 lines
2.5 KiB
Rust
85 lines
2.5 KiB
Rust
//! Helpers the integration tests of this crate share.
|
|
|
|
use std::fmt::{self, Write as _};
|
|
use std::sync::atomic::{AtomicU64, Ordering};
|
|
use std::sync::{Arc, Mutex, PoisonError};
|
|
|
|
use tracing::field::{Field, Visit};
|
|
use tracing::level_filters::LevelFilter;
|
|
use tracing::span::{Attributes, Id, Record};
|
|
use tracing::{Event, Metadata, Subscriber};
|
|
|
|
/// A subscriber that keeps every event and span it sees as one line of text
|
|
/// each: level, target and every field with its `Debug` text, as a log line
|
|
/// would show them.
|
|
struct Capture {
|
|
lines: Arc<Mutex<Vec<String>>>,
|
|
spans: AtomicU64,
|
|
}
|
|
|
|
impl Capture {
|
|
fn push(&self, line: String) {
|
|
self.lines.lock().unwrap_or_else(PoisonError::into_inner).push(line);
|
|
}
|
|
}
|
|
|
|
/// The fields of an event or a span as ` name=value` text.
|
|
struct Fields<'a>(&'a mut String);
|
|
|
|
impl Visit for Fields<'_> {
|
|
fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) {
|
|
let _ = write!(self.0, " {}={value:?}", field.name());
|
|
}
|
|
}
|
|
|
|
impl Subscriber for Capture {
|
|
fn enabled(&self, _: &Metadata<'_>) -> bool {
|
|
true
|
|
}
|
|
|
|
fn max_level_hint(&self) -> Option<LevelFilter> {
|
|
Some(LevelFilter::TRACE)
|
|
}
|
|
|
|
fn new_span(&self, attributes: &Attributes<'_>) -> Id {
|
|
let mut line = format!("span {}", attributes.metadata().name());
|
|
attributes.record(&mut Fields(&mut line));
|
|
self.push(line);
|
|
Id::from_u64(self.spans.fetch_add(1, Ordering::Relaxed) + 1)
|
|
}
|
|
|
|
fn record(&self, _: &Id, values: &Record<'_>) {
|
|
let mut line = String::from("span record");
|
|
values.record(&mut Fields(&mut line));
|
|
self.push(line);
|
|
}
|
|
|
|
fn record_follows_from(&self, _: &Id, _: &Id) {}
|
|
|
|
fn event(&self, event: &Event<'_>) {
|
|
let metadata = event.metadata();
|
|
let mut line = format!("{} {}:", metadata.level(), metadata.target());
|
|
event.record(&mut Fields(&mut line));
|
|
self.push(line);
|
|
}
|
|
|
|
fn enter(&self, _: &Id) {}
|
|
|
|
fn exit(&self, _: &Id) {}
|
|
}
|
|
|
|
/// Run `f` on this thread with a subscriber that takes in everything logged at
|
|
/// TRACE and above, and return what `f` returned with the lines logged.
|
|
pub fn at_trace<R>(f: impl FnOnce() -> R) -> (R, Vec<String>) {
|
|
let lines = Arc::new(Mutex::new(Vec::new()));
|
|
let subscriber = Capture { lines: Arc::clone(&lines), spans: AtomicU64::new(0) };
|
|
let out = tracing::subscriber::with_default(subscriber, f);
|
|
let lines = std::mem::take(&mut *lines.lock().unwrap_or_else(PoisonError::into_inner));
|
|
(out, lines)
|
|
}
|
|
|
|
/// How many of the lines say that a checkpoint was blocked.
|
|
pub fn blocked_checkpoints(lines: &[String]) -> usize {
|
|
lines.iter().filter(|line| line.contains("another connection blocked the checkpoint")).count()
|
|
}
|