Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test: add rekey test for old->new pragma order migration

LearningCircuitcd200ef5e622
diff --git a/tests/auth_tests/test_sqlcipher_backwards_compat.py b/tests/auth_tests/test_sqlcipher_backwards_compat.py
index 17cc3dcdf9..092ddbb02b 100644
--- a/tests/auth_tests/test_sqlcipher_backwards_compat.py
+++ b/tests/auth_tests/test_sqlcipher_backwards_compat.py
@@ -577,3 +577,75 @@ class TestOldToNewPragmaOrderMigration:
)
conn2.close()
+
+ def test_rekey_on_old_db_with_new_code(
+ self, sqlcipher_module, temp_db_path
+ ):
+ """
+ Verify password change (rekey) works on databases created with
+ OLD pragma order when using NEW pragma order code.
+
+ This is a realistic scenario: user upgrades code, then wants to
+ change their password.
+ """
+ from src.local_deep_research.database.sqlcipher_utils import (
+ set_sqlcipher_rekey,
+ )
+
+ old_password = "original_password"
+ new_password = "changed_password"
+
+ # Create database using OLD pragma order
+ conn1 = self._create_connection_old_order(
+ sqlcipher_module, temp_db_path, old_password
+ )
+ conn1.execute(
+ "CREATE TABLE secrets (id INTEGER PRIMARY KEY, data TEXT)"
+ )
+ conn1.execute("INSERT INTO secrets VALUES (1, 'sensitive_data')")
+ conn1.commit()
+ conn1.close()
+
+ # Open with NEW pragma order and change password
+ conn2 = self._create_connection_new_order(
+ sqlcipher_module, temp_db_path, old_password
+ )
+
+ # Verify data is accessible before rekey
+ result = conn2.execute(
+ "SELECT data FROM secrets WHERE id = 1"
+ ).fetchone()
+ assert result[0] == "sensitive_data"
+
+ # Change the password
+ set_sqlcipher_rekey(conn2, new_password)
+ conn2.commit()
+ conn2.close()
+
+ # Verify old password no longer works
+ try:
+ conn_fail = self._create_connection_new_order(
+ sqlcipher_module, temp_db_path, old_password
+ )
+ # If we get here, try to access data (should fail)
+ conn_fail.execute("SELECT * FROM secrets").fetchone()
+ conn_fail.close()
+ raise AssertionError("Old password should not work after rekey")
+ except Exception as e:
+ # Expected - old password should fail
+ if "Old password should not work" in str(e):
+ raise
+ # Any other exception is expected (file is not a database, etc.)
+ pass
+
+ # Verify new password works
+ conn3 = self._create_connection_new_order(
+ sqlcipher_module, temp_db_path, new_password
+ )
+ result = conn3.execute(
+ "SELECT data FROM secrets WHERE id = 1"
+ ).fetchone()
+ assert result[0] == "sensitive_data", (
+ "Data should be accessible with new password after rekey"
+ )
+ conn3.close()