mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
fix: If importing a backup fails, delete the partially-imported profile (#7885)
fix https://github.com/chatmail/core/issues/7863 `test_import_encrypted_bak_into_encrypted_acct` CFFI test fails because it tests that trying to import an encrypted account with a wrong passphrase into an already-encrypted database will fail, but leave the already-encrypted database (esp, leave it with the same password). But in order to reset the database after a failed login attempt, I'm using this code: ```rust context.sql.close().await; fs::remove_file(context.sql.dbfile.as_path()) .await .log_err(context) .ok(); context .sql .open(context, "".to_string()) // <-- NOTE THIS LINE .await .log_err(context) .ok(); ``` We're not remembering the password, so, we can't just pass the correct password there. Since password-protected databases are not really supported anyways, we decided to just skip the test. I also tried two tricks for deleting everything [found on Stackoverflow](https://stackoverflow.com/questions/525512/drop-all-tables-command), but neither of them managed to actually reset the database (i.e. they led to a failed Rust test, because asserting `!context2.is_configured().await?` failed): ```rust context .sql .call_write(|conn| { let mut stmt = conn.prepare( "select 'drop table ' || name || ';' from sqlite_master where type = 'table';", )?; let mut iter = stmt.query(())?; while iter.next()?.is_some() {} Ok(()) }) .await .log_err(context) .ok(); context .sql .run_migrations(context) .await .log_err(context) .ok(); ``` ```rust context .sql .transaction(|t| { t.execute_batch( " PRAGMA writable_schema = 1; delete from sqlite_master where type in ('table', 'index', 'trigger'); PRAGMA writable_schema = 0", )?; Ok(()) }) .await .log_err(context) .ok(); context .sql .run_migrations(context) .await .log_err(context) .ok(); ``` --------- Co-authored-by: l <link2xt@testrun.org>
This commit is contained in:
@@ -558,6 +558,12 @@ class TestOfflineChat:
|
||||
assert messages[0 + E2EE_INFO_MSGS].text == "msg1"
|
||||
assert os.path.exists(messages[1 + E2EE_INFO_MSGS].filename)
|
||||
|
||||
@pytest.mark.skip(
|
||||
reason="We didn't find a way to correctly reset an account after a failed import attempt "
|
||||
"while simultaneously making sure "
|
||||
"that the password of an encrypted account survives a failed import attempt. "
|
||||
"Since passphrases are not really supported anymore, we decided to just disable the test.",
|
||||
)
|
||||
def test_import_encrypted_bak_into_encrypted_acct(self, acfactory, tmp_path):
|
||||
"""
|
||||
Test that account passphrase isn't lost if backup failed to be imported.
|
||||
|
||||
Reference in New Issue
Block a user