Skip to content

fix: Add test for wrapping init script with single quotes #2979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2022
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
fix: Add test for wrapping init script with single quotes
This ensures our initialization script works with single  uotes.
  • Loading branch information
kylecarbs committed Jul 13, 2022
commit 3df2975d3ee9dcbff932abc18362459eefd36649
5 changes: 4 additions & 1 deletion provisionersdk/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ func TestAgentScript(t *testing.T) {
}
script = strings.ReplaceAll(script, "${ACCESS_URL}", srvURL.String()+"/")
script = strings.ReplaceAll(script, "${AUTH_TYPE}", "token")
output, err := exec.Command("sh", "-c", script).CombinedOutput()
// This is intentionally ran in single quotes to mimic how a customer may
// embed our script. Our scripts should not include any single quotes.
// nolint:gosec
output, err := exec.Command("sh", "-c", "sh -c '"+script+"'").CombinedOutput()
t.Log(string(output))
require.NoError(t, err)
// Ignore debug output from `set -x`, we're only interested in the last line.
Expand Down
4 changes: 2 additions & 2 deletions provisionersdk/scripts/bootstrap_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ cd "$BINARY_DIR"
# This could fail for a number of reasons, many of which are likely transient.
# So just keep trying!
while :; do
# Try a number of different download tools, as we don't know what we'll
# have available
# Try a number of different download tools, as we don not know what we
# will have available.
status=""
if command -v curl >/dev/null 2>&1; then
curl -fsSL --compressed "${BINARY_URL}" -o "${BINARY_NAME}" && break
Expand Down
4 changes: 2 additions & 2 deletions provisionersdk/scripts/bootstrap_windows.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Sleep for a while in case the underlying provider deletes the resource on error.
trap {
Write-Error '=== Agent script exited with non-zero code. Sleeping 24h to preserve logs...'
Write-Error "=== Agent script exited with non-zero code. Sleeping 24h to preserve logs..."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious how folks would be using sh -c on Windows, but I suppose it's good to remain consistent 👍

Start-Sleep -Seconds 86400
}

Expand All @@ -25,7 +25,7 @@ while ($true) {
}
}

# If the below fails, retrying probably won't help.
# If the below fails, retrying probably will not help.
Set-MpPreference -DisableRealtimeMonitoring $true -ExclusionPath $env:TEMP\sshd.exe
$env:CODER_AGENT_AUTH = "${AUTH_TYPE}"
$env:CODER_AGENT_URL = "${ACCESS_URL}"
Expand Down