Skip to content

Commit 56a6a8f

Browse files
committed
Add unit test for host env filtering and verify LOCALSTACK_AUTH_TOKEN exclusion
1 parent 5247525 commit 56a6a8f

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

internal/container/start_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"errors"
77
"io"
8+
"strings"
89
"testing"
910

1011
"github.com/localstack/lstk/internal/log"
@@ -65,3 +66,25 @@ func TestServicePortRange_ReturnsExpectedPorts(t *testing.T) {
6566
assert.Equal(t, "4559", ports[50].HostPort)
6667
}
6768

69+
func TestFilterHostEnv(t *testing.T) {
70+
tests := []struct {
71+
name string
72+
env string
73+
expected bool
74+
}{
75+
{"CI is included", "CI=true", true},
76+
{"LOCALSTACK_DISABLE_EVENTS is included", "LOCALSTACK_DISABLE_EVENTS=1", true},
77+
{"LOCALSTACK_HOST is included", "LOCALSTACK_HOST=0.0.0.0", true},
78+
{"LOCALSTACK_AUTH_TOKEN is excluded", "LOCALSTACK_AUTH_TOKEN=secret", false},
79+
{"PATH is excluded", "PATH=/usr/bin", false},
80+
{"HOME is excluded", "HOME=/root", false},
81+
{"LOCALSTACK_BUILD_VERSION is included", "LOCALSTACK_BUILD_VERSION=3.0.0", true},
82+
}
83+
84+
for _, tt := range tests {
85+
t.Run(tt.name, func(t *testing.T) {
86+
got := strings.HasPrefix(tt.env, "CI=") || (strings.HasPrefix(tt.env, "LOCALSTACK_") && !strings.HasPrefix(tt.env, "LOCALSTACK_AUTH_TOKEN="))
87+
assert.Equal(t, tt.expected, got)
88+
})
89+
}
90+
}

test/integration/start_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ func TestStartCommandPassesCIAndLocalStackEnvVars(t *testing.T) {
170170

171171
t.Setenv("CI", "true")
172172
t.Setenv("LOCALSTACK_DISABLE_EVENTS", "1")
173+
t.Setenv("LOCALSTACK_AUTH_TOKEN", "host-token")
173174

174175
mockServer := createMockLicenseServer(true)
175176
defer mockServer.Close()
@@ -187,6 +188,7 @@ func TestStartCommandPassesCIAndLocalStackEnvVars(t *testing.T) {
187188
assert.Equal(t, "true", envVars["CI"])
188189
assert.Equal(t, "1", envVars["LOCALSTACK_DISABLE_EVENTS"])
189190
assert.NotEmpty(t, envVars["LOCALSTACK_AUTH_TOKEN"])
191+
assert.NotEqual(t, "host-token", envVars["LOCALSTACK_AUTH_TOKEN"], "host LOCALSTACK_AUTH_TOKEN should not be passed through")
190192
}
191193

192194
// containerEnvToMap converts a Docker container's []string env to a map.

0 commit comments

Comments
 (0)