Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Make SQLite in-memory writable, add test to verify (#846)
Leendert de Borstf30fcf462489
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.ktindex 78d309614..6eac26af4 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt@@ -284,6 +284,9 @@ class VaultStore(private val storageProvider: StorageProvider) {tempDbFile = File.createTempFile("temp_db", ".sqlite")tempDbFile.writeBytes(decryptedDbData)+ // Close any existing connection if it exists+ dbConnection?.close()+// Create an in-memory databasedbConnection = SQLiteDatabase.create(null)@@ -309,7 +312,7 @@ class VaultStore(private val storageProvider: StorageProvider) {while (it.moveToNext()) {val tableName = it.getString(0)// Create table and copy data using rawQuery- dbConnection?.rawQuery("CREATE TABLE $tableName AS SELECT * FROM source.$tableName", null)+ dbConnection?.execSQL("CREATE TABLE $tableName AS SELECT * FROM source.$tableName")}}diff --git a/apps/mobile-app/android/app/src/test/java/net/aliasvault/app/nativevaultmanager/VaultStoreTest.kt b/apps/mobile-app/android/app/src/test/java/net/aliasvault/app/nativevaultmanager/VaultStoreTest.ktindex f5428edbf..88deff29d 100644--- a/apps/mobile-app/android/app/src/test/java/net/aliasvault/app/nativevaultmanager/VaultStoreTest.kt+++ b/apps/mobile-app/android/app/src/test/java/net/aliasvault/app/nativevaultmanager/VaultStoreTest.kt@@ -7,6 +7,7 @@ import org.robolectric.RobolectricTestRunnerimport org.robolectric.annotation.Configimport net.aliasvault.app.vaultstore.VaultStoreimport net.aliasvault.app.vaultstore.storageprovider.TestStorageProvider+import java.util.Dateimport kotlin.test.*@RunWith(RobolectricTestRunner::class)@@ -91,6 +92,35 @@ class VaultStoreTest {assertTrue(logo.size > 1024, "Logo data should exceed 1KB in size")}+ @Test+ fun testDatabaseWriteOperation() {+ // Create a test setting+ val testKey = "test_setting_key"+ val testValue = "test_setting_value"++ // Begin transaction+ vaultStore.beginTransaction()+ try {+ // Insert the setting using raw SQL with parameters+ val insertSql = "INSERT INTO Settings (Key, Value, CreatedAt, UpdatedAt, IsDeleted) VALUES (?, ?, ?, ?, ?)"+ val insertResult = vaultStore.executeUpdate(insertSql, arrayOf(testKey, testValue, "2025-01-01 00:00:00", "2025-01-01 00:00:00", 0))+ assertTrue(insertResult > 0, "Setting insertion should succeed")++ // Verify the setting was inserted by querying it+ val querySql = "SELECT Value FROM Settings WHERE Key = ?"+ val results = vaultStore.executeQuery(querySql, arrayOf(testKey))++ assertTrue(results.isNotEmpty(), "Should get a result (amount of updated rows)")++ // If everything succeeded, commit the transaction+ vaultStore.commitTransaction()+ } catch (e: Exception) {+ // If anything fails, rollback the transaction+ vaultStore.rollbackTransaction()+ throw e+ }+ }+private fun loadTestDatabase(): String {// Load the test database file from resourcesval inputStream = javaClass.classLoader?.getResourceAsStream("test-encrypted-vault.txt")