Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove GetUnsignedTask helper function and use var in each file #6799

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions pkg/reconciler/taskrun/resources/taskref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ var (
},
EntryPoint: "foo/bar",
}
unsignedV1beta1Task = &v1beta1.Task{
TypeMeta: metav1.TypeMeta{
APIVersion: "tekton.dev/v1beta1",
Kind: "Task"},
ObjectMeta: metav1.ObjectMeta{
Name: "test-task",
Namespace: "trusted-resources",
Annotations: map[string]string{"foo": "bar"},
},
Spec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{
Image: "ubuntu",
Name: "echo",
}},
},
}
unsignedV1Task = v1.Task{
TypeMeta: metav1.TypeMeta{
APIVersion: "tekton.dev/v1",
Expand Down Expand Up @@ -738,7 +754,7 @@ func TestGetTaskFunc_V1beta1Task_VerifyNoError(t *testing.T) {
signer, _, k8sclient, vps := test.SetupVerificationPolicies(t)
tektonclient := fake.NewSimpleClientset()

unsignedTask := test.GetUnsignedTask("test-task")
unsignedTask := unsignedV1beta1Task
unsignedTaskBytes, err := json.Marshal(unsignedTask)
unsignedV1Task := &v1.Task{}
unsignedTask.ConvertTo(ctx, unsignedV1Task)
Expand Down Expand Up @@ -872,7 +888,7 @@ func TestGetTaskFunc_V1beta1Task_VerifyError(t *testing.T) {
signer, _, k8sclient, vps := test.SetupVerificationPolicies(t)
tektonclient := fake.NewSimpleClientset()

unsignedTask := test.GetUnsignedTask("test-task")
unsignedTask := unsignedV1beta1Task
unsignedTaskBytes, err := json.Marshal(unsignedTask)
if err != nil {
t.Fatal("fail to marshal task", err)
Expand Down Expand Up @@ -1249,7 +1265,7 @@ func TestGetTaskFunc_GetFuncError(t *testing.T) {
_, k8sclient, vps := test.SetupMatchAllVerificationPolicies(t, "trusted-resources")
tektonclient := fake.NewSimpleClientset()

unsignedTask := test.GetUnsignedTask("test-task")
unsignedTask := unsignedV1beta1Task
unsignedTaskBytes, err := json.Marshal(unsignedTask)
if err != nil {
t.Fatal("fail to marshal task", err)
Expand Down
20 changes: 18 additions & 2 deletions pkg/trustedresources/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ const (
)

var (
unsignedV1beta1Task = &v1beta1.Task{
TypeMeta: metav1.TypeMeta{
APIVersion: "tekton.dev/v1beta1",
Kind: "Task"},
ObjectMeta: metav1.ObjectMeta{
Name: "test-task",
Namespace: "trusted-resources",
Annotations: map[string]string{"foo": "bar"},
},
Spec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{
Image: "ubuntu",
Name: "echo",
}},
},
}
unsignedV1Task = v1.Task{
TypeMeta: metav1.TypeMeta{
APIVersion: "tekton.dev/v1",
Expand Down Expand Up @@ -97,7 +113,7 @@ var (

func TestVerifyResource_Task_Success(t *testing.T) {
signer256, _, k8sclient, vps := test.SetupVerificationPolicies(t)
unsignedTask := test.GetUnsignedTask("test-task")
unsignedTask := unsignedV1beta1Task
signedTask, err := test.GetSignedV1beta1Task(unsignedTask, signer256, "signed")
if err != nil {
t.Fatal("fail to sign task", err)
Expand Down Expand Up @@ -265,7 +281,7 @@ func TestVerifyResource_Task_Error(t *testing.T) {
ctx = test.SetupTrustedResourceConfig(ctx, config.FailNoMatchPolicy)
sv, _, k8sclient, vps := test.SetupVerificationPolicies(t)

unsignedTask := test.GetUnsignedTask("test-task")
unsignedTask := unsignedV1beta1Task

signedTask, err := test.GetSignedV1beta1Task(unsignedTask, sv, "signed")
if err != nil {
Expand Down
20 changes: 0 additions & 20 deletions test/trustedresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,6 @@ var (
read = readPasswordFn
)

// GetUnsignedTask returns unsigned task with given name
func GetUnsignedTask(name string) *v1beta1.Task {
return &v1beta1.Task{
TypeMeta: metav1.TypeMeta{
APIVersion: "tekton.dev/v1beta1",
Kind: "Task"},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Annotations: map[string]string{"foo": "bar"},
},
Spec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{
Image: "ubuntu",
Name: "echo",
}},
},
}
}

// SetupTrustedResourceConfig configures the trusted-resources-verification-no-match-policy feature flag with the given mode for testing
func SetupTrustedResourceConfig(ctx context.Context, verificationNoMatchPolicy string) context.Context {
store := config.NewStore(logging.FromContext(ctx).Named("config-store"))
Expand Down
23 changes: 21 additions & 2 deletions test/trustedresources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,28 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/sigstore/sigstore/pkg/signature"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/test/diff"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var unsignedV1beta1Task = &v1beta1.Task{
TypeMeta: metav1.TypeMeta{
APIVersion: "tekton.dev/v1beta1",
Kind: "Task"},
ObjectMeta: metav1.ObjectMeta{
Name: "test-task",
Namespace: "trusted-resources",
Annotations: map[string]string{"foo": "bar"},
},
Spec: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{
Image: "ubuntu",
Name: "echo",
}},
},
}

func TestSignInterface(t *testing.T) {
sv, _, err := signature.NewDefaultECDSASignerVerifier()
if err != nil {
Expand All @@ -46,7 +65,7 @@ func TestSignInterface(t *testing.T) {
}{{
name: "Sign Task",
signer: sv,
target: GetUnsignedTask("unsigned"),
target: unsignedV1beta1Task,
wantErr: false,
}, {
name: "Sign String with cosign signer",
Expand All @@ -61,7 +80,7 @@ func TestSignInterface(t *testing.T) {
}, {
name: "Empty Signer",
signer: nil,
target: GetUnsignedTask("unsigned"),
target: unsignedV1beta1Task,
wantErr: true,
}, {
name: "Sign String with mock signer",
Expand Down
Loading