Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 51491fc

Browse files
authored
fix(provisionersdk): change test to use bash script instead of binary echo (coder#12759)
Just upgraded to macOS 14.4 and TestAgentScript/Run fails for me with error `signal: killed`. I opened the test directory in a terminal and sure enough, when you execute the `echo` binary, it is immediately killed. The binary has no extended attributes and is byte-identical to the one in `/bin/`. This fix uses a different strategy: instead of copying the `echo` binary from the system around, we just copy a small bash script that _calls_ the `echo` command.
1 parent 5f28220 commit 51491fc

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

provisionersdk/agent_test.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"net/http"
1212
"net/http/httptest"
1313
"net/url"
14-
"os"
1514
"os/exec"
1615
"runtime"
1716
"strings"
@@ -23,17 +22,19 @@ import (
2322
"github.com/coder/coder/v2/provisionersdk"
2423
)
2524

25+
// bashEcho is a script that calls the local `echo` with the arguments. This is preferable to
26+
// sending the real `echo` binary since macOS 14.4+ immediately sigkills `echo` if it is copied to
27+
// another directory and run locally.
28+
const bashEcho = `#!/usr/bin/env bash
29+
echo $@`
30+
2631
func TestAgentScript(t *testing.T) {
2732
t.Parallel()
2833
t.Run("Run", func(t *testing.T) {
2934
t.Parallel()
3035
srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
31-
echoPath, err := exec.LookPath("echo")
32-
require.NoError(t, err)
33-
content, err := os.ReadFile(echoPath)
34-
require.NoError(t, err)
3536
render.Status(r, http.StatusOK)
36-
render.Data(rw, r, content)
37+
render.Data(rw, r, []byte(bashEcho))
3738
}))
3839
defer srv.Close()
3940
srvURL, err := url.Parse(srv.URL)
@@ -46,9 +47,6 @@ func TestAgentScript(t *testing.T) {
4647
}
4748
script = strings.ReplaceAll(script, "${ACCESS_URL}", srvURL.String()+"/")
4849
script = strings.ReplaceAll(script, "${AUTH_TYPE}", "token")
49-
// In certain distributions "echo" is a part of coreutils, and determines
50-
// it's functionality based on the exec path name.
51-
script = strings.ReplaceAll(script, "BINARY_NAME=coder", "BINARY_NAME=echo")
5250
// This is intentionally ran in single quotes to mimic how a customer may
5351
// embed our script. Our scripts should not include any single quotes.
5452
// nolint:gosec

0 commit comments

Comments
 (0)