Skip to content

Commit 81b2dfb

Browse files
committed
Fix device tests
1 parent b12b834 commit 81b2dfb

File tree

4 files changed

+43
-57
lines changed

4 files changed

+43
-57
lines changed

core-tests-android/proguard-rules.pro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
*;
3131
}
3232

33+
-keep class androidx.test.** {
34+
*;
35+
}
36+
3337
-keep class androidx.tracing.Trace {
3438
public static void beginSection(java.lang.String);
3539
public static void endSection();

core-tests-android/src/androidTest/java/com/powersync/AndroidDatabaseTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,7 @@ class AndroidDatabaseTest {
4444

4545
@Test
4646
fun canUseTempStore() = helpers.canUseTempStore()
47+
48+
@Test
49+
fun testEncryptedDatabase() = helpers.testEncryptedDatabase()
4750
}

core-tests-android/src/androidTest/java/com/powersync/EncryptedDatabaseTest.kt

Lines changed: 0 additions & 57 deletions
This file was deleted.

core-tests-android/src/main/java/com/powersync/testutils/IntegrationTestHelpers.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package com.powersync.testutils
22

33
import android.content.Context
4+
import androidx.sqlite.SQLiteException
5+
import androidx.sqlite.execSQL
46
import app.cash.turbine.turbineScope
57
import com.powersync.DatabaseDriverFactory
68
import com.powersync.PowerSyncDatabase
79
import com.powersync.PowerSyncException
810
import com.powersync.db.schema.Schema
11+
import com.powersync.encryption.AndroidEncryptedDatabaseFactory
12+
import com.powersync.encryption.Key
913
import kotlinx.coroutines.CompletableDeferred
1014
import kotlinx.coroutines.async
1115
import kotlinx.coroutines.runBlocking
@@ -228,4 +232,36 @@ class IntegrationTestHelpers(private val context: Context) {
228232
database.execute("INSERT INTO foo VALUES (?)", parameters = listOf(data))
229233
}
230234
}
235+
236+
fun testEncryptedDatabase() = runTest {
237+
val database = PowerSyncDatabase(
238+
factory = AndroidEncryptedDatabaseFactory(
239+
context,
240+
Key.Passphrase("mykey")
241+
),
242+
schema = Schema(UserRow.table),
243+
dbFilename = "encrypted_test",
244+
)
245+
246+
check(database.get("PRAGMA cipher") { it.getString(0)!! } == "chacha20") {
247+
"Should be able to query PRAGMA cipher"
248+
}
249+
250+
database.execute(
251+
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
252+
listOf("Test", "test@example.org"),
253+
)
254+
database.close()
255+
256+
val unencryptedFactory = DatabaseDriverFactory(context)
257+
val unencrypted = unencryptedFactory.openConnection("encrypted_test", null, false)
258+
259+
try {
260+
unencrypted.execSQL("SELECT * FROM sqlite_schema")
261+
throw IllegalStateException("Was able to read schema from encrypted database without supplying a key")
262+
} catch (_: SQLiteException) {
263+
// Expected
264+
}
265+
unencrypted.close()
266+
}
231267
}

0 commit comments

Comments
 (0)