From 5cb93ec5a565697b5292fd8969b3b5d8ca08fe60 Mon Sep 17 00:00:00 2001 From: PuneetPunamiya Date: Mon, 23 Oct 2023 11:24:14 +0530 Subject: [PATCH] Updates go version in github actions workflows and pipeline version in e2e test script This patch also fixes the e2e tests and examples test Signed-off-by: Puneet Punamiya ppunamiy@redhat.com --- .github/workflows/kind-e2e.yaml | 4 ++-- test/e2e-tests.sh | 2 +- test/e2e_test.go | 18 +++++++++++++++-- test/examples_test.go | 36 ++++++++++++++++++++------------- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/.github/workflows/kind-e2e.yaml b/.github/workflows/kind-e2e.yaml index 0a3f31b728..1bd7df309d 100644 --- a/.github/workflows/kind-e2e.yaml +++ b/.github/workflows/kind-e2e.yaml @@ -2,7 +2,7 @@ name: Chains kind E2E Tests on: pull_request: - branches: + branches: - main - release-* @@ -53,7 +53,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.18.x + go-version: 1.19.x - uses: imjasonh/setup-ko@v0.6 with: diff --git a/test/e2e-tests.sh b/test/e2e-tests.sh index c1efe39b15..525d061205 100755 --- a/test/e2e-tests.sh +++ b/test/e2e-tests.sh @@ -28,7 +28,7 @@ header "Setting up environment" # Test against nightly instead of latest. install_tkn -export RELEASE_YAML="https://storage.googleapis.com/tekton-releases/pipeline/previous/v0.40.0/release.yaml" +export RELEASE_YAML="https://storage.googleapis.com/tekton-releases/pipeline/previous/v0.44.0/release.yaml" install_pipeline_crd install_chains diff --git a/test/e2e_test.go b/test/e2e_test.go index b4ebbe77fa..3aa34c4de1 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -773,8 +773,12 @@ func TestProvenanceMaterials(t *testing.T) { } if test.name == "pipelinerun" { pr := signedObj.GetObject().(*v1beta1.PipelineRun) - for _, trStatus := range pr.Status.TaskRuns { - for _, step := range trStatus.Status.Steps { + for _, cr := range pr.Status.ChildReferences { + taskRun, err := c.PipelineClient.TektonV1beta1().TaskRuns(ns).Get(ctx, cr.Name, metav1.GetOptions{}) + if err != nil { + t.Errorf("Did not expect an error but got %v", err) + } + for _, step := range taskRun.Status.Steps { want = append(want, provenance.ProvenanceMaterial{ URI: strings.Split(step.ImageID, "@")[0], Digest: provenance.DigestSet{ @@ -783,6 +787,16 @@ func TestProvenanceMaterials(t *testing.T) { }) } } + } else { + tr := signedObj.GetObject().(*v1beta1.TaskRun) + for _, step := range tr.Status.Steps { + want = append(want, provenance.ProvenanceMaterial{ + URI: strings.Split(step.ImageID, "@")[0], + Digest: provenance.DigestSet{ + "sha256": strings.Split(step.ImageID, ":")[1], + }, + }) + } } got := predicate.Materials diff --git a/test/examples_test.go b/test/examples_test.go index 90640cfc1e..8bddd107d0 100644 --- a/test/examples_test.go +++ b/test/examples_test.go @@ -42,6 +42,7 @@ import ( intoto "github.com/in-toto/in-toto-golang/in_toto" slsa "github.com/in-toto/in-toto-golang/in_toto/slsa_provenance/v0.2" "github.com/secure-systems-lab/go-securesystemslib/dsse" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/ghodss/yaml" "github.com/tektoncd/chains/pkg/chains/objects" @@ -60,6 +61,7 @@ type TestExample struct { getExampleObjects func(t *testing.T, ns string) map[string]objects.TektonObject payloadKey string signatureKey string + outputLocation string } // TestExamples copies the format in the tektoncd/pipelines repo @@ -75,6 +77,7 @@ func TestExamples(t *testing.T) { getExampleObjects: getTaskRunExamples, payloadKey: "chains.tekton.dev/payload-taskrun-%s", signatureKey: "chains.tekton.dev/signature-taskrun-%s", + outputLocation: "slsa/v1", }, { name: "pipelinerun-examples", @@ -85,6 +88,7 @@ func TestExamples(t *testing.T) { getExampleObjects: getPipelineRunExamples, payloadKey: "chains.tekton.dev/payload-pipelinerun-%s", signatureKey: "chains.tekton.dev/signature-pipelinerun-%s", + outputLocation: "slsa/v1", }, } @@ -129,7 +133,7 @@ func runInTotoFormatterTests(ctx context.Context, t *testing.T, ns string, c *cl if err := json.Unmarshal(payload, &gotProvenance); err != nil { t.Fatal(err) } - expected := expectedProvenance(t, path, completed) + expected := expectedProvenance(t, ctx, path, completed, test.outputLocation, ns, c) opts := []cmp.Option{ // Annotations and labels may contain release specific information. Ignore @@ -187,12 +191,12 @@ func (v *verifier) Public() crypto.PublicKey { return v.pub } -func expectedProvenance(t *testing.T, example string, obj objects.TektonObject) intoto.ProvenanceStatement { +func expectedProvenance(t *testing.T, ctx context.Context, example string, obj objects.TektonObject, outputLocation string, ns string, c *clients) intoto.ProvenanceStatement { switch obj.(type) { case *objects.TaskRunObject: - return expectedTaskRunProvenance(t, example, obj) + return expectedTaskRunProvenance(t, example, obj, outputLocation) case *objects.PipelineRunObject: - return expectedPipelineRunProvenance(t, example, obj) + return expectedPipelineRunProvenance(t, ctx, example, obj, outputLocation, ns, c) default: t.Error("Unexpected type trying to get provenance") } @@ -215,7 +219,7 @@ type Format struct { URIDigest []URIDigestPair } -func expectedTaskRunProvenance(t *testing.T, example string, obj objects.TektonObject) intoto.ProvenanceStatement { +func expectedTaskRunProvenance(t *testing.T, example string, obj objects.TektonObject, outputLocation string) intoto.ProvenanceStatement { tr := obj.GetObject().(*v1beta1.TaskRun) name := tr.Name @@ -249,10 +253,10 @@ func expectedTaskRunProvenance(t *testing.T, example string, obj objects.TektonO URIDigest: uridigest, } - return readExpectedAttestation(t, example, f) + return readExpectedAttestation(t, example, f, outputLocation) } -func expectedPipelineRunProvenance(t *testing.T, example string, obj objects.TektonObject) intoto.ProvenanceStatement { +func expectedPipelineRunProvenance(t *testing.T, ctx context.Context, example string, obj objects.TektonObject, outputLocation string, ns string, c *clients) intoto.ProvenanceStatement { pr := obj.GetObject().(*v1beta1.PipelineRun) buildStartTimes := []string{} @@ -261,10 +265,14 @@ func expectedPipelineRunProvenance(t *testing.T, example string, obj objects.Tek uriDigestSet := make(map[string]bool) // TODO: Load TaskRun data from ChildReferences. - for _, trStatus := range pr.Status.TaskRuns { - buildStartTimes = append(buildStartTimes, trStatus.Status.StartTime.Time.UTC().Format(time.RFC3339)) - buildFinishedTimes = append(buildFinishedTimes, trStatus.Status.CompletionTime.Time.UTC().Format(time.RFC3339)) - for _, step := range trStatus.Status.Steps { + for _, cr := range pr.Status.ChildReferences { + taskRun, err := c.PipelineClient.TektonV1beta1().TaskRuns(ns).Get(ctx, cr.Name, metav1.GetOptions{}) + if err != nil { + t.Errorf("Did not expect an error but got %v", err) + } + buildStartTimes = append(buildStartTimes, taskRun.Status.StartTime.Time.UTC().Format(time.RFC3339)) + buildFinishedTimes = append(buildFinishedTimes, taskRun.Status.CompletionTime.Time.UTC().Format(time.RFC3339)) + for _, step := range taskRun.Status.Steps { // append uri and digest that havent already been appended uri := strings.Split(step.ImageID, "@")[0] digest := strings.Split(step.ImageID, ":")[1] @@ -274,7 +282,7 @@ func expectedPipelineRunProvenance(t *testing.T, example string, obj objects.Tek uriDigestSet[uriDigest] = true } } - for _, sidecar := range trStatus.Status.Sidecars { + for _, sidecar := range taskRun.Status.Sidecars { // append uri and digest that havent already been appended uri := strings.Split(sidecar.ImageID, "@")[0] digest := strings.Split(sidecar.ImageID, ":")[1] @@ -294,10 +302,10 @@ func expectedPipelineRunProvenance(t *testing.T, example string, obj objects.Tek URIDigest: uridigest, } - return readExpectedAttestation(t, example, f) + return readExpectedAttestation(t, example, f, outputLocation) } -func readExpectedAttestation(t *testing.T, example string, f Format) intoto.ProvenanceStatement { +func readExpectedAttestation(t *testing.T, example string, f Format, outputLocation string) intoto.ProvenanceStatement { path := filepath.Join("testdata/intoto", strings.Replace(filepath.Base(example), ".yaml", ".json", 1)) t.Logf("Reading expected provenance from %s", path)