Misc cleanups (#1891)
This commit is contained in:
parent
07a83a33b8
commit
c555609f16
12 changed files with 53 additions and 44 deletions
|
@ -12,28 +12,28 @@ import kotlin.test.assertTrue
|
|||
class GpgIdentifierTest {
|
||||
|
||||
@Test
|
||||
fun `parses hexadecimal key id without leading 0x`() {
|
||||
fun parseHexKeyIdWithout0xPrefix() {
|
||||
val identifier = GpgIdentifier.fromString("79E8208280490C77")
|
||||
assertNotNull(identifier)
|
||||
assertTrue { identifier is GpgIdentifier.KeyId }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `parses hexadecimal key id`() {
|
||||
fun parseHexKeyId() {
|
||||
val identifier = GpgIdentifier.fromString("0x79E8208280490C77")
|
||||
assertNotNull(identifier)
|
||||
assertTrue { identifier is GpgIdentifier.KeyId }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `parses email as user id`() {
|
||||
fun parseValidEmail() {
|
||||
val identifier = GpgIdentifier.fromString("john.doe@example.org")
|
||||
assertNotNull(identifier)
|
||||
assertTrue { identifier is GpgIdentifier.UserId }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `parses user@host without TLD`() {
|
||||
fun parseEmailWithoutTLD() {
|
||||
val identifier = GpgIdentifier.fromString("john.doe@example")
|
||||
assertNotNull(identifier)
|
||||
assertTrue { identifier is GpgIdentifier.UserId }
|
||||
|
|
|
@ -17,7 +17,10 @@ afterEvaluate {
|
|||
}
|
||||
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions { jvmTarget = JavaVersion.VERSION_11.toString() }
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_11.toString()
|
||||
freeCompilerArgs = freeCompilerArgs + "-Xsam-conversions=class"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,10 @@ afterEvaluate {
|
|||
}
|
||||
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions { jvmTarget = JavaVersion.VERSION_11.toString() }
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_11.toString()
|
||||
freeCompilerArgs = freeCompilerArgs + "-Xsam-conversions=class"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,10 @@ afterEvaluate {
|
|||
}
|
||||
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions { jvmTarget = JavaVersion.VERSION_11.toString() }
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_11.toString()
|
||||
freeCompilerArgs = freeCompilerArgs + "-Xsam-conversions=class"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,15 +22,15 @@ public object KeyDeletionFailedException : KeyManagerException("Couldn't delete
|
|||
public object InvalidKeyException :
|
||||
KeyManagerException("Given key cannot be parsed as a known key type")
|
||||
|
||||
/** No key matching [keyId] could be found. */
|
||||
/** No key matching `keyId` could be found. */
|
||||
public class KeyNotFoundException(keyId: String) :
|
||||
KeyManagerException("No key found with id: $keyId")
|
||||
|
||||
/** Attempting to add another key for [keyId] without requesting a replace. */
|
||||
/** Attempting to add another key for `keyId` without requesting a replace. */
|
||||
public class KeyAlreadyExistsException(keyId: String) :
|
||||
KeyManagerException("Pre-existing key was found for $keyId")
|
||||
|
||||
/** Sealed exception types for [CryptoHandler]. */
|
||||
/** Sealed exception types for [dev.msfjarvis.aps.crypto.CryptoHandler]. */
|
||||
public sealed class CryptoHandlerException(message: String? = null, cause: Throwable? = null) :
|
||||
CryptoException(message, cause)
|
||||
|
||||
|
|
|
@ -12,28 +12,28 @@ import kotlin.test.assertTrue
|
|||
class GpgIdentifierTest {
|
||||
|
||||
@Test
|
||||
fun `parses hexadecimal key id without leading 0x`() {
|
||||
fun parseHexKeyIdWithout0xPrefix() {
|
||||
val identifier = GpgIdentifier.fromString("79E8208280490C77")
|
||||
assertNotNull(identifier)
|
||||
assertTrue { identifier is GpgIdentifier.KeyId }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `parses hexadecimal key id`() {
|
||||
fun parseHexKeyId() {
|
||||
val identifier = GpgIdentifier.fromString("0x79E8208280490C77")
|
||||
assertNotNull(identifier)
|
||||
assertTrue { identifier is GpgIdentifier.KeyId }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `parses email as user id`() {
|
||||
fun parseValidEmail() {
|
||||
val identifier = GpgIdentifier.fromString("john.doe@example.org")
|
||||
assertNotNull(identifier)
|
||||
assertTrue { identifier is GpgIdentifier.UserId }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `parses user@host without TLD`() {
|
||||
fun parseEmailWithoutTLD() {
|
||||
val identifier = GpgIdentifier.fromString("john.doe@example")
|
||||
assertNotNull(identifier)
|
||||
assertTrue { identifier is GpgIdentifier.UserId }
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing
|
|||
|
||||
class KeyUtilsTest {
|
||||
@Test
|
||||
fun `parse GPG key with multiple identities`() {
|
||||
fun parseKeyWithMultipleIdentities() {
|
||||
val key = PGPKey(getArmoredPrivateKeyWithMultipleIdentities())
|
||||
val keyring = tryParseKeyring(key)
|
||||
assertNotNull(keyring)
|
||||
|
|
|
@ -51,7 +51,7 @@ class PGPKeyManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testAddingKey() =
|
||||
fun addKey() =
|
||||
scope.runTest {
|
||||
// Check if the key id returned is correct
|
||||
val keyId = keyManager.getKeyId(keyManager.addKey(key).unwrap())
|
||||
|
@ -66,7 +66,7 @@ class PGPKeyManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testAddingKeyWithoutReplaceFlag() =
|
||||
fun addKeyWithoutReplaceFlag() =
|
||||
scope.runTest {
|
||||
// Check adding the keys twice
|
||||
keyManager.addKey(key, false).unwrap()
|
||||
|
@ -76,7 +76,7 @@ class PGPKeyManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testAddingKeyWithReplaceFlag() =
|
||||
fun addKeyWithReplaceFlag() =
|
||||
scope.runTest {
|
||||
// Check adding the keys twice
|
||||
keyManager.addKey(key, true).unwrap()
|
||||
|
@ -86,7 +86,7 @@ class PGPKeyManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testRemovingKey() =
|
||||
fun removeKey() =
|
||||
scope.runTest {
|
||||
// Add key using KeyManager
|
||||
keyManager.addKey(key).unwrap()
|
||||
|
@ -101,7 +101,7 @@ class PGPKeyManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testGetExistingKeyById() =
|
||||
fun getKeyById() =
|
||||
scope.runTest {
|
||||
// Add key using KeyManager
|
||||
keyManager.addKey(key).unwrap()
|
||||
|
@ -116,7 +116,7 @@ class PGPKeyManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testGetExistingKeyByFullUserId() =
|
||||
fun getKeyByFullUserId() =
|
||||
scope.runTest {
|
||||
keyManager.addKey(key).unwrap()
|
||||
|
||||
|
@ -126,7 +126,7 @@ class PGPKeyManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testGetExistingKeyByEmailUserId() =
|
||||
fun getKeyByEmailUserId() =
|
||||
scope.runTest {
|
||||
keyManager.addKey(key).unwrap()
|
||||
|
||||
|
@ -136,7 +136,7 @@ class PGPKeyManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testGetNonExistentKey() =
|
||||
fun getNonExistentKey() =
|
||||
scope.runTest {
|
||||
// Add key using KeyManager
|
||||
keyManager.addKey(key).unwrap()
|
||||
|
@ -150,7 +150,7 @@ class PGPKeyManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testFindKeysWithoutAdding() =
|
||||
fun findNonExistentKey() =
|
||||
scope.runTest {
|
||||
// Check returned key
|
||||
val error = keyManager.getKeyById(KeyId(0x08edf7567183ce44)).unwrapError()
|
||||
|
@ -159,7 +159,7 @@ class PGPKeyManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testGettingAllKeys() =
|
||||
fun getAllKeys() =
|
||||
scope.runTest {
|
||||
// TODO: Should we check for more than 1 keys?
|
||||
// Check if KeyManager returns no key
|
||||
|
@ -175,7 +175,7 @@ class PGPKeyManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testGettingMultipleIdentityKeyWithBothUserIDs() {
|
||||
fun getMultipleIdentityKeyWithAllIdentities() {
|
||||
scope.runTest {
|
||||
val key = PGPKey(getArmoredPrivateKeyWithMultipleIdentities())
|
||||
keyManager.addKey(key).unwrap()
|
||||
|
|
|
@ -34,7 +34,7 @@ class PasswordEntryTest {
|
|||
)
|
||||
|
||||
@Test
|
||||
fun testGetPassword() {
|
||||
fun getPassword() {
|
||||
assertEquals("fooooo", makeEntry("fooooo\nbla\n").password)
|
||||
assertEquals("fooooo", makeEntry("fooooo\nbla").password)
|
||||
assertEquals("fooooo", makeEntry("fooooo\n").password)
|
||||
|
@ -52,7 +52,7 @@ class PasswordEntryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testGetExtraContent() {
|
||||
fun getExtraContent() {
|
||||
assertEquals("bla\n", makeEntry("fooooo\nbla\n").extraContentString)
|
||||
assertEquals("bla", makeEntry("fooooo\nbla").extraContentString)
|
||||
assertEquals("", makeEntry("fooooo\n").extraContentString)
|
||||
|
@ -103,7 +103,7 @@ class PasswordEntryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testGetUsername() {
|
||||
fun getUsername() {
|
||||
for (field in PasswordEntry.USERNAME_FIELDS) {
|
||||
assertEquals("username", makeEntry("\n$field username").username)
|
||||
assertEquals(
|
||||
|
@ -123,7 +123,7 @@ class PasswordEntryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testHasUsername() {
|
||||
fun hasUsername() {
|
||||
assertNotNull(makeEntry("secret\nextra\nlogin: username\ncontent\n").username)
|
||||
assertNull(makeEntry("secret\nextra\ncontent\n").username)
|
||||
assertNull(makeEntry("secret\nlogin failed\n").username)
|
||||
|
@ -132,7 +132,7 @@ class PasswordEntryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testGeneratesOtpFromTotpUri() = runTest {
|
||||
fun generatesOtpFromTotpUri() = runTest {
|
||||
val entry = makeEntry("secret\nextra\n$TOTP_URI")
|
||||
assertTrue(entry.hasTotp())
|
||||
entry.totp.test {
|
||||
|
@ -149,7 +149,7 @@ class PasswordEntryTest {
|
|||
* blocked https://msfjarvis.dev/aps/issue/1550.
|
||||
*/
|
||||
@Test
|
||||
fun testGeneratedOtpHasCorrectRemainingTime() = runTest {
|
||||
fun generatedOtpHasCorrectRemainingTime() = runTest {
|
||||
val entry = makeEntry("secret\nextra\n$TOTP_URI", TestUserClock.withAddedSeconds(5))
|
||||
assertTrue(entry.hasTotp())
|
||||
entry.totp.test {
|
||||
|
@ -161,7 +161,7 @@ class PasswordEntryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testGeneratesOtpWithOnlyUriInFile() = runTest {
|
||||
fun generatesOtpWithOnlyUriInFile() = runTest {
|
||||
val entry = makeEntry(TOTP_URI)
|
||||
assertNull(entry.password)
|
||||
entry.totp.test {
|
||||
|
@ -173,7 +173,7 @@ class PasswordEntryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testOnlyLooksForUriInFirstLine() {
|
||||
fun onlyLooksForUriInFirstLine() {
|
||||
val entry = makeEntry("id:\n$TOTP_URI")
|
||||
assertNotNull(entry.password)
|
||||
assertTrue(entry.hasTotp())
|
||||
|
|
|
@ -24,7 +24,7 @@ class OtpTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testOtpGeneration6Digits() {
|
||||
fun otpGeneration6Digits() {
|
||||
assertEquals(
|
||||
"953550",
|
||||
generateOtp(
|
||||
|
@ -46,7 +46,7 @@ class OtpTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testOtpGeneration10Digits() {
|
||||
fun otpGeneration10Digits() {
|
||||
assertEquals(
|
||||
"0740900914",
|
||||
generateOtp(
|
||||
|
@ -71,7 +71,7 @@ class OtpTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testOtpGenerationIllegalInput() {
|
||||
fun otpGenerationIllegalInput() {
|
||||
assertNull(
|
||||
generateOtp(
|
||||
counter = 10000,
|
||||
|
@ -108,7 +108,7 @@ class OtpTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testOtpGenerationUnusualSecrets() {
|
||||
fun otpGenerationUnusualSecrets() {
|
||||
assertEquals(
|
||||
"127764",
|
||||
generateOtp(
|
||||
|
@ -126,7 +126,7 @@ class OtpTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testOtpGenerationUnpaddedSecrets() {
|
||||
fun otpGenerationUnpaddedSecrets() {
|
||||
// Secret was generated with `echo 'string with some padding needed' | base32`
|
||||
// We don't care for the resultant OTP's actual value, we just want both the padded and
|
||||
// unpadded variant to generate the same one.
|
||||
|
|
|
@ -15,7 +15,7 @@ class DicewarePassphraseGeneratorTest {
|
|||
|
||||
private val intGenerator = RandomIntGenerator { it.random(random) }
|
||||
@Test
|
||||
fun generate_passphrase() {
|
||||
fun generatePassphrase() {
|
||||
val die = Die(6, intGenerator)
|
||||
|
||||
val generator =
|
||||
|
|
|
@ -17,19 +17,19 @@ class DieTest {
|
|||
private val intGenerator = RandomIntGenerator { it.random(random) }
|
||||
|
||||
@Test
|
||||
fun test_one_roll() {
|
||||
fun oneRoll() {
|
||||
val die = Die(6, intGenerator)
|
||||
assertEquals(5, die.roll())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test_multiple_rolls() {
|
||||
fun multipleRolls() {
|
||||
val die = Die(6, intGenerator)
|
||||
assertEquals(526242, die.rollMultiple(6))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test_consecutive_rolls() {
|
||||
fun consecutiveRolls() {
|
||||
val die = Die(6, intGenerator)
|
||||
assertEquals(5, die.roll())
|
||||
assertEquals(2, die.roll())
|
||||
|
@ -40,7 +40,7 @@ class DieTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun test_100_sides() {
|
||||
fun hundredSides() {
|
||||
val die = Die(100, intGenerator)
|
||||
assertEquals(67, die.roll())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue