diff --git a/Cargo.lock b/Cargo.lock index 48fd03b..aea5df7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9703,6 +9703,7 @@ dependencies = [ "serde", "serde_json", "thiserror 2.0.21", + "tracing", "tsclientlib", "voelin-identity", ] diff --git a/crates/voelin-store/Cargo.toml b/crates/voelin-store/Cargo.toml index b20313f..56cb5ba 100644 --- a/crates/voelin-store/Cargo.toml +++ b/crates/voelin-store/Cargo.toml @@ -19,6 +19,7 @@ rusqlite = { version = "0.40.2", features = ["bundled"] } serde = { version = "1.0.229", features = ["derive"] } serde_json = "1.0.151" thiserror = "2.0.21" +tracing = "0.1.44" tsclientlib = { path = "../proto/tsclientlib" } voelin-identity = { workspace = true } diff --git a/crates/voelin-store/src/keystore.rs b/crates/voelin-store/src/keystore.rs index 8e0f2ef..f1fb940 100644 --- a/crates/voelin-store/src/keystore.rs +++ b/crates/voelin-store/src/keystore.rs @@ -24,6 +24,23 @@ //! `data` again. That is how [`KeyStore::sign_out`] unbinds a device-only //! secret, so a damaged row never blocks it. //! +//! A row that is damaged elsewhere never fails a call that is not about it. A +//! row whose binding columns cannot be read (`synced = 2`, an `account` that is +//! no uid, a revision that is no integer; only something outside this crate +//! writes them) is listed and read as unbound, and a warning names the row and +//! the reason. [`KeyStore::list`] fails only when the database does, because +//! the trait's [`KeyStore::sign_out`] starts with it and then reads the account +//! record and the device key with [`KeyStore::get`]: one damaged row, the +//! record's own included, would otherwise keep a sign-out from ever finishing, +//! and with it the deletion of the key the user asked to forget. Unbound is the +//! reading that never deletes on a guess: a sign-out neither deletes such a row +//! as a synced copy nor writes it, it stays as it is until a `put` of it writes +//! four good binding columns. A `data` column that is not text is read as text +//! with the odd bytes replaced, so that a record that cannot be read is deleted +//! by the sign-out, as the trait says, instead of its read failing; a row whose +//! `kind` or `uid` is not text cannot be addressed, and the list leaves it out +//! with a warning. +//! //! A TeamSpeak blob that is refused says why in words that carry none of its //! input: its `data` is the identity's private key, and an error reaches log //! lines. @@ -32,6 +49,7 @@ use std::path::Path; use std::sync::{Mutex, MutexGuard, PoisonError}; use rusqlite::params; +use rusqlite::types::ValueRef; use tsclientlib::Identity; use voelin_identity::migrate::SELECT_ACCOUNT_COLUMNS; use voelin_identity::{ @@ -46,7 +64,7 @@ type KsResult = std::result::Result; /// The rows of [`KeyStore::list`]. The secret of a kind this crate does not /// interpret is never read; a TeamSpeak row's `data` is, for its level. const LIST: &str = "SELECT kind, uid, CASE WHEN kind = 'teamspeak' THEN data END, - account, integration, integration_rev, synced + account, integration, integration_rev, synced, id FROM identities ORDER BY kind, uid"; /// Replace the binding of the row of this `(kind, uid)` if its `data` is @@ -118,16 +136,21 @@ impl KeyStore for SqliteKeyStore { let store = self.lock(); let mut statement = store.db.prepare_cached(LIST).map_err(backend)?; let rows = statement.query_map([], Columns::read).map_err(backend)?; - rows.map(|row| row.map_err(backend)?.into_info()).collect() + let mut infos = Vec::new(); + for row in rows { + infos.extend(row.map_err(backend)?.map(Columns::into_info)); + } + Ok(infos) } fn get(&self, kind: &str, uid: &str) -> KsResult> { let store = self.lock(); - let sql = - format!("SELECT {SELECT_ACCOUNT_COLUMNS} FROM identities WHERE kind = ?1 AND uid = ?2"); + let sql = format!( + "SELECT {SELECT_ACCOUNT_COLUMNS}, id FROM identities WHERE kind = ?1 AND uid = ?2" + ); let mut statement = store.db.prepare_cached(&sql).map_err(backend)?; let mut rows = statement.query_map(params![kind, uid], Columns::read).map_err(backend)?; - rows.next().transpose().map_err(backend)?.map(Columns::into_blob).transpose() + Ok(rows.next().transpose().map_err(backend)?.flatten().map(Columns::into_blob)) } fn put(&self, blob: &IdentityBlob) -> KsResult<()> { @@ -232,38 +255,48 @@ enum Refused { UidHeld { uid: String, kind: String }, } -/// One row of the table as `LIST` and `SELECT_ACCOUNT_COLUMNS` select it. +/// One row of the table as `LIST` and `SELECT_ACCOUNT_COLUMNS` select it (with +/// the row id last), its binding already read. struct Columns { kind: String, uid: String, /// The identity itself. `LIST` leaves it out for kinds with no level. data: Option, - account: Option, - integration: Option, - rev: i64, - synced: i64, + /// `None` for an unbound row and for one whose binding columns are damaged. + binding: Option, +} + +/// Why binding columns cannot be read. +#[derive(Debug, thiserror::Error)] +enum Damage { + #[error(transparent)] + Binding(#[from] BlobError), + #[error("a binding column holds a value of the wrong type")] + WrongType, } impl Columns { - fn read(row: &rusqlite::Row<'_>) -> rusqlite::Result { - Ok(Self { - kind: row.get(0)?, - uid: row.get(1)?, - data: row.get(2)?, - account: row.get(3)?, - integration: row.get(4)?, - rev: row.get(5)?, - synced: row.get(6)?, - }) - } - - fn binding(&self) -> KsResult> { - Ok(AccountBinding::from_columns( - self.account.as_deref(), - self.integration.as_deref(), - self.rev, - self.synced, - )?) + /// The row, or `None` for a row that cannot be addressed (its `kind` or + /// `uid` is not text) and is left out with a warning. + fn read(row: &rusqlite::Row<'_>) -> rusqlite::Result> { + let id: i64 = row.get(7)?; + let (Ok(kind), Ok(uid)) = (row.get_ref(0)?.as_str(), row.get_ref(1)?.as_str()) else { + tracing::warn!(id, "an identities row whose kind or uid is not text is left out"); + return Ok(None); + }; + let binding = read_binding(row).unwrap_or_else(|damage| { + tracing::warn!( + id, kind, uid, %damage, + "the binding columns of an identity cannot be read: it is treated as unbound", + ); + None + }); + Ok(Some(Self { + kind: kind.to_owned(), + uid: uid.to_owned(), + data: lossy_text(row.get_ref(2)?), + binding, + })) } /// The security level of a TeamSpeak row, 0 for any other kind and for JSON @@ -277,16 +310,39 @@ impl Columns { } } - fn into_info(self) -> KsResult { - let binding = self.binding()?; + fn into_info(self) -> IdentityInfo { let level = self.level(); - Ok(IdentityInfo { kind: self.kind, uid: self.uid, level, binding }) + IdentityInfo { kind: self.kind, uid: self.uid, level, binding: self.binding } } - fn into_blob(self) -> KsResult { - let binding = self.binding()?; + fn into_blob(self) -> IdentityBlob { let level = self.level(); let data = self.data.unwrap_or_default(); - Ok(IdentityBlob::from_row(&self.kind, self.uid, level, data).with_binding(binding)) + IdentityBlob::from_row(&self.kind, self.uid, level, data).with_binding(self.binding) + } +} + +/// The binding of a row from its four columns (3 to 6 of both selects). +fn read_binding(row: &rusqlite::Row<'_>) -> std::result::Result, Damage> { + let column = |index| row.get_ref(index).map_err(|_| Damage::WrongType); + let account = column(3)?.as_str_or_null().map_err(|_| Damage::WrongType)?; + let integration = column(4)?.as_str_or_null().map_err(|_| Damage::WrongType)?; + let rev = column(5)?.as_i64().map_err(|_| Damage::WrongType)?; + let synced = column(6)?.as_i64().map_err(|_| Damage::WrongType)?; + Ok(AccountBinding::from_columns(account, integration, rev, synced)?) +} + +/// A `data` column as text, whatever it holds. Bytes that are no UTF-8 and +/// values of another type are damage; read as text they fail where the +/// blob's kind is checked, with that kind's own error, instead of failing the +/// read of the row. +fn lossy_text(value: ValueRef<'_>) -> Option { + match value { + ValueRef::Null => None, + ValueRef::Integer(n) => Some(n.to_string()), + ValueRef::Real(x) => Some(x.to_string()), + ValueRef::Text(bytes) | ValueRef::Blob(bytes) => { + Some(String::from_utf8_lossy(bytes).into_owned()) + } } } diff --git a/crates/voelin-store/tests/keystore.rs b/crates/voelin-store/tests/keystore.rs index 2d5a396..8e4fdf5 100644 --- a/crates/voelin-store/tests/keystore.rs +++ b/crates/voelin-store/tests/keystore.rs @@ -26,7 +26,7 @@ use tsclientlib::Identity; use voelin_identity::{ AccountBinding, AccountId, AccountRecord, BlobError, DeviceKeyChoice, IdentityBlob, IdentityInfo, IdentityKey, IntegrationId, KIND_ACCOUNT, KIND_TEAMSPEAK, KIND_VOELIN, KeyStore, - KeyStoreError, SignOut, Uid, UidParseError, account_uid, + KeyStoreError, SignOut, Uid, account_uid, }; use voelin_store::{IdentityOrigin, SqliteKeyStore, Store}; @@ -408,37 +408,112 @@ fn the_account_record_goes_through_the_stores_own_accessors() { assert!(matches!(store.account_record(), Err(KeyStoreError::Blob(BlobError::AccountJson)))); } +/// The ways the binding columns of a row can be damaged outside this crate: +/// what `AccountBinding::from_columns` refuses, and values of the wrong type. +/// Each is applied to a row that has a good account. +const BINDING_DAMAGE: [&str; 11] = [ + "account = 'junk'", + "synced = 2", + "synced = -1", + "integration_rev = -3", + "integration = 'nope'", + // An integration, a revision or a flag without an account. + "account = NULL, integration = 'aaaqeayeaudaocajbifqydiob4'", + "account = NULL, integration_rev = 5", + "account = NULL, synced = 2", + // Values of another type than the column's. + "synced = 'yes'", + "integration_rev = 'many'", + "account = x'0102'", +]; + #[test] -fn damaged_binding_columns_are_precise_errors_when_read() { +fn a_row_whose_binding_columns_cannot_be_read_is_listed_and_read_as_unbound() { + // A listing that fails on one damaged row would keep a sign-out from ever + // finishing (it starts with the list), so the row reads as unbound, with a + // warning, and everything else about it is as stored. let scratch = Scratch::new("damaged"); let store = SqliteKeyStore::open(&scratch.db()).unwrap(); - store.put(&teamspeak_blob()).unwrap(); + let ts = teamspeak_blob(); + store.put(&ts).unwrap(); + let neighbour = fresh_teamspeak(binding()); + store.put(&neighbour).unwrap(); let db = Connection::open(scratch.db()).unwrap(); - let set = |sql: &str| { - db.execute(&format!("UPDATE identities SET {sql} WHERE uid = ?1"), [TEAMSPEAK_UID]).unwrap() + let account = binding_for(1); + let reset = || { + db.execute( + "UPDATE identities SET account = ?2, integration = NULL, integration_rev = 0, + synced = 0 WHERE uid = ?1", + [TEAMSPEAK_UID, &account.to_base32()], + ) + .unwrap(); }; - let read = || store.get(KIND_TEAMSPEAK, TEAMSPEAK_UID); - set("account = 'junk'"); - assert!(matches!( - read(), - Err(KeyStoreError::Blob(BlobError::BindingAccount(UidParseError::Length(4)))) - )); - // A listing fails the same way: a damaged row is reported, not skipped. - assert!(matches!(store.list(), Err(KeyStoreError::Blob(BlobError::BindingAccount(_))))); + reset(); + let bound = store.get(KIND_TEAMSPEAK, TEAMSPEAK_UID).unwrap().unwrap(); + assert_eq!(bound.binding.map(|b| b.account), Some(account)); + assert_eq!(store.bound_to(&account).unwrap().len(), 1); - set(&format!("account = '{}'", binding_for(1).to_base32())); - assert_eq!(read().unwrap().unwrap().binding.unwrap().account, binding_for(1)); + for damage in BINDING_DAMAGE { + reset(); + db.execute(&format!("UPDATE identities SET {damage} WHERE uid = ?1"), [TEAMSPEAK_UID]) + .unwrap(); + // Read: the identity, unbound, its JSON and level as stored. + let read = store.get(KIND_TEAMSPEAK, TEAMSPEAK_UID).unwrap().expect(damage); + assert_eq!(read, ts, "{damage}"); + assert_eq!(read.json, TEAMSPEAK_JSON, "{damage}"); + // Listed: still there, unbound, and its neighbour is untouched. + let listed = store.list().unwrap(); + assert_eq!(listed.len(), 2, "{damage}"); + let row = listed.iter().find(|i| i.uid == TEAMSPEAK_UID).expect(damage); + assert_eq!((row.binding, row.level), (None, TEAMSPEAK_LEVEL), "{damage}"); + let next = listed.iter().find(|i| i.uid == neighbour.uid).unwrap(); + assert_eq!(next.binding, neighbour.binding, "{damage}"); + // It belongs to no account as far as a sign-out can tell: not a guess. + assert!(store.bound_to(&account).unwrap().is_empty(), "{damage}"); + assert_eq!(store.bound_to(&binding().account).unwrap().len(), 1, "{damage}"); + } - set("synced = 2"); - assert!(matches!(read(), Err(KeyStoreError::Blob(BlobError::BindingSynced(2))))); - set("synced = 0, integration_rev = -3"); - assert!(matches!(read(), Err(KeyStoreError::Blob(BlobError::BindingRevision)))); - set("integration_rev = 0, integration = 'nope'"); - assert!(matches!(read(), Err(KeyStoreError::Blob(BlobError::BindingIntegration(_))))); - // An integration without an account. - set("account = NULL, integration = 'aaaqeayeaudaocajbifqydiob4'"); - assert!(matches!(read(), Err(KeyStoreError::Blob(BlobError::BindingOrphan)))); + // A put of the row writes four good columns, however it was damaged. + let rebound = ts.clone().with_binding(binding()); + store.put(&rebound).unwrap(); + assert_eq!(store.get(KIND_TEAMSPEAK, TEAMSPEAK_UID).unwrap().unwrap(), rebound); + let (synced, rev): (i64, i64) = db + .query_row( + "SELECT synced, integration_rev FROM identities WHERE uid = ?1", + [TEAMSPEAK_UID], + |r| Ok((r.get(0)?, r.get(1)?)), + ) + .unwrap(); + assert_eq!((synced, rev), (1, 3)); +} + +#[test] +fn a_row_that_cannot_be_addressed_is_left_out_of_the_list() { + // A `kind` or `uid` that is not text cannot be named in `get` or `remove`, + // so the list has nothing to show for it; it must not fail the others. + let scratch = Scratch::new("unaddressable"); + let store = SqliteKeyStore::open(&scratch.db()).unwrap(); + store.put(&teamspeak_blob()).unwrap(); + store.put_voelin_key(&key()).unwrap(); + let db = Connection::open(scratch.db()).unwrap(); + let id: i64 = db + .query_row("SELECT id FROM identities WHERE uid = ?1", [TEAMSPEAK_UID], |r| r.get(0)) + .unwrap(); + for (column, original) in [("uid", TEAMSPEAK_UID), ("kind", KIND_TEAMSPEAK)] { + db.execute(&format!("UPDATE identities SET {column} = x'0102' WHERE id = ?1"), [id]) + .unwrap(); + let listed = store.list().unwrap(); + assert_eq!(sorted(listed), [(KIND_VOELIN.to_owned(), RFC8032_UID.to_owned())], "{column}"); + assert!(store.get(KIND_TEAMSPEAK, TEAMSPEAK_UID).unwrap().is_none(), "{column}"); + db.execute( + &format!("UPDATE identities SET {column} = ?2 WHERE id = ?1"), + params![id, original], + ) + .unwrap(); + assert_eq!(store.list().unwrap().len(), 2, "{column}"); + } + assert_eq!(store.get(KIND_TEAMSPEAK, TEAMSPEAK_UID).unwrap().unwrap(), teamspeak_blob()); } // ------------------------------------- what the TeamSpeak methods share @@ -1168,3 +1243,189 @@ fn a_sign_out_is_durable_in_the_file() { .unwrap(); assert_eq!(account, None); } + +// ------------------------------- sign-out with damaged rows (the gate's probe) + +/// A signed-in install on a file, to damage through a second connection (as +/// something outside this crate could): the device key, the record with the +/// given key flag, a synced copy, a device-only secret and a local identity. +struct OnFile { + scratch: Scratch, + store: SqliteKeyStore, + synced: IdentityBlob, + device_only: IdentityBlob, + local: IdentityBlob, +} + +fn signed_in_install_on_file(bound_existing_key: bool) -> OnFile { + let scratch = Scratch::new("signed-in"); + let store = SqliteKeyStore::open(&scratch.db()).unwrap(); + let synced = fresh_teamspeak(binding()); + let device_only = fresh_teamspeak(AccountBinding { synced: false, ..binding() }); + let local = fresh_teamspeak(None); + store.put_voelin_key(&key()).unwrap(); + store.put_account_record(&AccountRecord { bound_existing_key, ..record() }).unwrap(); + for blob in [&synced, &device_only, &local] { + store.put(blob).unwrap(); + } + OnFile { scratch, store, synced, device_only, local } +} + +impl OnFile { + /// Run one statement on the file, which must change a row. + fn damage(&self, sql: &str) { + let db = Connection::open(self.scratch.db()).unwrap(); + assert_eq!(db.execute(sql, []).unwrap(), 1, "{sql}"); + } + + /// What a sign-out of `choice` must have done, whatever else was damaged: + /// the record and the synced copy are gone, the device-only secret is + /// unbound and the local identity is as it was; the device key is deleted + /// when the user forgot it or the client made it for the account, and + /// reported as kept and unbound otherwise. + fn assert_signed_out( + &self, + done: &SignOut, + bound_existing_key: bool, + choice: DeviceKeyChoice, + label: &str, + ) { + let key_goes = matches!(choice, DeviceKeyChoice::Forget(_)) || !bound_existing_key; + let mut removed = vec![(KIND_ACCOUNT.to_owned(), record().blob_uid()), pair(&self.synced)]; + let mut unbound = vec![pair(&self.device_only)]; + let device_key = (KIND_VOELIN.to_owned(), key().uid().to_base32()); + if key_goes { + removed.push(device_key) + } else { + unbound.push(device_key) + } + removed.sort(); + unbound.sort(); + assert_eq!(sorted(done.removed.clone()), removed, "{label}: {done:?}"); + assert_eq!(sorted(done.unbound.clone()), unbound, "{label}: {done:?}"); + + let store = &self.store; + assert!(store.get(KIND_ACCOUNT, &record().blob_uid()).unwrap().is_none(), "{label}"); + assert!(store.get(KIND_TEAMSPEAK, &self.synced.uid).unwrap().is_none(), "{label}"); + let secret = store.get(KIND_TEAMSPEAK, &self.device_only.uid).unwrap().unwrap(); + assert_eq!(secret, self.device_only.clone().with_binding(None), "{label}"); + assert_eq!(store.get(KIND_TEAMSPEAK, &self.local.uid).unwrap().unwrap(), self.local); + assert_eq!(store.voelin_key(&key().uid()).unwrap().is_none(), key_goes, "{label}"); + // A retry has nothing left to do. + assert_eq!( + store.sign_out(&binding().account, choice).unwrap(), + SignOut::default(), + "{label}" + ); + } +} + +/// The ways the row of the account record can be damaged in its binding +/// columns, the first being the gate's probe. +const RECORD_ROW_DAMAGE: [&str; 5] = [ + "UPDATE identities SET synced = 2 WHERE kind = 'account'", + "UPDATE identities SET account = 'junk' WHERE kind = 'account'", + "UPDATE identities SET integration = 'aaaqeayeaudaocajbifqydiob4' WHERE kind = 'account'", + "UPDATE identities SET integration_rev = 'many' WHERE kind = 'account'", + "UPDATE identities SET account = x'0102' WHERE kind = 'account'", +]; + +#[test] +fn a_damaged_account_record_row_does_not_keep_a_sign_out_from_finishing() { + // The record carries no binding, so damage in those columns says nothing + // about the record: it is read, and the sign-out does what it always does. + // `Forget` deletes the key it names; `Auto` follows the record. + for bound_existing_key in [true, false] { + for damage in RECORD_ROW_DAMAGE { + for choice in [DeviceKeyChoice::Auto, DeviceKeyChoice::Forget(key().uid())] { + let label = format!("{bound_existing_key}, {choice:?}, {damage}"); + let install = signed_in_install_on_file(bound_existing_key); + install.damage(damage); + let done = install + .store + .sign_out(&binding().account, choice) + .unwrap_or_else(|error| panic!("{label}: {error}")); + install.assert_signed_out(&done, bound_existing_key, choice, &label); + } + } + } +} + +#[test] +fn a_damaged_device_key_row_does_not_keep_a_sign_out_from_finishing() { + // With `Auto` and a key that predates the account, the trait reads the key + // to report it as kept. Damage in its binding columns must not fail that. + for bound_existing_key in [true, false] { + for damage in [ + "UPDATE identities SET synced = 2 WHERE kind = 'voelin'", + "UPDATE identities SET account = 'junk' WHERE kind = 'voelin'", + "UPDATE identities SET integration_rev = 'many' WHERE kind = 'voelin'", + ] { + let label = format!("{bound_existing_key}, {damage}"); + let install = signed_in_install_on_file(bound_existing_key); + install.damage(damage); + let done = install + .store + .sign_out(&binding().account, DeviceKeyChoice::Auto) + .unwrap_or_else(|error| panic!("{label}: {error}")); + install.assert_signed_out(&done, bound_existing_key, DeviceKeyChoice::Auto, &label); + if bound_existing_key { + // The key was kept, as it was stored. + let kept = install.store.voelin_key(&key().uid()).unwrap().unwrap(); + assert_eq!(&kept.to_pkcs8().unwrap()[..], &key().to_pkcs8().unwrap()[..]); + } + } + } +} + +#[test] +fn a_damaged_synced_copy_is_not_deleted_on_a_guess() { + // Its binding cannot be read, so a sign-out cannot know it is a copy of what + // the service holds: it stays, unbound as far as the store can tell, and the + // rest of the sign-out is done. + let install = signed_in_install_on_file(true); + install + .damage(&format!("UPDATE identities SET synced = 2 WHERE uid = '{}'", install.synced.uid)); + let done = install.store.sign_out(&binding().account, DeviceKeyChoice::Auto).unwrap(); + assert_eq!(done.removed.len(), 1, "only the record: {done:?}"); + assert!(done.removed.iter().all(|i| i.kind == KIND_ACCOUNT), "{done:?}"); + let kept = install.store.get(KIND_TEAMSPEAK, &install.synced.uid).unwrap().unwrap(); + assert_eq!((kept.binding, kept.json.as_str()), (None, install.synced.json.as_str())); + assert_eq!(install.store.account_record().unwrap(), None); + let again = install.store.sign_out(&binding().account, DeviceKeyChoice::Auto).unwrap(); + assert_eq!(again, SignOut::default()); +} + +#[test] +fn an_account_row_whose_data_is_not_text_is_deleted_like_an_unreadable_record() { + // A `data` column that holds bytes or a number reads as text that is no + // record: the trait deletes the record before it reports the error, so the + // sign-out finishes on the second call at the latest instead of failing the + // read for ever. `Forget` deletes the key it names first. + for damage in [ + "UPDATE identities SET data = x'ff00fe' WHERE kind = 'account'", + "UPDATE identities SET data = 5 WHERE kind = 'account'", + "UPDATE identities SET data = 1.5 WHERE kind = 'account'", + ] { + for choice in [DeviceKeyChoice::Auto, DeviceKeyChoice::Forget(key().uid())] { + let label = format!("{choice:?}, {damage}"); + let install = signed_in_install_on_file(true); + install.damage(damage); + let error = install.store.sign_out(&binding().account, choice).unwrap_err(); + assert!( + matches!(error, KeyStoreError::Blob(BlobError::AccountJson)), + "{label}: {error:?}" + ); + + let store = &install.store; + assert!(store.get(KIND_ACCOUNT, &record().blob_uid()).unwrap().is_none(), "{label}"); + assert!(store.get(KIND_TEAMSPEAK, &install.synced.uid).unwrap().is_none(), "{label}"); + let secret = store.get(KIND_TEAMSPEAK, &install.device_only.uid).unwrap().unwrap(); + assert_eq!(secret.binding, None, "{label}"); + // `Auto` cannot find the key the record named, and keeps it. + let forgot = matches!(choice, DeviceKeyChoice::Forget(_)); + assert_eq!(store.voelin_key(&key().uid()).unwrap().is_none(), forgot, "{label}"); + assert_eq!(store.sign_out(&binding().account, choice).unwrap(), SignOut::default()); + } + } +} diff --git a/docs/architecture.md b/docs/architecture.md index 2b60763..5a0b51a 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -349,6 +349,10 @@ names (the error says only that, never the JSON: it is a private key), and the TeamSpeak security level is still computed from the key, never stored. A `put` that changes only the binding of a row does not read its JSON again, so a row damaged outside the client cannot keep a sign-out from unbinding it. +A row whose binding columns cannot be read is listed and read as unbound, with a +warning, instead of failing the list; so no damaged row, the account record's +included, keeps a sign-out from finishing, and `Forget` still deletes the key +it names. Signing out of an account is the trait's `sign_out`, run on this table: it removes the account record and the synced copies, unbinds the identities only this device holds, keeps the device key (unbound, byte for byte) when the