Skip to content

Agent Mesh

do not inherit env vars on tests to switch to headleess

Antonio Ojea94c184933455
diff --git a/cmd/sam-node/oidc_test.go b/cmd/sam-node/oidc_test.go
index a063aaae..1d32b3e3 100644
--- a/cmd/sam-node/oidc_test.go
+++ b/cmd/sam-node/oidc_test.go
@@ -6,11 +6,21 @@ import (
"net/http"
"net/http/httptest"
"net/url"
+ "os"
"testing"
"time"
)
func TestInteractiveLogin(t *testing.T) {
+ origSSHClient := os.Getenv("SSH_CLIENT")
+ origSSHTTY := os.Getenv("SSH_TTY")
+ os.Unsetenv("SSH_CLIENT")
+ os.Unsetenv("SSH_TTY")
+ defer func() {
+ os.Setenv("SSH_CLIENT", origSSHClient)
+ os.Setenv("SSH_TTY", origSSHTTY)
+ }()
+
mux := http.NewServeMux()
mux.HandleFunc("/token", func(w http.ResponseWriter, r *http.Request) {
diff --git a/tests/integration/minimal_helpers_test.go b/tests/integration/minimal_helpers_test.go
index b879e5d4..08280c0d 100644
--- a/tests/integration/minimal_helpers_test.go
+++ b/tests/integration/minimal_helpers_test.go
@@ -18,6 +18,7 @@ import (
"bytes"
"context"
"errors"
+ "os"
"os/exec"
"path/filepath"
"runtime"
@@ -76,9 +77,13 @@ func runCommand(
cmd := exec.CommandContext(ctx, name, args...)
cmd.Dir = cwd
- if len(env) > 0 {
- cmd.Env = append(cmd.Env, env...)
+ var finalEnv []string
+ for _, e := range append(os.Environ(), env...) {
+ if !strings.HasPrefix(e, "SSH_CLIENT=") && !strings.HasPrefix(e, "SSH_TTY=") {
+ finalEnv = append(finalEnv, e)
+ }
}
+ cmd.Env = finalEnv
if stdin != "" {
cmd.Stdin = bytes.NewBufferString(stdin)
}
@@ -152,9 +157,13 @@ func runCommandWithCallback(
cmd := exec.CommandContext(ctx, name, args...)
cmd.Dir = cwd
- if len(env) > 0 {
- cmd.Env = append(cmd.Env, env...)
+ var finalEnv []string
+ for _, e := range append(os.Environ(), env...) {
+ if !strings.HasPrefix(e, "SSH_CLIENT=") && !strings.HasPrefix(e, "SSH_TTY=") {
+ finalEnv = append(finalEnv, e)
+ }
}
+ cmd.Env = finalEnv
if stdin != "" {
cmd.Stdin = bytes.NewBufferString(stdin)
}