get.porter.sh/porter@v1.3.0/tests/integration/registry_integration_test.go (about) 1 //go:build integration 2 3 package integration 4 5 import ( 6 "context" 7 "fmt" 8 "testing" 9 10 "get.porter.sh/porter/pkg/cnab" 11 cnabtooci "get.porter.sh/porter/pkg/cnab/cnab-to-oci" 12 "get.porter.sh/porter/pkg/portercontext" 13 "get.porter.sh/porter/tests/tester" 14 "github.com/stretchr/testify/require" 15 ) 16 17 func TestRegistry(t *testing.T) { 18 ctx := context.Background() 19 c := portercontext.NewTestContext(t) 20 r := cnabtooci.NewRegistry(c.Context) 21 22 t.Run("secure registry, existing bundle", func(t *testing.T) { 23 repo := cnab.MustParseOCIReference("ghcr.io/getporter/examples/porter-hello") 24 ref, err := repo.WithTag("v0.2.0") 25 require.NoError(t, err) 26 27 // List Tags 28 regOpts := cnabtooci.RegistryOptions{} 29 tags, err := r.ListTags(ctx, repo, regOpts) 30 require.NoError(t, err, "ListTags failed") 31 require.Contains(t, tags, "v0.2.0", "expected a tag for the bundle version") 32 require.Contains(t, tags, "3cb284ae76addb8d56b52bb7d6838351", "expected a tag for the bundle image") 33 34 // GetBundleMetadata 35 // Validates that we are passing auth when querying the registry 36 meta, err := r.GetBundleMetadata(ctx, ref, regOpts) 37 require.NoError(t, err, "GetBundleMetadata failed") 38 require.Equal(t, "sha256:276b44be3f478b4c8d1f99c1925386d45a878a853f22436ece5589f32e9df384", meta.Digest.String(), "incorrect bundle digest") 39 }) 40 41 t.Run("insecure registry, existing bundle", func(t *testing.T) { 42 // Start an insecure registry with self-signed certificates 43 testr, err := tester.NewTest(t) 44 require.NoError(t, err, "tester.NewTest failed") 45 defer testr.Close() 46 reg := testr.StartTestRegistry(tester.TestRegistryOptions{UseTLS: true}) 47 48 // Copy a test bundle to the registry 49 testRef := fmt.Sprintf("%s/porter-hello-nonroot:v0.2.0", reg) 50 testr.RunPorter("copy", "--source=ghcr.io/getporter/examples/porter-hello:v0.2.0", "--destination", testRef, "--insecure-registry") 51 52 // List Tags 53 ref := cnab.MustParseOCIReference(testRef) 54 regOpts := cnabtooci.RegistryOptions{InsecureRegistry: true} 55 tags, err := r.ListTags(ctx, ref, regOpts) 56 require.NoError(t, err, "ListTags failed") 57 require.Contains(t, tags, "v0.2.0", "expected a tag for the bundle version") 58 59 // GetBundleMetadata 60 // Validate that call works when no auth is needed (since it's the local test registry, there is no auth) 61 meta, err := r.GetBundleMetadata(ctx, ref, regOpts) 62 require.NoError(t, err, "GetBundleMetadata failed") 63 require.Equal(t, "sha256:276b44be3f478b4c8d1f99c1925386d45a878a853f22436ece5589f32e9df384", meta.Digest.String(), "incorrect bundle digest") 64 }) 65 66 t.Run("nonexistent bundle", func(t *testing.T) { 67 ref := cnab.MustParseOCIReference("ghcr.io/getporter/oops-i-dont-exist") 68 69 // List Tags 70 // Note that listing tags on a nonexistent repo will always yield an authentication error, instead of a not found, to avoid leaking information about private repositories 71 regOpts := cnabtooci.RegistryOptions{} 72 _, err := r.ListTags(ctx, ref, regOpts) 73 require.ErrorIs(t, cnabtooci.ErrNotFound{}, err) 74 75 // GetBundleMetadata 76 // Validates that we are passing auth when querying the registry 77 _, err = r.GetBundleMetadata(ctx, ref, regOpts) 78 require.ErrorIs(t, cnabtooci.ErrNotFound{}, err) 79 }) 80 81 t.Run("pull docker image as bundle", func(t *testing.T) { 82 ref := cnab.MustParseOCIReference("getporter/porter-hello-installer:0.1.0") 83 _, err := r.PullBundle(ctx, ref, cnabtooci.RegistryOptions{}) 84 require.ErrorContains(t, err, "the provided reference must be a Porter bundle") 85 }) 86 }