Repository: kubernetes/kubernetes
File: staging/src/k8s.io/apiserver/pkg/admission/plugin/policy/validating/typechecking_test.go (Go)

Code before:
											AdditionalProperties: &spec.SchemaOrBool{Allows: true},
										},
									},
								},
							},
						},
					},
				},
			},
			assertions: []assertionFunc{toBeEmpty},
		},
		{
			name:           "schema without type",
			policy:         noTypeSchemaPolicy,
			schemaToReturn: &spec.Schema{},
			assertions:     []assertionFunc{toBeEmpty},
		},
		{
			name: "variables valid",
			policy: &v1.ValidatingAdmissionPolicy{Spec: v1.ValidatingAdmissionPolicySpec{
				Variables: []v1.Variable{
					{
						Name:       "works",
						Expression: "true",
					},
				},
				Validations: []v1.Validation{
					{
						Expression: "variables.works",
					},
				},
				MatchConstraints: deploymentPolicy.Spec.MatchConstraints,
			},
			},
			schemaToReturn: &spec.Schema{
				SchemaProps: spec.SchemaProps{
					Type: []string{"object"},
					Properties: map[string]spec.Schema{
						"foo": *spec.Int64Property(),
					},
				},
			},
			assertions: []assertionFunc{toHaveLengthOf(0)},
		},
		{
			name: "variables missing field",
			policy: &v1.ValidatingAdmissionPolicy{Spec: v1.ValidatingAdmissionPolicySpec{
				Variables: []v1.Variable{
					{
						Name:       "works",
						Expression: "true",

Review comment (suggestion):
Please add a test case that verifies `params` availability with an untyped schema. This ensures the variable falls back to `Dyn` instead of being undeclared.

```go
		{
			name: "params with untyped schema",
			policy: &v1.ValidatingAdmissionPolicy{Spec: v1.ValidatingAdmissionPolicySpec{
				ParamKind: &v1.ParamKind{
					APIVersion: "v1",
					Kind:       "Config",
				},
				Validations: []v1.Validation{
					{
						Expression: "params != null", // Should pass check
					},
				},
				MatchConstraints: deploymentPolicy.Spec.MatchConstraints,
			}},
			schemaToReturn: &spec.Schema{}, // Untyped
			assertions:     []assertionFunc{toBeEmpty},
		},
```

Code after:
					Type: []string{"object"},
					Properties: map[string]spec.Schema{
						"spec": {
							SchemaProps: spec.SchemaProps{
								Type: []string{"object"},
								Properties: map[string]spec.Schema{
									"text": *spec.StringProperty(),
								},
							},
						},
						"status": {
							SchemaProps: spec.SchemaProps{
								Type: []string{"object"},
								Properties: map[string]spec.Schema{
									"problematicProperty": {
										SchemaProps: spec.SchemaProps{
											Type:                 []string{"object"},
											AdditionalProperties: &spec.SchemaOrBool{Allows: true},
										},
									},
								},
							},
						},
					},
				},
			},
			assertions: []assertionFunc{toBeEmpty},
		},
		{
			name:           "schema without type",
			policy:         noTypeSchemaPolicy,
			schemaToReturn: &spec.Schema{},
			assertions:     []assertionFunc{toBeEmpty},
		},
		{
			name: "variables valid",
			policy: &v1.ValidatingAdmissionPolicy{Spec: v1.ValidatingAdmissionPolicySpec{
				Variables: []v1.Variable{
					{
						Name:       "works",
						Expression: "true",
					},
				},
				Validations: []v1.Validation{
					{
						Expression: "variables.works",
					},
				},
				MatchConstraints: deploymentPolicy.Spec.MatchConstraints,
			},
			},