diff options
| author | Harsh Shandilya <me@msfjarvis.dev> | 2021-03-09 14:53:11 +0530 |
|---|---|---|
| committer | Harsh Shandilya <me@msfjarvis.dev> | 2021-03-18 11:40:30 +0530 |
| commit | 774fda83ac276a635e3402034b1eedbd10be916f (patch) | |
| tree | 57783a953fcd193d32f1e3dc8df26e07f03df328 /app/src/androidTest/java/dev/msfjarvis/aps/util | |
| parent | be31ae37f443982b377d027cd613f04d0926568d (diff) | |
| download | HardenedPass-774fda83ac276a635e3402034b1eedbd10be916f.tar.gz HardenedPass-774fda83ac276a635e3402034b1eedbd10be916f.zip | |
all: reformat with ktfmt
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/androidTest/java/dev/msfjarvis/aps/util')
3 files changed, 162 insertions, 151 deletions
diff --git a/app/src/androidTest/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt b/app/src/androidTest/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt index cac5d80d..83a6afde 100644 --- a/app/src/androidTest/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt +++ b/app/src/androidTest/java/dev/msfjarvis/aps/util/settings/MigrationsTest.kt @@ -19,102 +19,103 @@ import org.junit.Test class MigrationsTest { - private fun checkOldKeysAreRemoved(context: Context) = with(context.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)) + private fun checkOldKeysAreRemoved(context: Context) = + with(context.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() { - val context = Application.instance.applicationContext - context.sharedPrefs.edit { - clear() - 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(context) - checkOldKeysAreRemoved(context) - assertEquals( - context.sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL), - "ssh://msfjarvis@192.168.0.102:2200/mnt/disk3/pass-repo" - ) + @Test + fun verifySshWithCustomPortMigration() { + val context = Application.instance.applicationContext + context.sharedPrefs.edit { + clear() + 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(context) + checkOldKeysAreRemoved(context) + assertEquals( + context.sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL), + "ssh://msfjarvis@192.168.0.102:2200/mnt/disk3/pass-repo" + ) + } - @Test - fun verifySshWithDefaultPortMigration() { - val context = Application.instance.applicationContext - context.sharedPrefs.edit { - clear() - 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(context) - checkOldKeysAreRemoved(context) - assertEquals( - context.sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL), - "msfjarvis@192.168.0.102:/mnt/disk3/pass-repo" - ) + @Test + fun verifySshWithDefaultPortMigration() { + val context = Application.instance.applicationContext + context.sharedPrefs.edit { + clear() + 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(context) + checkOldKeysAreRemoved(context) + assertEquals( + context.sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL), + "msfjarvis@192.168.0.102:/mnt/disk3/pass-repo" + ) + } - @Test - fun verifyHttpsWithGitHubMigration() { - val context = Application.instance.applicationContext - context.sharedPrefs.edit { - clear() - 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(context) - checkOldKeysAreRemoved(context) - assertEquals( - context.sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL), - "https://github.com/Android-Password-Store/pass-test" - ) + @Test + fun verifyHttpsWithGitHubMigration() { + val context = Application.instance.applicationContext + context.sharedPrefs.edit { + clear() + 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(context) + checkOldKeysAreRemoved(context) + assertEquals( + context.sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL), + "https://github.com/Android-Password-Store/pass-test" + ) + } - @Test - fun verifyHiddenFoldersMigrationIfDisabled() { - val context = Application.instance.applicationContext - context.sharedPrefs.edit { clear() } - runMigrations(context) - assertEquals(true, context.sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, true)) - assertEquals(false, context.sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, false)) - } + @Test + fun verifyHiddenFoldersMigrationIfDisabled() { + val context = Application.instance.applicationContext + context.sharedPrefs.edit { clear() } + runMigrations(context) + assertEquals(true, context.sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, true)) + assertEquals(false, context.sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, false)) + } - @Test - fun verifyHiddenFoldersMigrationIfEnabled() { - val context = Application.instance.applicationContext - context.sharedPrefs.edit { - clear() - putBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, true) - } - runMigrations(context) - assertEquals(false, context.sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, false)) - assertEquals(true, context.sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, false)) + @Test + fun verifyHiddenFoldersMigrationIfEnabled() { + val context = Application.instance.applicationContext + context.sharedPrefs.edit { + clear() + putBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, true) } + runMigrations(context) + assertEquals(false, context.sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_FOLDERS, false)) + assertEquals(true, context.sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, false)) + } - @Test - fun verifyClearClipboardHistoryMigration() { - val context = Application.instance.applicationContext - context.sharedPrefs.edit { - clear() - putBoolean(PreferenceKeys.CLEAR_CLIPBOARD_20X, true) - } - runMigrations(context) - assertEquals(true, context.sharedPrefs.getBoolean(PreferenceKeys.CLEAR_CLIPBOARD_HISTORY, false)) - assertFalse(context.sharedPrefs.contains(PreferenceKeys.CLEAR_CLIPBOARD_20X)) + @Test + fun verifyClearClipboardHistoryMigration() { + val context = Application.instance.applicationContext + context.sharedPrefs.edit { + clear() + putBoolean(PreferenceKeys.CLEAR_CLIPBOARD_20X, true) } + runMigrations(context) + assertEquals(true, context.sharedPrefs.getBoolean(PreferenceKeys.CLEAR_CLIPBOARD_HISTORY, false)) + assertFalse(context.sharedPrefs.contains(PreferenceKeys.CLEAR_CLIPBOARD_20X)) + } } diff --git a/app/src/androidTest/java/dev/msfjarvis/aps/util/totp/UriTotpFinderTest.kt b/app/src/androidTest/java/dev/msfjarvis/aps/util/totp/UriTotpFinderTest.kt index 4ecc31d2..b89cf0ef 100644 --- a/app/src/androidTest/java/dev/msfjarvis/aps/util/totp/UriTotpFinderTest.kt +++ b/app/src/androidTest/java/dev/msfjarvis/aps/util/totp/UriTotpFinderTest.kt @@ -10,36 +10,40 @@ import org.junit.Test 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)) - } - - 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" - } + 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)) + } + + 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/androidTest/java/dev/msfjarvis/aps/util/viewmodel/StrictDomainRegexTest.kt b/app/src/androidTest/java/dev/msfjarvis/aps/util/viewmodel/StrictDomainRegexTest.kt index fc76deef..575c5aa7 100644 --- a/app/src/androidTest/java/dev/msfjarvis/aps/util/viewmodel/StrictDomainRegexTest.kt +++ b/app/src/androidTest/java/dev/msfjarvis/aps/util/viewmodel/StrictDomainRegexTest.kt @@ -10,40 +10,46 @@ import kotlin.test.assertTrue import org.junit.Test private infix fun String.matchedForDomain(domain: String) = - SearchableRepositoryViewModel.generateStrictDomainRegex(domain)?.containsMatchIn(this) == true + SearchableRepositoryViewModel.generateStrictDomainRegex(domain)?.containsMatchIn(this) == true 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")) - } + @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")) + } } |
