diff --git a/operator/internal/controller/stackrun_approval_test.go b/operator/internal/controller/stackrun_approval_test.go index eacc78d..28bd5c6 100644 --- a/operator/internal/controller/stackrun_approval_test.go +++ b/operator/internal/controller/stackrun_approval_test.go @@ -33,3 +33,17 @@ func TestWaitingForApproval(t *testing.T) { t.Fatal("approval wait is promote-only") } } + +func TestWaitingForApprovalRejectsBlankApprover(t *testing.T) { + run := &tektondagv1alpha1.StackRun{ + ObjectMeta: metav1.ObjectMeta{Name: "sr"}, + Spec: tektondagv1alpha1.StackRunSpec{ + Mode: tektondagv1alpha1.StackRunModePromote, + RequireApproval: true, + ApprovedBy: " \n\t ", + }, + } + if !waitingForApproval(run) { + t.Fatal("whitespace approvedBy must not release a promote") + } +} diff --git a/operator/internal/controller/stackrun_controller.go b/operator/internal/controller/stackrun_controller.go index 7a5b961..8dbf95c 100644 --- a/operator/internal/controller/stackrun_controller.go +++ b/operator/internal/controller/stackrun_controller.go @@ -20,6 +20,7 @@ import ( "context" "fmt" "strconv" + "strings" "time" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -142,7 +143,7 @@ func (r *StackRunReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c func waitingForApproval(run *tektondagv1alpha1.StackRun) bool { return run.Spec.Mode == tektondagv1alpha1.StackRunModePromote && run.Spec.RequireApproval && - run.Spec.ApprovedBy == "" + strings.TrimSpace(run.Spec.ApprovedBy) == "" } func (r *StackRunReconciler) pendingApproval(ctx context.Context, run *tektondagv1alpha1.StackRun) (ctrl.Result, error) {