Files
openide/platform/external-process-auth-helper/test/externalProcessAuthHelper/SshPromptsTest.kt
Roman Shevchenko dffc787d4c [project] moving SSHUtil to a more appropriate module
GitOrigin-RevId: 11bb97575b52914743114e64cbecc327ec1ec402
2024-06-07 08:04:35 +00:00

39 lines
1.8 KiB
Kotlin
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.externalProcessAuthHelper
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import java.util.regex.Matcher
import java.util.regex.Pattern
class SshPromptsTest {
@Test
@Suppress("NonAsciiCharacters")
fun testPassphraseRegex() {
passphraseRegexShouldMatch("Enter passphrase for key 'С:\\test\\dir\\.ssh\\id.rsa':", "С:\\test\\dir\\.ssh\\id.rsa")
passphraseRegexShouldMatch("Enter passphrase for 'С:\\test\\dir\\.ssh\\id.rsa':", "С:\\test\\dir\\.ssh\\id.rsa")
passphraseRegexShouldMatch("Enter passphrase for С:\\test\\dir\\.ssh\\id.rsa:", "С:\\test\\dir\\.ssh\\id.rsa")
passphraseRegexShouldMatch("Enter passphrase for key С:\\test\\dir\\.ssh\\id.rsa:", "С:\\test\\dir\\.ssh\\id.rsa")
passphraseRegexShouldMatch("Enter passphrase for key '/home/test/rsa':", "/home/test/rsa")
passphraseRegexShouldMatch("Enter passphrase for key /home/test/rsa:", "/home/test/rsa")
passphraseRegexShouldMatch("Enter passphrase for '/home/test/rsa':", "/home/test/rsa")
}
@Test
fun testPasswordRegex() {
regexShouldMatch(SshPrompts.PASSWORD_PROMPT, "User1's password:", "User1") { SshPrompts.extractUsername(it) }
}
private fun passphraseRegexShouldMatch(input: String, expected: String) {
regexShouldMatch(SshPrompts.PASSPHRASE_PROMPT, input, expected) { SshPrompts.extractKeyPath(it) }
}
private fun regexShouldMatch(pattern: Pattern, input: String, expected: String, resultProvider: (Matcher) -> String) {
val matcher = pattern.matcher(input)
assertTrue(matcher.matches())
val result = resultProvider(matcher)
assertEquals(expected, result)
}
}