diff options
Diffstat (limited to 'app/src/test/java/dev')
4 files changed, 0 insertions, 348 deletions
diff --git a/app/src/test/java/dev/msfjarvis/aps/util/crypto/GpgIdentifierTest.kt b/app/src/test/java/dev/msfjarvis/aps/util/crypto/GpgIdentifierTest.kt deleted file mode 100644 index 8c3272ef..00000000 --- a/app/src/test/java/dev/msfjarvis/aps/util/crypto/GpgIdentifierTest.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. - * SPDX-License-Identifier: GPL-3.0-only - */ - -package dev.msfjarvis.aps.util.crypto - -import kotlin.test.Test -import kotlin.test.assertNotNull -import kotlin.test.assertTrue - -class GpgIdentifierTest { - - @Test - fun parseHexKeyIdWithout0xPrefix() { - val identifier = GpgIdentifier.fromString("79E8208280490C77") - assertNotNull(identifier) - assertTrue { identifier is GpgIdentifier.KeyId } - } - - @Test - fun parseHexKeyId() { - val identifier = GpgIdentifier.fromString("0x79E8208280490C77") - assertNotNull(identifier) - assertTrue { identifier is GpgIdentifier.KeyId } - } - - @Test - fun parseValidEmail() { - val identifier = GpgIdentifier.fromString("john.doe@example.org") - assertNotNull(identifier) - assertTrue { identifier is GpgIdentifier.UserId } - } - - @Test - fun parseEmailWithoutTLD() { - val identifier = GpgIdentifier.fromString("john.doe@example") - assertNotNull(identifier) - assertTrue { identifier is GpgIdentifier.UserId } - } -} diff --git a/app/src/test/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt b/app/src/test/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt deleted file mode 100644 index cf89d81e..00000000 --- a/app/src/test/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. - * SPDX-License-Identifier: GPL-3.0-only - */ -@file:Suppress("DEPRECATION") - -package dev.msfjarvis.aps.util.settings - -import android.content.Context -import android.content.SharedPreferences -import androidx.core.content.edit -import com.github.ivanshafran.sharedpreferencesmock.SPMockBuilder -import dev.msfjarvis.aps.util.extensions.getString -import kotlin.test.BeforeTest -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertFalse -import kotlin.test.assertNull -import kotlin.test.assertTrue -import org.junit.Rule -import org.junit.rules.TemporaryFolder - -class MigrationsTest { - - @get:Rule val tempFolder = TemporaryFolder() - - private lateinit var context: Context - private lateinit var filesDir: String - private lateinit var sharedPrefs: SharedPreferences - private lateinit var encryptedSharedPreferences: SharedPreferences - private lateinit var proxySharedPreferences: SharedPreferences - - @BeforeTest - fun setup() { - context = SPMockBuilder().createContext() - filesDir = tempFolder.root.path - sharedPrefs = SPMockBuilder().createSharedPreferences() - encryptedSharedPreferences = SPMockBuilder().createSharedPreferences() - proxySharedPreferences = SPMockBuilder().createSharedPreferences() - } - - private fun checkOldKeysAreRemoved() = - with(sharedPrefs) { - assertNull(getString(PreferenceKeys.GIT_REMOTE_PORT)) - assertNull(getString(PreferenceKeys.GIT_REMOTE_USERNAME)) - assertNull(getString(PreferenceKeys.GIT_REMOTE_SERVER)) - assertNull(getString(PreferenceKeys.GIT_REMOTE_LOCATION)) - assertNull(getString(PreferenceKeys.GIT_REMOTE_PROTOCOL)) - } - - @Test - fun verifySshWithCustomPortMigration() { - sharedPrefs.edit { - putString(PreferenceKeys.GIT_REMOTE_PORT, "2200") - putString(PreferenceKeys.GIT_REMOTE_USERNAME, "msfjarvis") - putString(PreferenceKeys.GIT_REMOTE_LOCATION, "/mnt/disk3/pass-repo") - putString(PreferenceKeys.GIT_REMOTE_SERVER, "192.168.0.102") - putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, Protocol.Ssh.pref) - putString(PreferenceKeys.GIT_REMOTE_AUTH, AuthMode.Password.pref) - } - runMigrations( - filesDir, - sharedPrefs, - GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir) - ) - checkOldKeysAreRemoved() - assertEquals( - sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL), - "ssh://msfjarvis@192.168.0.102:2200/mnt/disk3/pass-repo" - ) - } - - @Test - fun verifySshWithDefaultPortMigration() { - sharedPrefs.edit { - putString(PreferenceKeys.GIT_REMOTE_USERNAME, "msfjarvis") - putString(PreferenceKeys.GIT_REMOTE_LOCATION, "/mnt/disk3/pass-repo") - putString(PreferenceKeys.GIT_REMOTE_SERVER, "192.168.0.102") - putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, Protocol.Ssh.pref) - putString(PreferenceKeys.GIT_REMOTE_AUTH, AuthMode.SshKey.pref) - } - runMigrations( - filesDir, - sharedPrefs, - GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir) - ) - checkOldKeysAreRemoved() - assertEquals( - sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL), - "msfjarvis@192.168.0.102:/mnt/disk3/pass-repo" - ) - } - - @Test - fun verifyHttpsWithGitHubMigration() { - sharedPrefs.edit { - putString(PreferenceKeys.GIT_REMOTE_USERNAME, "msfjarvis") - putString(PreferenceKeys.GIT_REMOTE_LOCATION, "Android-Password-Store/pass-test") - putString(PreferenceKeys.GIT_REMOTE_SERVER, "github.com") - putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, Protocol.Https.pref) - putString(PreferenceKeys.GIT_REMOTE_AUTH, AuthMode.None.pref) - } - runMigrations( - filesDir, - sharedPrefs, - GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir) - ) - checkOldKeysAreRemoved() - assertEquals( - sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL), - "https://github.com/Android-Password-Store/pass-test" - ) - } - - @Test - fun verifyHiddenFoldersMigrationIfDisabled() { - runMigrations( - filesDir, - sharedPrefs, - GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir) - ) - assertEquals(true, sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, true)) - assertEquals(false, sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, false)) - } - - @Test - fun verifyHiddenFoldersMigrationIfEnabled() { - sharedPrefs.edit { putBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, true) } - runMigrations( - filesDir, - sharedPrefs, - GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir) - ) - assertEquals(false, sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, false)) - assertEquals(true, sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, false)) - } - - @Test - fun verifyClearClipboardHistoryMigration() { - sharedPrefs.edit { putBoolean(PreferenceKeys.CLEAR_CLIPBOARD_20X, true) } - runMigrations( - filesDir, - sharedPrefs, - GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir) - ) - assertEquals(true, sharedPrefs.getBoolean(PreferenceKeys.CLEAR_CLIPBOARD_HISTORY, false)) - assertFalse(sharedPrefs.contains(PreferenceKeys.CLEAR_CLIPBOARD_20X)) - } - - @Test - fun verifyClassicPasswordGeneratorMigration() { - sharedPrefs.edit { putString(PreferenceKeys.PREF_KEY_PWGEN_TYPE, "classic") } - runMigrations( - filesDir, - sharedPrefs, - GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir), - ) - assertEquals("classic", sharedPrefs.getString(PreferenceKeys.PREF_KEY_PWGEN_TYPE)) - } - - @Test - fun verifyXkPasswdPasswordGeneratorMigration() { - sharedPrefs.edit { putString(PreferenceKeys.PREF_KEY_PWGEN_TYPE, "xkpasswd") } - runMigrations( - filesDir, - sharedPrefs, - GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir), - ) - assertEquals("diceware", sharedPrefs.getString(PreferenceKeys.PREF_KEY_PWGEN_TYPE)) - } - - @Test - fun verifyExternalStorageMigration() { - sharedPrefs.edit { - putBoolean(PreferenceKeys.GIT_EXTERNAL, true) - putString(PreferenceKeys.GIT_EXTERNAL_REPO, "/sdcard/") - } - runMigrations( - filesDir, - sharedPrefs, - GitSettings(sharedPrefs, encryptedSharedPreferences, proxySharedPreferences, filesDir), - ) - assertFalse { sharedPrefs.contains(PreferenceKeys.GIT_EXTERNAL) } - assertFalse { sharedPrefs.contains(PreferenceKeys.GIT_EXTERNAL_REPO) } - assertTrue { sharedPrefs.getBoolean(PreferenceKeys.GIT_EXTERNAL_MIGRATED, false) } - } -} diff --git a/app/src/test/java/dev/msfjarvis/aps/util/totp/UriTotpFinderTest.kt b/app/src/test/java/dev/msfjarvis/aps/util/totp/UriTotpFinderTest.kt deleted file mode 100644 index 8d1d5915..00000000 --- a/app/src/test/java/dev/msfjarvis/aps/util/totp/UriTotpFinderTest.kt +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. - * SPDX-License-Identifier: GPL-3.0-only - */ - -package dev.msfjarvis.aps.util.totp - -import kotlin.test.Test -import kotlin.test.assertEquals -import org.junit.runner.RunWith -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [23]) -class UriTotpFinderTest { - - private val totpFinder = UriTotpFinder() - - @Test - fun findSecret() { - assertEquals("HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ", totpFinder.findSecret(TOTP_URI)) - assertEquals( - "HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ", - totpFinder.findSecret("name\npassword\ntotp: HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ") - ) - assertEquals("HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ", totpFinder.findSecret(PASS_FILE_CONTENT)) - } - - @Test - fun findDigits() { - assertEquals("12", totpFinder.findDigits(TOTP_URI)) - assertEquals("12", totpFinder.findDigits(PASS_FILE_CONTENT)) - } - - @Test - fun findPeriod() { - assertEquals(25, totpFinder.findPeriod(TOTP_URI)) - assertEquals(25, totpFinder.findPeriod(PASS_FILE_CONTENT)) - } - - @Test - fun findAlgorithm() { - assertEquals("SHA256", totpFinder.findAlgorithm(TOTP_URI)) - assertEquals("SHA256", totpFinder.findAlgorithm(PASS_FILE_CONTENT)) - } - - @Test - fun findIssuer() { - assertEquals("ACME Co", totpFinder.findIssuer(TOTP_URI)) - assertEquals("ACME Co", totpFinder.findIssuer(PASS_FILE_CONTENT)) - } - - companion object { - - const val TOTP_URI = - "otpauth://totp/ACME%20Co:john@example.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=SHA256&digits=12&period=25" - const val PASS_FILE_CONTENT = "password\n$TOTP_URI" - } -} diff --git a/app/src/test/java/dev/msfjarvis/aps/util/viewmodel/StrictDomainRegexTest.kt b/app/src/test/java/dev/msfjarvis/aps/util/viewmodel/StrictDomainRegexTest.kt deleted file mode 100644 index ea58460d..00000000 --- a/app/src/test/java/dev/msfjarvis/aps/util/viewmodel/StrictDomainRegexTest.kt +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. - * SPDX-License-Identifier: GPL-3.0-only - */ -package dev.msfjarvis.aps.util.viewmodel - -import kotlin.test.Test -import kotlin.test.assertFalse -import kotlin.test.assertNull -import kotlin.test.assertTrue -import org.junit.runner.RunWith -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config - -private infix fun String.matchedForDomain(domain: String) = - SearchableRepositoryViewModel.generateStrictDomainRegex(domain)?.containsMatchIn(this) == true - -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [23]) -class StrictDomainRegexTest { - - @Test - fun acceptsLiteralDomain() { - assertTrue("work/example.org/john.doe@example.org.gpg" matchedForDomain "example.org") - assertTrue("example.org/john.doe@example.org.gpg" matchedForDomain "example.org") - assertTrue("example.org.gpg" matchedForDomain "example.org") - } - - @Test - fun acceptsSubdomains() { - assertTrue("work/www.example.org/john.doe@example.org.gpg" matchedForDomain "example.org") - assertTrue("www2.example.org/john.doe@example.org.gpg" matchedForDomain "example.org") - assertTrue("www.login.example.org.gpg" matchedForDomain "example.org") - } - - @Test - fun rejectsPhishingAttempts() { - assertFalse("example.org.gpg" matchedForDomain "xample.org") - assertFalse("login.example.org.gpg" matchedForDomain "xample.org") - assertFalse("example.org/john.doe@exmple.org.gpg" matchedForDomain "xample.org") - assertFalse("example.org.gpg" matchedForDomain "e/xample.org") - } - - @Test - fun rejectNonGpgComponentMatches() { - assertFalse("work/example.org" matchedForDomain "example.org") - } - - @Test - fun rejectsEmailAddresses() { - assertFalse("work/notexample.org/john.doe@example.org.gpg" matchedForDomain "example.org") - assertFalse("work/notexample.org/john.doe@www.example.org.gpg" matchedForDomain "example.org") - assertFalse("work/john.doe@www.example.org/foo.org" matchedForDomain "example.org") - } - - @Test - fun rejectsPathSeparators() { - assertNull(SearchableRepositoryViewModel.generateStrictDomainRegex("ex/ample.org")) - } -} |