mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
vcs: ensure min pinentry password length in tests
(cherry picked from commit 60e4b656f84c29abd8074d7b9f232167af8d2a9f) IJ-CR-149656 GitOrigin-RevId: a4d567960fc50e2282b3cf9d158da8d1afb4b284
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ed58651022
commit
60e0fff2fd
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user