Files
buildkit/executor/containerid_test.go
Tonis Tiigi 6e9d3d4bbc executor: validate container IDs centrally
Add executor.ValidContainerID and enforce it in runc/containerd Run paths.

Only runc executor used the ID in filesystem operations.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 789df2422341960b7549d14ea475add43e73cd74)
2026-03-25 08:14:29 -07:00

34 lines
788 B
Go

package executor
import "testing"
func TestValidContainerID(t *testing.T) {
t.Parallel()
tests := []struct {
name string
id string
wantErr bool
}{
{name: "lowercase", id: "abc123", wantErr: false},
{name: "uppercase", id: "AbC123", wantErr: false},
{name: "empty", id: "", wantErr: true},
{name: "dash", id: "abc-123", wantErr: true},
{name: "slash", id: "abc/123", wantErr: true},
{name: "underscore", id: "abc_123", wantErr: true},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
err := ValidContainerID(tc.id)
if tc.wantErr && err == nil {
t.Fatalf("expected an error for id %q", tc.id)
}
if !tc.wantErr && err != nil {
t.Fatalf("expected no error for id %q, got %v", tc.id, err)
}
})
}
}