Skip to content

Commit

Permalink
Add test coverage of result size of string operations
Browse files Browse the repository at this point in the history
Kubernetes-commit: ab26637eae47f953190a4d93a7f6155e3b7e89cc
  • Loading branch information
jpbetz authored and k8s-publishing-bot committed Aug 7, 2023
1 parent 3f6c83c commit 0404ad2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
26 changes: 26 additions & 0 deletions pkg/apis/apiextensions/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9315,6 +9315,32 @@ func TestValidateCustomResourceDefinitionValidation(t *testing.T) {
forbidden("spec.validation.openAPIV3Schema.properties[f].x-kubernetes-validations[0].messageExpression"),
},
},
{
name: "x-kubernetes-validations rule with lowerAscii check should be within estimated cost limit",
opts: validationOptions{requireStructuralSchema: true},
input: apiextensions.CustomResourceValidation{
OpenAPIV3Schema: &apiextensions.JSONSchemaProps{
Type: "object",
Properties: map[string]apiextensions.JSONSchemaProps{
"f": {
Type: "array",
MaxItems: pointer.Int64(5),
Items: &apiextensions.JSONSchemaPropsOrArray{
Schema: &apiextensions.JSONSchemaProps{
Type: "string",
MaxLength: pointer.Int64(5),
},
},
XValidations: apiextensions.ValidationRules{
{
Rule: "self.all(x, self.exists_one(y, x.lowerAscii() == y.lowerAscii()))",
},
},
},
},
},
},
},
{
name: "x-kubernetes-validations rule invalidated by messageExpression exceeding per-CRD estimated cost limit",
opts: validationOptions{requireStructuralSchema: true},
Expand Down
1 change: 1 addition & 0 deletions pkg/apiserver/schema/cel/celcoststability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func TestCelCostStability(t *testing.T) {
"self.val1.substring(4, 10).trim() == 'takes'": 6,
"self.val1.upperAscii() == 'ROOK TAKES 👑'": 6,
"self.val1.lowerAscii() == 'rook takes 👑'": 6,
"self.val1.lowerAscii() == self.val1.lowerAscii()": 10,
},
},
{name: "escaped strings",
Expand Down
6 changes: 3 additions & 3 deletions pkg/apiserver/schema/cel/compilation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1688,12 +1688,12 @@ func TestCostEstimation(t *testing.T) {
"before": strType,
"after": strType,
})
objType = withRule(objType, "self.str.replace(self.before, self.after) == 'does not matter'")
objType = withRule(objType, "self.str.replace(self.before, self.after) == '0123456789'")
return &objType
},
expectedCalcCost: 629154,
expectedCalcCost: 629152,
setMaxElements: 10,
expectedSetCost: 16,
expectedSetCost: 14,
},
{
name: "extended library split",
Expand Down

0 comments on commit 0404ad2

Please sign in to comment.