Persist encrypted alert configuration
This commit is contained in:
+43
@@ -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))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user