Skip to content

Commit a416662

Browse files
authored
Fix windows credential_process containing quotes (#3330)
1 parent 218787c commit a416662

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Fix `credential_process` retrieval when command contains quoted arguments on Windows (#3322)"
4+
}

jetbrains-core/src/software/aws/toolkits/jetbrains/core/credentials/ToolkitCredentialProcessProvider.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.MapperFeature
99
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
1010
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
1111
import com.fasterxml.jackson.module.kotlin.readValue
12+
import com.intellij.execution.configurations.CommandLineTokenizer
1213
import com.intellij.execution.configurations.GeneralCommandLine
1314
import com.intellij.execution.process.ProcessOutput
1415
import com.intellij.execution.util.ExecUtil
@@ -24,6 +25,7 @@ import software.amazon.awssdk.utils.cache.CachedSupplier
2425
import software.amazon.awssdk.utils.cache.RefreshResult
2526
import software.aws.toolkits.resources.message
2627
import java.time.Instant
28+
import java.util.Enumeration
2729

2830
/**
2931
* Similar to the SDKs ProcessCredentialsProvider, but ties in the env var system of the IDE such as getting $PATH
@@ -39,7 +41,8 @@ class ToolkitCredentialProcessProvider internal constructor(
3941
}
4042
private val cmd by lazy {
4143
if (SystemInfo.isWindows) {
42-
GeneralCommandLine("cmd", "/C", command)
44+
@Suppress("UNCHECKED_CAST")
45+
GeneralCommandLine("cmd", "/C", *(CommandLineTokenizer(command) as Enumeration<String>).toList().toTypedArray())
4346
} else {
4447
GeneralCommandLine("sh", "-c", command)
4548
}

jetbrains-core/tst/software/aws/toolkits/jetbrains/core/credentials/ToolkitCredentialProcessProviderTest.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,34 @@ class ToolkitCredentialProcessProviderTest {
164164
verifyNoMoreInteractions(parser)
165165
}
166166

167+
@Test
168+
fun `handles quoted commands`() {
169+
val cmd = if (SystemInfo.isWindows) {
170+
"""
171+
"dir"
172+
""".trimIndent()
173+
} else {
174+
"""
175+
ls
176+
""".trimIndent()
177+
}
178+
179+
val folderWithSpaceInItsName = folder.newFolder("hello world")
180+
val file = File(folderWithSpaceInItsName, "foo")
181+
file.writeText("bar")
182+
183+
val sut = createSut("""$cmd ${folder.root.absolutePath}${File.separator}"hello world"""")
184+
stubParser()
185+
186+
sut.resolveCredentials()
187+
188+
val captor = argumentCaptor<String>().apply {
189+
verify(parser).parse(capture())
190+
}
191+
192+
assertThat(captor.firstValue).contains("foo")
193+
}
194+
167195
@Test
168196
fun `has path`() {
169197
val cmd = if (SystemInfo.isWindows) {

0 commit comments

Comments
 (0)