diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2022-10-25 23:57:46 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2022-10-25 23:57:46 +0530 |
commit | bb960ccb76dcfe8b2bed6de1ada5cafc64d7b26b (patch) | |
tree | 9ef8fbfd4bcc008ca7a5d81ba5ee1a55c00fe5c6 /format-common-impl | |
parent | 0c939a2929e590d8a891237240ffc9f89f0c7405 (diff) |
refactor: move UriTotpFinderTest to `format-common-impl`
Diffstat (limited to 'format-common-impl')
-rw-r--r-- | format-common-impl/src/test/kotlin/app/passwordstore/util/totp/UriTotpFinderTest.kt | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/format-common-impl/src/test/kotlin/app/passwordstore/util/totp/UriTotpFinderTest.kt b/format-common-impl/src/test/kotlin/app/passwordstore/util/totp/UriTotpFinderTest.kt new file mode 100644 index 00000000..c62df0e7 --- /dev/null +++ b/format-common-impl/src/test/kotlin/app/passwordstore/util/totp/UriTotpFinderTest.kt @@ -0,0 +1,60 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +package app.passwordstore.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" + } +} |