mirror of https://github.com/coder/coder.git
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.
This commit is contained in:
parent
5f28220eec
commit
51491fc01b
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue