diff --git a/plugins/git4idea/tests/git4idea/commit/signing/PinentryDataEncryptTest.kt b/plugins/git4idea/tests/git4idea/commit/signing/PinentryDataEncryptTest.kt index 386f754e88a4..8fdf90ed618c 100644 --- a/plugins/git4idea/tests/git4idea/commit/signing/PinentryDataEncryptTest.kt +++ b/plugins/git4idea/tests/git4idea/commit/signing/PinentryDataEncryptTest.kt @@ -9,7 +9,7 @@ import kotlin.random.Random class PinentryDataEncryptTest : UsefulTestCase() { fun `test encrypt and decrypt`() { - val password = PinentryTestUtil.generatePassword(Random.nextInt(2, 200)) + val password = PinentryTestUtil.generatePassword(Random.nextInt(4, 200)) val keyPair = CryptoUtils.generateKeyPair() val encryptedPassword = CryptoUtils.encrypt(password, keyPair.private) diff --git a/plugins/git4idea/tests/git4idea/commit/signing/PinentryExecutionTest.kt b/plugins/git4idea/tests/git4idea/commit/signing/PinentryExecutionTest.kt index 5e90a205721b..95aa9bb115b2 100644 --- a/plugins/git4idea/tests/git4idea/commit/signing/PinentryExecutionTest.kt +++ b/plugins/git4idea/tests/git4idea/commit/signing/PinentryExecutionTest.kt @@ -106,7 +106,7 @@ class PinentryExecutionTest : GitSingleRepoTest() { private fun requestPasswordAndAssert(paths: GpgAgentPaths) { PinentryService.getInstance(project).use { pinentryData -> - val keyPassword = PinentryTestUtil.generatePassword(Random.nextInt(2, 200)) + val keyPassword = PinentryTestUtil.generatePassword(Random.nextInt(4, 200)) setUiRequester { keyPassword } val output = requestPassword(paths, pinentryData) diff --git a/plugins/git4idea/tests/git4idea/commit/signing/PinentryTestUtil.kt b/plugins/git4idea/tests/git4idea/commit/signing/PinentryTestUtil.kt index 4fefa803736b..7b5f70692718 100644 --- a/plugins/git4idea/tests/git4idea/commit/signing/PinentryTestUtil.kt +++ b/plugins/git4idea/tests/git4idea/commit/signing/PinentryTestUtil.kt @@ -2,6 +2,7 @@ package git4idea.commit.signing import java.security.SecureRandom +import kotlin.math.max object PinentryTestUtil { private const val UPPERCASE_LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -14,7 +15,8 @@ object PinentryTestUtil { private val RANDOM = SecureRandom() fun generatePassword(length: Int): String { - val password = StringBuilder(length) + val passwordLength = max(length, 4) + val password = StringBuilder(passwordLength) //fill first 4 char password.append(UPPERCASE_LETTERS[RANDOM.nextInt(UPPERCASE_LETTERS.length)]) @@ -23,11 +25,11 @@ object PinentryTestUtil { password.append(SPECIAL_CHARACTERS[RANDOM.nextInt(SPECIAL_CHARACTERS.length)]) //fill last characters randomly - repeat(length - 4) { + repeat(passwordLength - 4) { password.append(ALL_CHARACTERS[RANDOM.nextInt(ALL_CHARACTERS.length)]) } - require(password.length == length) + require(password.length == passwordLength) return password.toString().shuffle() }