From 51491fc01bb81b8cb4ea0e0f7c77531108ec5dd2 Mon Sep 17 00:00:00 2001 From: Spike Curtis Date: Tue, 26 Mar 2024 14:37:20 +0400 Subject: [PATCH] fix(provisionersdk): change test to use bash script instead of binary echo (#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. --- provisionersdk/agent_test.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/provisionersdk/agent_test.go b/provisionersdk/agent_test.go index c10127b03d..96c0d531ad 100644 --- a/provisionersdk/agent_test.go +++ b/provisionersdk/agent_test.go @@ -11,7 +11,6 @@ import ( "net/http" "net/http/httptest" "net/url" - "os" "os/exec" "runtime" "strings" @@ -23,17 +22,19 @@ import ( "github.com/coder/coder/v2/provisionersdk" ) +// bashEcho is a script that calls the local `echo` with the arguments. This is preferable to +// sending the real `echo` binary since macOS 14.4+ immediately sigkills `echo` if it is copied to +// another directory and run locally. +const bashEcho = `#!/usr/bin/env bash +echo $@` + func TestAgentScript(t *testing.T) { t.Parallel() t.Run("Run", func(t *testing.T) { t.Parallel() srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { - echoPath, err := exec.LookPath("echo") - require.NoError(t, err) - content, err := os.ReadFile(echoPath) - require.NoError(t, err) render.Status(r, http.StatusOK) - render.Data(rw, r, content) + render.Data(rw, r, []byte(bashEcho)) })) defer srv.Close() srvURL, err := url.Parse(srv.URL) @@ -46,9 +47,6 @@ func TestAgentScript(t *testing.T) { } script = strings.ReplaceAll(script, "${ACCESS_URL}", srvURL.String()+"/") script = strings.ReplaceAll(script, "${AUTH_TYPE}", "token") - // In certain distributions "echo" is a part of coreutils, and determines - // it's functionality based on the exec path name. - script = strings.ReplaceAll(script, "BINARY_NAME=coder", "BINARY_NAME=echo") // 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