aboutsummaryrefslogtreecommitdiff
path: root/format/common/src
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2024-05-28 15:11:50 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2024-05-28 15:11:50 +0530
commitc980c898de8417e16942741d469ebef8532b822a (patch)
treecc0639b9bbe45bb7ff89fe3a956c0619f3d943b2 /format/common/src
parentde6cdfee0e37aab03bfb91e5e90c3ec4bd740fe3 (diff)
chore: reformat with trailing commas changes
Diffstat (limited to 'format/common/src')
-rw-r--r--format/common/src/main/kotlin/app/passwordstore/data/passfile/PasswordEntry.kt9
-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
4 files changed, 19 insertions, 95 deletions
diff --git a/format/common/src/main/kotlin/app/passwordstore/data/passfile/PasswordEntry.kt b/format/common/src/main/kotlin/app/passwordstore/data/passfile/PasswordEntry.kt
index f4dcc2b7..cd152c9a 100644
--- a/format/common/src/main/kotlin/app/passwordstore/data/passfile/PasswordEntry.kt
+++ b/format/common/src/main/kotlin/app/passwordstore/data/passfile/PasswordEntry.kt
@@ -205,7 +205,7 @@ constructor(
millis / (THOUSAND_MILLIS * totpPeriod),
totpAlgorithm,
digits,
- issuer
+ issuer,
)
.mapBoth({ code -> Ok(Totp(code, remainingTime)) }, ::Err)
}
@@ -233,12 +233,7 @@ constructor(
"identity:",
)
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
- public val PASSWORD_FIELDS: Array<String> =
- arrayOf(
- "password:",
- "secret:",
- "pass:",
- )
+ public val PASSWORD_FIELDS: Array<String> = arrayOf("password:", "secret:", "pass:")
private const val THOUSAND_MILLIS = 1000L
}
}
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))
}