From e3ba8be9e61059e7d34f8ed78a24272dfee10595 Mon Sep 17 00:00:00 2001 From: Miaha Cybersec Date: Thu, 27 Jun 2024 08:50:23 -0600 Subject: [PATCH] Test BuildKit with defaults --- pkg/buildkit/buildkit_test.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/pkg/buildkit/buildkit_test.go b/pkg/buildkit/buildkit_test.go index 8f9279d6..aad4064e 100644 --- a/pkg/buildkit/buildkit_test.go +++ b/pkg/buildkit/buildkit_test.go @@ -197,6 +197,18 @@ func TestNewClient(t *testing.T) { cancel() checkMissingCapsError(t, err, requiredCaps...) }) + t.Run("faulty addr", func(t *testing.T) { + t.Parallel() + addr := newMockBuildkitAPI(t) // this should return a faulty addr + ctxT, cancel := context.WithTimeout(ctx, time.Second) + defer cancel() + bkOpts := Opts{ + Addr: `invalid-address:\\` + addr, + KeyPath: `No-Keys-Exist/Here`, + } + _, err := NewClient(ctxT, bkOpts) + assert.Error(t, err) + }) t.Run("with caps", func(t *testing.T) { t.Parallel() addr := newMockBuildkitAPI(t, requiredCaps...) @@ -213,10 +225,18 @@ func TestNewClient(t *testing.T) { err = ValidateClient(ctxT, client) assert.NoError(t, err) }) + t.Run("default buildkit addr", func(t *testing.T) { + t.Parallel() + bkOpts := Opts{} // Initialize with default values + ctxT, cancel := context.WithTimeout(ctx, time.Second) + defer cancel() + client, err := NewClient(ctxT, bkOpts) + assert.NoError(t, err) + defer client.Close() + err = ValidateClient(ctxT, client) + assert.NoError(t, err) + }) }) - - // TODO: Test with defaults, but then we need to control those socket paths. - // I considered doing this in a chroot, but it is fairly complicated to do so and requires root privileges anyway (or CAP_SYS_CHROOT). } func TestArrayFile(t *testing.T) {