mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 17:06:35 +03:00
fix: Clear VerifiedOneOnOneChats config on backup (#4681)
If the user makes a backup from a UI that supports the experimental verified 1:1 chats (e.g. nightly Android) and imports it into a UI that doesn't, then this config should be cleared. We already talked about this a long time ago after @Simon-Laux noticed this problem, but I think we didn't actually solve it back then? Best to review with whitespace changes disabled.
This commit is contained in:
107
src/imex.rs
107
src/imex.rs
@@ -771,6 +771,11 @@ async fn export_database(context: &Context, dest: &Path, passphrase: String) ->
|
|||||||
let res = conn
|
let res = conn
|
||||||
.query_row("SELECT sqlcipher_export('backup')", [], |_row| Ok(()))
|
.query_row("SELECT sqlcipher_export('backup')", [], |_row| Ok(()))
|
||||||
.context("failed to export to attached backup database");
|
.context("failed to export to attached backup database");
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE backup.config SET value='0' WHERE keyname='verified_one_on_one_chats';",
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
.ok(); // If verified_one_on_one_chats was not set, this errors, which we ignore
|
||||||
conn.execute("DETACH DATABASE backup", [])
|
conn.execute("DETACH DATABASE backup", [])
|
||||||
.context("failed to detach backup database")?;
|
.context("failed to detach backup database")?;
|
||||||
res?;
|
res?;
|
||||||
@@ -880,55 +885,73 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_export_and_import_backup() -> Result<()> {
|
async fn test_export_and_import_backup() -> Result<()> {
|
||||||
let backup_dir = tempfile::tempdir().unwrap();
|
for set_verified_oneonone_chats in [true, false] {
|
||||||
|
let backup_dir = tempfile::tempdir().unwrap();
|
||||||
|
|
||||||
let context1 = TestContext::new_alice().await;
|
let context1 = TestContext::new_alice().await;
|
||||||
assert!(context1.is_configured().await?);
|
assert!(context1.is_configured().await?);
|
||||||
|
if set_verified_oneonone_chats {
|
||||||
|
context1
|
||||||
|
.set_config_bool(Config::VerifiedOneOnOneChats, true)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
let context2 = TestContext::new().await;
|
let context2 = TestContext::new().await;
|
||||||
assert!(!context2.is_configured().await?);
|
assert!(!context2.is_configured().await?);
|
||||||
assert!(has_backup(&context2, backup_dir.path()).await.is_err());
|
assert!(has_backup(&context2, backup_dir.path()).await.is_err());
|
||||||
|
|
||||||
// export from context1
|
// export from context1
|
||||||
assert!(
|
assert!(
|
||||||
imex(&context1, ImexMode::ExportBackup, backup_dir.path(), None)
|
imex(&context1, ImexMode::ExportBackup, backup_dir.path(), None)
|
||||||
.await
|
.await
|
||||||
.is_ok()
|
.is_ok()
|
||||||
);
|
);
|
||||||
let _event = context1
|
let _event = context1
|
||||||
.evtracker
|
.evtracker
|
||||||
.get_matching(|evt| matches!(evt, EventType::ImexProgress(1000)))
|
.get_matching(|evt| matches!(evt, EventType::ImexProgress(1000)))
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// import to context2
|
// import to context2
|
||||||
let backup = has_backup(&context2, backup_dir.path()).await?;
|
let backup = has_backup(&context2, backup_dir.path()).await?;
|
||||||
|
|
||||||
// Import of unencrypted backup with incorrect "foobar" backup passphrase fails.
|
// Import of unencrypted backup with incorrect "foobar" backup passphrase fails.
|
||||||
assert!(imex(
|
assert!(imex(
|
||||||
&context2,
|
&context2,
|
||||||
ImexMode::ImportBackup,
|
ImexMode::ImportBackup,
|
||||||
backup.as_ref(),
|
backup.as_ref(),
|
||||||
Some("foobar".to_string())
|
Some("foobar".to_string())
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.is_err());
|
.is_err());
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
imex(&context2, ImexMode::ImportBackup, backup.as_ref(), None)
|
imex(&context2, ImexMode::ImportBackup, backup.as_ref(), None)
|
||||||
.await
|
.await
|
||||||
.is_ok()
|
.is_ok()
|
||||||
);
|
);
|
||||||
let _event = context2
|
let _event = context2
|
||||||
.evtracker
|
.evtracker
|
||||||
.get_matching(|evt| matches!(evt, EventType::ImexProgress(1000)))
|
.get_matching(|evt| matches!(evt, EventType::ImexProgress(1000)))
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
assert!(context2.is_configured().await?);
|
|
||||||
assert_eq!(
|
|
||||||
context2.get_config(Config::Addr).await?,
|
|
||||||
Some("alice@example.org".to_string())
|
|
||||||
);
|
|
||||||
|
|
||||||
|
assert!(context2.is_configured().await?);
|
||||||
|
assert_eq!(
|
||||||
|
context2.get_config(Config::Addr).await?,
|
||||||
|
Some("alice@example.org".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
context2
|
||||||
|
.get_config_bool(Config::VerifiedOneOnOneChats)
|
||||||
|
.await?,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
context1
|
||||||
|
.get_config_bool(Config::VerifiedOneOnOneChats)
|
||||||
|
.await?,
|
||||||
|
set_verified_oneonone_chats
|
||||||
|
);
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user