Fix android tests (#2410)

This commit is contained in:
Rafał Borcz 2024-02-04 10:48:59 +01:00 committed by GitHub
parent fc91936884
commit e58a60410c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 17 deletions

2
.gitignore vendored
View File

@ -65,6 +65,8 @@ captures/
.idea/uiDesigner.xml
.idea/runConfigurations.xml
.idea/discord.xml
.idea/migrations.xml
.idea/androidTestResultsUserPreferences.xml
# Keystore files
*.jks

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectMigrations">
<option name="MigrateToGradleLocalJavaHome">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</component>
</project>

View File

@ -142,7 +142,9 @@ android {
packagingOptions {
resources {
excludes += ['META-INF/library_release.kotlin_module',
'META-INF/library-core_release.kotlin_module']
'META-INF/library-core_release.kotlin_module',
'META-INF/LICENSE.md',
'META-INF/LICENSE-notice.md']
}
}

View File

@ -14,34 +14,37 @@ import kotlin.test.assertFailsWith
@RunWith(AndroidJUnit4::class)
class ScramblerTest {
private val scrambler = Scrambler(ApplicationProvider.getApplicationContext())
@Test
fun encryptDecryptTest() {
assertEquals("TEST", decrypt(encrypt("TEST",
ApplicationProvider.getApplicationContext())))
assertEquals(
"TEST", scrambler.decrypt(scrambler.encrypt("TEST"))
)
}
@Test
fun emptyTextEncryptTest() {
assertFailsWith<ScramblerException> {
decrypt("")
scrambler.decrypt("")
}
assertFailsWith<ScramblerException> {
encrypt("", ApplicationProvider.getApplicationContext())
scrambler.encrypt("")
}
}
@Test
@SdkSuppress(minSdkVersion = 18)
fun emptyKeyStoreTest() {
val text = encrypt("test", ApplicationProvider.getApplicationContext())
val text = scrambler.encrypt("test")
val keyStore = KeyStore.getInstance("AndroidKeyStore")
keyStore.load(null)
keyStore.deleteEntry("wulkanowy_password")
assertFailsWith<ScramblerException> {
decrypt(text)
scrambler.decrypt(text)
}
}
}