Skip to content

Commit e341b1c

Browse files
committed
Only allow commands as a list of strings
1 parent 246f957 commit e341b1c

2 files changed

Lines changed: 6 additions & 32 deletions

File tree

packages/smithy-aws-core/src/smithy_aws_core/identity/process.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# SPDX-License-Identifier: Apache-2.0
33
import asyncio
44
import json
5-
import shlex
65
from dataclasses import dataclass
76
from datetime import UTC, datetime
87

@@ -31,15 +30,12 @@ class ProcessCredentialsResolver(
3130

3231
def __init__(
3332
self,
34-
command: str | list[str],
33+
command: list[str],
3534
config: ProcessCredentialsConfig | None = None,
3635
):
37-
normalized_command = (
38-
shlex.split(command) if isinstance(command, str) else command
39-
)
40-
if not normalized_command:
41-
raise ValueError("command must be a non-empty string or list")
42-
self._command = list(normalized_command)
36+
if not command:
37+
raise ValueError("command must be a non-empty list")
38+
self._command = list(command)
4339
self._config = config or ProcessCredentialsConfig()
4440
self._credentials = None
4541

packages/smithy-aws-core/tests/unit/identity/test_process.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def test_config_custom_values():
3434
assert config.timeout == 60
3535

3636

37-
@pytest.mark.parametrize("command", [[], "", None])
37+
@pytest.mark.parametrize("command", [[], None])
3838
def test_resolver_invalid_command(command: object):
39-
with pytest.raises(ValueError, match="command must be a non-empty string or list"):
39+
with pytest.raises((ValueError, TypeError)):
4040
ProcessCredentialsResolver(command) # type: ignore[arg-type]
4141

4242

@@ -383,25 +383,3 @@ async def test_command_with_multiple_args():
383383
stdout=asyncio.subprocess.PIPE,
384384
stderr=asyncio.subprocess.PIPE,
385385
)
386-
387-
388-
@pytest.mark.asyncio
389-
async def test_string_command_with_multiple_args():
390-
resp_body = json.dumps(DEFAULT_RESPONSE_DATA)
391-
process = mock_subprocess(0, resp_body.encode("utf-8"))
392-
393-
with patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
394-
resolver = ProcessCredentialsResolver(
395-
'aws-credential-helper --profile "test profile" --format json'
396-
)
397-
await resolver.get_identity(properties={})
398-
399-
mock_exec.assert_called_once_with(
400-
"aws-credential-helper",
401-
"--profile",
402-
"test profile",
403-
"--format",
404-
"json",
405-
stdout=asyncio.subprocess.PIPE,
406-
stderr=asyncio.subprocess.PIPE,
407-
)

0 commit comments

Comments
 (0)