Files
buildx/policy/policy_error_test.go
T
Tonis Tiigi 9f59d5b789 policy: add progress vertex error integration test
Refactor policy error unit tests to table-driven subtests with slug names.
Add rawjson integration coverage to verify policy vertex captures DENY build
errors in progress output.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-02-19 18:13:58 -08:00

52 lines
1.3 KiB
Go

package policy
import (
"errors"
"testing"
gwpb "github.com/moby/buildkit/frontend/gateway/pb"
solverpb "github.com/moby/buildkit/solver/pb"
"github.com/moby/buildkit/sourcepolicy/policysession"
"github.com/stretchr/testify/require"
)
func TestPolicyIsPolicyError(t *testing.T) {
tests := []struct {
name string
err error
want bool
}{
{
name: "matches-recorded-source",
err: errors.New("failed to solve: error evaluating the source policy: source \"docker-image://busybox:latest\" not allowed by policy: action DENY"),
want: true,
},
{
name: "does-not-match-without-buildkit-pattern",
err: errors.New("failed to parse dockerfile for docker-image://busybox:latest"),
want: false,
},
{
name: "does-not-match-unrelated-error",
err: errors.New("failed to solve: error evaluating the source policy: source \"docker-image://alpine:latest\" not allowed by policy: action DENY"),
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := NewPolicy(Opt{})
req := &policysession.CheckPolicyRequest{
Source: &gwpb.ResolveSourceMetaResponse{
Source: &solverpb.SourceOp{
Identifier: "docker-image://busybox:latest",
},
},
}
p.recordDenyIdentifier(req)
require.Equal(t, tt.want, p.IsPolicyError(tt.err))
})
}
}