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

Add validation for array indexing in finally when expressions #6638

Merged
merged 1 commit into from
May 9, 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
1 change: 1 addition & 0 deletions pkg/apis/pipeline/v1/pipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ func (ps *PipelineSpec) ValidateParamArrayIndex(ctx context.Context, params Para
paramsRefs = append(paramsRefs, ps.Finally[i].Matrix.Params.extractValues()...)
}
for _, wes := range ps.Finally[i].When {
paramsRefs = append(paramsRefs, wes.Input)
paramsRefs = append(paramsRefs, wes.Values...)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1/pipeline_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3573,14 +3573,14 @@ func TestValidateParamArrayIndex_invalid(t *testing.T) {
{Name: "final-task-second-param", Value: *NewStructuredValues("$(params.second-param[2])")},
},
When: WhenExpressions{{
Input: "$(params.first-param[0])",
Input: "$(params.first-param[5])",
Operator: selection.In,
Values: []string{"$(params.second-param[1])"},
}},
}},
},
params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}},
expected: fmt.Errorf("non-existent param references:[$(params.first-param[2]) $(params.second-param[2])]"),
expected: fmt.Errorf("non-existent param references:[$(params.first-param[2]) $(params.first-param[5]) $(params.second-param[2])]"),
}, {
name: "parameter evaluation with both tasks and final tasks reference out of bound",
original: PipelineSpec{
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/pipeline/v1beta1/pipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ func (ps *PipelineSpec) ValidateParamArrayIndex(ctx context.Context, params Para
paramsRefs = append(paramsRefs, ps.Finally[i].Matrix.Params.extractValues()...)
}
for _, wes := range ps.Finally[i].WhenExpressions {
paramsRefs = append(paramsRefs, wes.Input)
paramsRefs = append(paramsRefs, wes.Values...)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1beta1/pipeline_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3633,14 +3633,14 @@ func TestValidateParamArrayIndex_invalid(t *testing.T) {
{Name: "final-task-second-param", Value: *NewStructuredValues("$(params.second-param[2])")},
},
WhenExpressions: WhenExpressions{{
Input: "$(params.first-param[0])",
Input: "$(params.first-param[5])",
Operator: selection.In,
Values: []string{"$(params.second-param[1])"},
}},
}},
},
params: Params{{Name: "second-param", Value: *NewStructuredValues("second-value", "second-value-again")}},
expected: fmt.Errorf("non-existent param references:[$(params.first-param[2]) $(params.second-param[2])]"),
expected: fmt.Errorf("non-existent param references:[$(params.first-param[2]) $(params.first-param[5]) $(params.second-param[2])]"),
}, {
name: "parameter evaluation with both tasks and final tasks reference out of bound",
original: PipelineSpec{
Expand Down