aboutsummaryrefslogtreecommitdiff
path: root/format/common/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'format/common/src/test')
-rw-r--r--format/common/src/test/kotlin/app/passwordstore/data/passfile/PasswordEntryTest.kt10
-rw-r--r--format/common/src/test/kotlin/app/passwordstore/util/totp/OtpTest.kt93
-rw-r--r--format/common/src/test/kotlin/app/passwordstore/util/totp/UriTotpFinderTest.kt2
3 files changed, 17 insertions, 88 deletions
diff --git a/format/common/src/test/kotlin/app/passwordstore/data/passfile/PasswordEntryTest.kt b/format/common/src/test/kotlin/app/passwordstore/data/passfile/PasswordEntryTest.kt
index 95fb3e62..ccac0b81 100644
--- a/format/common/src/test/kotlin/app/passwordstore/data/passfile/PasswordEntryTest.kt
+++ b/format/common/src/test/kotlin/app/passwordstore/data/passfile/PasswordEntryTest.kt
@@ -26,11 +26,7 @@ class PasswordEntryTest {
private val totpFinder = UriTotpFinder()
private fun makeEntry(content: String, clock: UserClock = fakeClock) =
- PasswordEntry(
- clock,
- totpFinder,
- content.encodeToByteArray(),
- )
+ PasswordEntry(clock, totpFinder, content.encodeToByteArray())
@Test
fun getPassword() {
@@ -62,7 +58,7 @@ class PasswordEntryTest {
assertEquals("blubb", makeEntry("password: foo\nblubb").extraContentString)
assertEquals(
"blubb\nusername: bar",
- makeEntry("blubb\npassword: foo\nusername: bar").extraContentString
+ makeEntry("blubb\npassword: foo\nusername: bar").extraContentString,
)
assertEquals("", makeEntry("\n").extraContentString)
assertEquals("", makeEntry("").extraContentString)
@@ -107,7 +103,7 @@ class PasswordEntryTest {
assertEquals("username", makeEntry("\n$field username").username)
assertEquals(
"username",
- makeEntry("\n${field.uppercase(Locale.getDefault())} username").username
+ makeEntry("\n${field.uppercase(Locale.getDefault())} username").username,
)
}
assertEquals("username", makeEntry("secret\nextra\nlogin: username\ncontent\n").username)
diff --git a/format/common/src/test/kotlin/app/passwordstore/util/totp/OtpTest.kt b/format/common/src/test/kotlin/app/passwordstore/util/totp/OtpTest.kt
index 54ac492d..6f94bda5 100644
--- a/format/common/src/test/kotlin/app/passwordstore/util/totp/OtpTest.kt
+++ b/format/common/src/test/kotlin/app/passwordstore/util/totp/OtpTest.kt
@@ -25,103 +25,36 @@ class OtpTest {
@Test
fun otpGeneration6Digits() {
- assertEquals(
- "953550",
- generateOtp(
- counter = 1593333298159 / (1000 * 30),
- )
- )
- assertEquals(
- "275379",
- generateOtp(
- counter = 1593333571918 / (1000 * 30),
- )
- )
- assertEquals(
- "867507",
- generateOtp(
- counter = 1593333600517 / (1000 * 57),
- )
- )
+ assertEquals("953550", generateOtp(counter = 1593333298159 / (1000 * 30)))
+ assertEquals("275379", generateOtp(counter = 1593333571918 / (1000 * 30)))
+ assertEquals("867507", generateOtp(counter = 1593333600517 / (1000 * 57)))
}
@Test
fun otpGeneration10Digits() {
- assertEquals(
- "0740900914",
- generateOtp(
- counter = 1593333655044 / (1000 * 30),
- digits = "10",
- )
- )
- assertEquals(
- "0070632029",
- generateOtp(
- counter = 1593333691405 / (1000 * 30),
- digits = "10",
- )
- )
- assertEquals(
- "1017265882",
- generateOtp(
- counter = 1593333728893 / (1000 * 83),
- digits = "10",
- )
- )
+ assertEquals("0740900914", generateOtp(counter = 1593333655044 / (1000 * 30), digits = "10"))
+ assertEquals("0070632029", generateOtp(counter = 1593333691405 / (1000 * 30), digits = "10"))
+ assertEquals("1017265882", generateOtp(counter = 1593333728893 / (1000 * 83), digits = "10"))
}
@Test
fun otpGenerationIllegalInput() {
- assertNull(
- generateOtp(
- counter = 10000,
- algorithm = "SHA0",
- digits = "10",
- )
- )
- assertNull(
- generateOtp(
- counter = 10000,
- digits = "a",
- )
- )
- assertNull(
- generateOtp(
- counter = 10000,
- algorithm = "SHA1",
- digits = "5",
- )
- )
- assertNull(
- generateOtp(
- counter = 10000,
- digits = "11",
- )
- )
- assertNull(
- generateOtp(
- counter = 10000,
- secret = "JBSWY3DPEHPK3PXPAAAAB",
- digits = "6",
- )
- )
+ assertNull(generateOtp(counter = 10000, algorithm = "SHA0", digits = "10"))
+ assertNull(generateOtp(counter = 10000, digits = "a"))
+ assertNull(generateOtp(counter = 10000, algorithm = "SHA1", digits = "5"))
+ assertNull(generateOtp(counter = 10000, digits = "11"))
+ assertNull(generateOtp(counter = 10000, secret = "JBSWY3DPEHPK3PXPAAAAB", digits = "6"))
}
@Test
fun otpGenerationUnusualSecrets() {
assertEquals(
"127764",
- generateOtp(
- counter = 1593367111963 / (1000 * 30),
- secret = "JBSWY3DPEHPK3PXPAAAAAAAA",
- )
+ generateOtp(counter = 1593367111963 / (1000 * 30), secret = "JBSWY3DPEHPK3PXPAAAAAAAA"),
)
assertEquals(
"047515",
- generateOtp(
- counter = 1593367171420 / (1000 * 30),
- secret = "JBSWY3DPEHPK3PXPAAAAA",
- )
+ generateOtp(counter = 1593367171420 / (1000 * 30), secret = "JBSWY3DPEHPK3PXPAAAAA"),
)
}
diff --git a/format/common/src/test/kotlin/app/passwordstore/util/totp/UriTotpFinderTest.kt b/format/common/src/test/kotlin/app/passwordstore/util/totp/UriTotpFinderTest.kt
index e462c490..16d9900c 100644
--- a/format/common/src/test/kotlin/app/passwordstore/util/totp/UriTotpFinderTest.kt
+++ b/format/common/src/test/kotlin/app/passwordstore/util/totp/UriTotpFinderTest.kt
@@ -17,7 +17,7 @@ class UriTotpFinderTest {
assertEquals("HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ", totpFinder.findSecret(TOTP_URI))
assertEquals(
"HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ",
- totpFinder.findSecret("name\npassword\ntotp: HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ")
+ totpFinder.findSecret("name\npassword\ntotp: HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ"),
)
assertEquals("HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ", totpFinder.findSecret(PASS_FILE_CONTENT))
}