Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(approval): reject invalid roles at runtime (#20910)
boojackacc055e97627
diff --git a/backend/utils/utils.go b/backend/utils/utils.goindex dfe99ba594..4ae3484348 100644--- a/backend/utils/utils.go+++ b/backend/utils/utils.go@@ -69,6 +69,14 @@ func CheckApprovalApproved(approval *storepb.IssuePayloadApproval) (bool, error)if approval.ApprovalTemplate == nil {return true, nil}+ if approval.ApprovalTemplate.Flow == nil {+ return false, errors.Errorf("approval template flow cannot be nil")+ }+ for i, role := range approval.ApprovalTemplate.Flow.Roles {+ if strings.TrimSpace(role) == "" {+ return false, errors.Errorf("approval template role at position %d cannot be empty", i+1)+ }+ }return FindRejectedRole(approval) == "" && FindNextPendingRole(approval) == "", nil}diff --git a/backend/utils/utils_test.go b/backend/utils/utils_test.goindex 08345daf66..3c41d17032 100644--- a/backend/utils/utils_test.go+++ b/backend/utils/utils_test.go@@ -63,6 +63,7 @@ func TestCheckIssueApprovedForPlan(t *testing.T) {issue *storepb.Issueplan *storepb.PlanConfigwant bool+ wantErr string}{{name: "database change approved for matching plan version",@@ -109,6 +110,64 @@ func TestCheckIssueApprovedForPlan(t *testing.T) {plan: &storepb.PlanConfig{ApprovalInputVersion: 2},want: true,},+ {+ name: "empty approval flow skips approval",+ issueType: storepb.Issue_DATABASE_CHANGE,+ issue: &storepb.Issue{+ Approval: &storepb.IssuePayloadApproval{+ ApprovalFindingDone: true,+ ApprovalInputVersion: 2,+ ApprovalTemplate: &storepb.ApprovalTemplate{+ Flow: &storepb.ApprovalFlow{},+ },+ },+ },+ plan: &storepb.PlanConfig{ApprovalInputVersion: 2},+ want: true,+ },+ {+ name: "empty approval role is invalid",+ issueType: storepb.Issue_DATABASE_CHANGE,+ issue: &storepb.Issue{+ Approval: &storepb.IssuePayloadApproval{+ ApprovalFindingDone: true,+ ApprovalInputVersion: 2,+ ApprovalTemplate: &storepb.ApprovalTemplate{+ Flow: &storepb.ApprovalFlow{Roles: []string{""}},+ },+ },+ },+ plan: &storepb.PlanConfig{ApprovalInputVersion: 2},+ wantErr: "approval template role at position 1 cannot be empty",+ },+ {+ name: "blank approval role is invalid",+ issueType: storepb.Issue_DATABASE_CHANGE,+ issue: &storepb.Issue{+ Approval: &storepb.IssuePayloadApproval{+ ApprovalFindingDone: true,+ ApprovalInputVersion: 2,+ ApprovalTemplate: &storepb.ApprovalTemplate{+ Flow: &storepb.ApprovalFlow{Roles: []string{" "}},+ },+ },+ },+ plan: &storepb.PlanConfig{ApprovalInputVersion: 2},+ wantErr: "approval template role at position 1 cannot be empty",+ },+ {+ name: "nil approval flow is invalid",+ issueType: storepb.Issue_DATABASE_CHANGE,+ issue: &storepb.Issue{+ Approval: &storepb.IssuePayloadApproval{+ ApprovalFindingDone: true,+ ApprovalInputVersion: 2,+ ApprovalTemplate: &storepb.ApprovalTemplate{},+ },+ },+ plan: &storepb.PlanConfig{ApprovalInputVersion: 2},+ wantErr: "approval template flow cannot be nil",+ },}for _, tt := range tests {@@ -119,6 +178,11 @@ func TestCheckIssueApprovedForPlan(t *testing.T) {}, &store.PlanMessage{Config: tt.plan,})+ if tt.wantErr != "" {+ assert.ErrorContains(t, err, tt.wantErr)+ assert.False(t, got)+ return+ }assert.NoError(t, err)assert.Equal(t, tt.want, got)})