Store::identity and Store::identities read the stored JSON of a TeamSpeak
identity with `?`, so a row whose data was damaged outside the client came back
as Error::Json carrying serde_json's message, and that message quotes a value
it refuses: tsproto reports a key that does not import as an invalid value, the
key string and all. The error reaches status lines, events and logs.
identity_from_json classifies the error as voelin-core's ts::identity::from_json
does (voelin-core depends on voelin-store, so the classification is here too):
Error::Identity { damage: IdentityDamage, line, column } says malformed, cut
short, not an identity or unreadable, and where, and nothing of the text.
Error::Json stays for the bookmarks and settings, which hold no secret.
The key store was checked as the recorded leak (docs/session-seam.md 17.6)
names it, and does not leak: check_teamspeak (keystore.rs) drops the parse
error with `let Ok(..) else`, Columns::level uses `map_or`, and the warning of a
damaged binding names the row's kind and uid. A test pins that too.
tests/identity_text.rs damages a row six ways (a key that does not import, a
counter of the wrong type, syntax, a text cut inside its key, bytes that are no
UTF-8 as a BLOB and as TEXT) through a second connection, calls everything of
Store and SqliteKeyStore that reads or writes it, and looks through the errors
(text, Debug and sources) and every log line at TRACE (a capturing subscriber in
tests/support) for any 8 characters in a row of the row's data. A control shows
that serde's own message quotes the value and that the capture sees a warning.
With identity_from_json returning the old error the first test fails, naming
the quoted key; the key store test is a guard.
docs/session-seam.md 17.6: the leak bullet is closed.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
88 lines
2.6 KiB
Rust
88 lines
2.6 KiB
Rust
//! Helpers the integration tests of this crate share.
|
|
|
|
// Each integration test crate of this directory uses some of these helpers.
|
|
#![allow(dead_code)]
|
|
|
|
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()
|
|
}
|