Persist encrypted alert configuration

This commit is contained in:
ajp_anton
2026-08-16 17:16:07 +00:00
parent ae409612b4
commit 720db4b7d3
5 changed files with 250 additions and 0 deletions
@@ -0,0 +1,43 @@
package se.ajpanton.notificationsmaster.alerts
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Test
import org.junit.runner.RunWith
import java.io.File
@RunWith(AndroidJUnit4::class)
class AlertConfigurationStoreTest {
private val context = InstrumentationRegistry.getInstrumentation().targetContext
private val configurationFile = File(context.filesDir, "alert-configuration.bin")
@After
fun removeStoredConfiguration() {
configurationFile.delete()
File(configurationFile.path + ".bak").delete()
File(configurationFile.path + ".new").delete()
}
@Test
fun encryptsAndReloadsConfiguration() {
val profile = AlertProfile("profile", "Sensitive profile", vibrationPattern = listOf(0, 120))
val configuration = AlertConfiguration(
profiles = listOf(profile),
appSettings = listOf(AlertAppSettings("chat.app", directAlertControl = true)),
rules = listOf(
AlertRule(
"rule", "chat.app", 0, setOf(AlertSource.NOTIFICATION_POST),
outcome = AlertOutcome.PLAY_PROFILE, profileId = profile.id,
),
),
)
AlertConfigurationStore(context).save(configuration)
assertEquals(configuration, AlertConfigurationStore(context).load())
assertFalse(configurationFile.readBytes().decodeToString().contains(profile.name))
}
}