Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions host-setup/bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,9 @@ function Invoke-Upgrade {
# Installs only what is named, since the agent tools are never installed as a set nobody chose.
function Invoke-AgentsInstall {
if ($script:AGENT_NAMES.Count -eq 0) { die "-Agents takes the tools to install, separated by commas, or 'all'" }
foreach ($name in $script:AGENT_NAMES) {
if ($name -match '^[-\u2013\u2014\u2015]') { die "-Agents takes tool names, and '$name' starts with a dash" }
}
if ($script:AGENT_NAMES -ccontains 'all') {
if ($script:AGENT_NAMES.Count -gt 1) { die "-Agents takes 'all' alone, or a list of tool names" }
Invoke-Tool -Tool 'install-agents.ps1' -Arguments '-Install', '-All'
Expand Down
1 change: 1 addition & 0 deletions host-setup/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ parse_args() {
IFS=',' read -r -a agent_fields <<<"$2"
for agent_name in "${agent_fields[@]}"; do
if [[ -n $agent_name ]]; then
[[ $agent_name != -* ]] || die "--agents takes tool names, and \"$agent_name\" starts with a dash"
AGENTS+=("$agent_name")
if [[ $agent_name == "all" ]]; then
saw_all=true
Expand Down
17 changes: 17 additions & 0 deletions tests/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,15 @@ def test_agents_with_an_empty_list_is_refused_before_anything_runs(self) -> None
self.assertEqual(self.steps(), [])
self.assertEqual(list(self.data.iterdir()), [])

def test_agents_a_dash_prefixed_name_is_refused_before_anything_runs(self) -> None:
for given in ("--all", "-a", "herdr,--all", "-x,herdr"):
with self.subTest(given=given):
result = self.run_main(action="--agents", args=(given,))
self.assertNotEqual(result.returncode, 0)
self.assertIn("starts with a dash", result.stderr)
self.assertEqual(self.steps(), [])
Comment thread
ptr727 marked this conversation as resolved.
self.assertEqual(list(self.data.iterdir()), [])

def test_agents_with_no_list_is_refused_before_anything_runs(self) -> None:
result = self.run_main(action="--agents")
self.assertNotEqual(result.returncode, 0)
Expand Down Expand Up @@ -1972,6 +1981,14 @@ def test_empty_names_are_dropped_from_the_list(self) -> None:
self.assertEqual(result.returncode, 0, result.stderr)
self.assertEqual(self.steps(), ["install-agents.ps1 -Install herdr cswap"], result.stdout)

def test_a_dash_prefixed_name_is_refused(self) -> None:
for given in ("-All", "-a", "herdr,-All", "\u2013All", "herdr,\u2014y", "\u2015All"):
with self.subTest(given=given):
result = self.run_agents([given])
self.assertNotEqual(result.returncode, 0)
self.assertIn("starts with a dash", result.stderr)
self.assertEqual(self.steps(), [])

def test_an_empty_list_is_refused(self) -> None:
result = self.run_agents([","])
self.assertNotEqual(result.returncode, 0)
Expand Down
Loading