| 1 |
// Copyright 2023-2026 Princess Beef Heavy Industries, LLC / Dave Shanley |
| 2 |
// https://pb33f.io |
| 3 |
|
| 4 |
package errors |
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
"testing" |
| 9 |
|
| 10 |
"github.com/pb33f/libopenapi/datamodel/high/base" |
| 11 |
"github.com/pb33f/libopenapi/datamodel/low" |
| 12 |
"github.com/pb33f/libopenapi/orderedmap" |
| 13 |
"github.com/stretchr/testify/require" |
| 14 |
"go.yaml.in/yaml/v4" |
| 15 |
|
| 16 |
v3 "github.com/pb33f/libopenapi/datamodel/high/v3" |
| 17 |
lowbase "github.com/pb33f/libopenapi/datamodel/low/base" |
| 18 |
lowv3 "github.com/pb33f/libopenapi/datamodel/low/v3" |
| 19 |
|
| 20 |
"github.com/pb33f/libopenapi-validator/helpers" |
| 21 |
) |
| 22 |
|
| 23 |
// Helper to create a mock v3.Parameter object with a schema |
| 24 |
func createMockParameterWithSchema() *v3.Parameter { |
| 25 |
schemaProxy := &lowbase.SchemaProxy{} |
| 26 |
_ = schemaProxy.Build(context.Background(), &yaml.Node{}, &yaml.Node{}, nil) |
| 27 |
schemaProxy.Schema().Type = low.NodeReference[lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]]{ |
| 28 |
KeyNode: &yaml.Node{}, |
| 29 |
ValueNode: &yaml.Node{}, |
| 30 |
Value: lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]{ |
| 31 |
A: "string", |
| 32 |
}, |
| 33 |
} |
| 34 |
schemaProxy.Schema().Enum = low.NodeReference[[]low.ValueReference[*yaml.Node]]{ |
| 35 |
KeyNode: &yaml.Node{Line: 10, Column: 20}, |
| 36 |
ValueNode: &yaml.Node{}, |
| 37 |
Value: []low.ValueReference[*yaml.Node]{ |
| 38 |
{Value: &yaml.Node{Value: "enum1"}}, |
| 39 |
{Value: &yaml.Node{Value: "enum2"}}, |
| 40 |
}, |
| 41 |
} |
| 42 |
|
| 43 |
param := &lowv3.Parameter{ |
| 44 |
Name: low.NodeReference[string]{Value: "testParam"}, |
| 45 |
Schema: low.NodeReference[*lowbase.SchemaProxy]{Value: schemaProxy}, |
| 46 |
Style: low.NodeReference[string]{Value: "form", KeyNode: &yaml.Node{Line: 15, Column: 25}, ValueNode: &yaml.Node{}}, |
| 47 |
Explode: low.NodeReference[bool]{Value: false, ValueNode: &yaml.Node{Line: 18, Column: 30}, KeyNode: &yaml.Node{}}, |
| 48 |
Required: low.NodeReference[bool]{ |
| 49 |
KeyNode: &yaml.Node{Line: 22, Column: 32}, |
| 50 |
ValueNode: &yaml.Node{}, |
| 51 |
}, |
| 52 |
KeyNode: &yaml.Node{}, |
| 53 |
} |
| 54 |
return v3.NewParameter(param) |
| 55 |
} |
| 56 |
|
| 57 |
func TestIncorrectFormEncoding(t *testing.T) { |
| 58 |
param := createMockParameterWithSchema() |
| 59 |
qp := &helpers.QueryParam{ |
| 60 |
Key: "testParam", |
| 61 |
Values: []string{"incorrect,value"}, |
| 62 |
} |
| 63 |
|
| 64 |
// Call the function |
| 65 |
err := IncorrectFormEncoding(param, qp, 0) |
| 66 |
|
| 67 |
// Validate the error |
| 68 |
require.NotNil(t, err) |
| 69 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 70 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 71 |
require.Equal(t, "testParam", err.ParameterName) |
| 72 |
require.Contains(t, err.Message, "Query parameter 'testParam' is not exploded correctly") |
| 73 |
require.Contains(t, err.Reason, "'testParam' has a default or 'form' encoding defined") |
| 74 |
require.Equal(t, 18, err.SpecLine) |
| 75 |
require.Equal(t, 30, err.SpecCol) |
| 76 |
require.Contains(t, err.HowToFix, "&testParam=incorrect&testParam=value'") |
| 77 |
} |
| 78 |
|
| 79 |
func TestIncorrectSpaceDelimiting(t *testing.T) { |
| 80 |
param := createMockParameterWithSchema() |
| 81 |
qp := &helpers.QueryParam{ |
| 82 |
Key: "testParam", |
| 83 |
Values: []string{"value1", "value2"}, |
| 84 |
} |
| 85 |
|
| 86 |
// create a low level query parameter |
| 87 |
|
| 88 |
// Call the function |
| 89 |
err := IncorrectSpaceDelimiting(param, qp) |
| 90 |
|
| 91 |
// Validate the error |
| 92 |
require.NotNil(t, err) |
| 93 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 94 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 95 |
require.Equal(t, "testParam", err.ParameterName) |
| 96 |
require.Contains(t, err.Message, "Query parameter 'testParam' delimited incorrectly") |
| 97 |
require.Contains(t, err.Reason, "'spaceDelimited' style defined") |
| 98 |
require.Contains(t, err.HowToFix, "testParam=value1%20value2") |
| 99 |
} |
| 100 |
|
| 101 |
func TestIncorrectPipeDelimiting(t *testing.T) { |
| 102 |
param := createMockParameterWithSchema() |
| 103 |
qp := &helpers.QueryParam{ |
| 104 |
Key: "testParam", |
| 105 |
Values: []string{"value1", "value2"}, |
| 106 |
} |
| 107 |
|
| 108 |
// Call the function |
| 109 |
err := IncorrectPipeDelimiting(param, qp) |
| 110 |
|
| 111 |
// Validate the error |
| 112 |
require.NotNil(t, err) |
| 113 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 114 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 115 |
require.Equal(t, "testParam", err.ParameterName) |
| 116 |
require.Contains(t, err.Message, "Query parameter 'testParam' delimited incorrectly") |
| 117 |
require.Contains(t, err.Reason, "'pipeDelimited' style defined") |
| 118 |
require.Contains(t, err.HowToFix, "testParam=value1|value2") |
| 119 |
} |
| 120 |
|
| 121 |
func TestQueryParameterMissing(t *testing.T) { |
| 122 |
param := createMockParameterWithSchema() |
| 123 |
|
| 124 |
// Call the function |
| 125 |
err := QueryParameterMissing(param, "/test-path", "get", "{}") |
| 126 |
|
| 127 |
// Validate the error |
| 128 |
require.NotNil(t, err) |
| 129 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 130 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 131 |
require.Equal(t, "testParam", err.ParameterName) |
| 132 |
require.Contains(t, err.Message, "Query parameter 'testParam' is missing") |
| 133 |
require.Contains(t, err.Reason, "'testParam' is defined as being required") |
| 134 |
require.Equal(t, HowToFixMissingValue, err.HowToFix) |
| 135 |
} |
| 136 |
|
| 137 |
func TestHeaderParameterMissing(t *testing.T) { |
| 138 |
param := createMockParameterWithSchema() |
| 139 |
|
| 140 |
// Call the function |
| 141 |
err := HeaderParameterMissing(param, "/test-path", "get", "{}") |
| 142 |
|
| 143 |
// Validate the error |
| 144 |
require.NotNil(t, err) |
| 145 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 146 |
require.Equal(t, helpers.ParameterValidationHeader, err.ValidationSubType) |
| 147 |
require.Equal(t, "testParam", err.ParameterName) |
| 148 |
require.Contains(t, err.Message, "Header parameter 'testParam' is missing") |
| 149 |
require.Contains(t, err.Reason, "'testParam' is defined as being required") |
| 150 |
require.Equal(t, HowToFixMissingValue, err.HowToFix) |
| 151 |
} |
| 152 |
|
| 153 |
func TestCookieParameterMissing(t *testing.T) { |
| 154 |
param := createMockParameterWithSchema() |
| 155 |
|
| 156 |
// Call the function |
| 157 |
err := CookieParameterMissing(param, "/test", "get", "") |
| 158 |
|
| 159 |
// Validate the error |
| 160 |
require.NotNil(t, err) |
| 161 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 162 |
require.Equal(t, helpers.ParameterValidationCookie, err.ValidationSubType) |
| 163 |
require.Equal(t, "testParam", err.ParameterName) |
| 164 |
require.Contains(t, err.Message, "Cookie parameter 'testParam' is missing") |
| 165 |
require.Contains(t, err.Reason, "'testParam' is defined as being required") |
| 166 |
require.Equal(t, HowToFixMissingValue, err.HowToFix) |
| 167 |
} |
| 168 |
|
| 169 |
func TestHeaderParameterCannotBeDecoded(t *testing.T) { |
| 170 |
param := createMockParameterWithSchema() |
| 171 |
val := "malformed_header_value" |
| 172 |
|
| 173 |
// Call the function |
| 174 |
err := HeaderParameterCannotBeDecoded(param, val, "/test-path", "get", "{}") |
| 175 |
|
| 176 |
// Validate the error |
| 177 |
require.NotNil(t, err) |
| 178 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 179 |
require.Equal(t, helpers.ParameterValidationHeader, err.ValidationSubType) |
| 180 |
require.Equal(t, "testParam", err.ParameterName) |
| 181 |
require.Contains(t, err.Message, "Header parameter 'testParam' cannot be decoded") |
| 182 |
require.Contains(t, err.Reason, "'malformed_header_value' is malformed") |
| 183 |
require.Equal(t, HowToFixInvalidEncoding, err.HowToFix) |
| 184 |
} |
| 185 |
|
| 186 |
func TestIncorrectHeaderParamEnum(t *testing.T) { |
| 187 |
param := createMockParameterWithSchema() |
| 188 |
schemaProxy := &lowbase.SchemaProxy{} |
| 189 |
require.NoError(t, schemaProxy.Build(context.Background(), &yaml.Node{}, &yaml.Node{}, nil)) |
| 190 |
schemaProxy.Schema().Type = low.NodeReference[lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]]{ |
| 191 |
KeyNode: &yaml.Node{}, |
| 192 |
ValueNode: &yaml.Node{}, |
| 193 |
Value: lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]{ |
| 194 |
A: "string", |
| 195 |
}, |
| 196 |
} |
| 197 |
schemaProxy.Schema().Enum = low.NodeReference[[]low.ValueReference[*yaml.Node]]{ |
| 198 |
KeyNode: &yaml.Node{Line: 10, Column: 20}, |
| 199 |
ValueNode: &yaml.Node{}, |
| 200 |
Value: []low.ValueReference[*yaml.Node]{ |
| 201 |
{Value: &yaml.Node{Value: "enum1"}}, |
| 202 |
{Value: &yaml.Node{Value: "enum2"}}, |
| 203 |
}, |
| 204 |
} |
| 205 |
|
| 206 |
s := schemaProxy.Schema() |
| 207 |
|
| 208 |
// build a high level schema from the low level one |
| 209 |
schema := base.NewSchema(s) |
| 210 |
|
| 211 |
// Call the function with an invalid enum value |
| 212 |
err := IncorrectHeaderParamEnum(param, "invalidEnum", schema, "/test-path", "get", "{}") |
| 213 |
|
| 214 |
// Validate the error |
| 215 |
require.NotNil(t, err) |
| 216 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 217 |
require.Equal(t, helpers.ParameterValidationHeader, err.ValidationSubType) |
| 218 |
require.Equal(t, "testParam", err.ParameterName) |
| 219 |
require.Contains(t, err.Message, "Header parameter 'testParam' does not match allowed values") |
| 220 |
require.Contains(t, err.Reason, "'invalidEnum' is not one of those values") |
| 221 |
require.Equal(t, 10, err.SpecLine) |
| 222 |
require.Equal(t, 20, err.SpecCol) |
| 223 |
require.Contains(t, err.HowToFix, "enum1, enum2") |
| 224 |
} |
| 225 |
|
| 226 |
func TestIncorrectQueryParamArrayBoolean(t *testing.T) { |
| 227 |
param := createMockParameterWithSchema() |
| 228 |
schemaProxy := &lowbase.SchemaProxy{} |
| 229 |
require.NoError(t, schemaProxy.Build(context.Background(), &yaml.Node{}, &yaml.Node{}, nil)) |
| 230 |
schemaProxy.Schema().Type = low.NodeReference[lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]]{ |
| 231 |
KeyNode: &yaml.Node{}, |
| 232 |
ValueNode: &yaml.Node{}, |
| 233 |
Value: lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]{ |
| 234 |
A: "string", |
| 235 |
}, |
| 236 |
} |
| 237 |
schemaProxy.Schema().Items = low.NodeReference[*lowbase.SchemaDynamicValue[*lowbase.SchemaProxy, bool]]{ |
| 238 |
KeyNode: &yaml.Node{Line: 30, Column: 40}, |
| 239 |
ValueNode: &yaml.Node{}, |
| 240 |
Value: &lowbase.SchemaDynamicValue[*lowbase.SchemaProxy, bool]{A: schemaProxy}, |
| 241 |
} |
| 242 |
|
| 243 |
s := schemaProxy.Schema() |
| 244 |
|
| 245 |
// build a high level schema from the low level one |
| 246 |
schema := base.NewSchema(s) |
| 247 |
|
| 248 |
// Call the function with an invalid boolean value in the array |
| 249 |
err := IncorrectQueryParamArrayBoolean(param, "notBoolean", schema, schema.Items.A.Schema(), "/test-path", "get", "{}") |
| 250 |
|
| 251 |
// Validate the error |
| 252 |
require.NotNil(t, err) |
| 253 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 254 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 255 |
require.Equal(t, "testParam", err.ParameterName) |
| 256 |
require.Contains(t, err.Message, "Query array parameter 'testParam' is not a valid boolean") |
| 257 |
require.Contains(t, err.Reason, "the value 'notBoolean' is not a valid true/false value") |
| 258 |
require.Contains(t, err.HowToFix, "true/false") |
| 259 |
} |
| 260 |
|
| 261 |
// Helper function to create a mock v3.Parameter with deepObject style |
| 262 |
func createMockParameterWithDeepObjectStyle() *v3.Parameter { |
| 263 |
param := &lowv3.Parameter{ |
| 264 |
Name: low.NodeReference[string]{Value: "testParam"}, |
| 265 |
Style: low.NodeReference[string]{Value: "deepObject", KeyNode: &yaml.Node{Line: 12, Column: 22}, ValueNode: &yaml.Node{}}, // Correct ValueNode set |
| 266 |
Explode: low.NodeReference[bool]{Value: false}, |
| 267 |
} |
| 268 |
return v3.NewParameter(param) |
| 269 |
} |
| 270 |
|
| 271 |
func TestInvalidDeepObject(t *testing.T) { |
| 272 |
param := createMockParameterWithDeepObjectStyle() |
| 273 |
|
| 274 |
// Create a mock query parameter with multiple values |
| 275 |
qp := &helpers.QueryParam{ |
| 276 |
Key: "testParam", |
| 277 |
Values: []string{"value1", "value2"}, |
| 278 |
} |
| 279 |
|
| 280 |
// Call the function |
| 281 |
err := InvalidDeepObject(param, qp) |
| 282 |
|
| 283 |
// Validate the error |
| 284 |
require.NotNil(t, err) |
| 285 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 286 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 287 |
require.Equal(t, "testParam", err.ParameterName) |
| 288 |
require.Contains(t, err.Message, "Query parameter 'testParam' is not a valid deepObject") |
| 289 |
require.Contains(t, err.Reason, "'testParam' has the 'deepObject' style defined") |
| 290 |
require.Contains(t, err.HowToFix, "testParam=value1|value2") |
| 291 |
} |
| 292 |
|
| 293 |
func TestInvalidDeepObjectPathConflict(t *testing.T) { |
| 294 |
param := createMockParameterWithDeepObjectStyle() |
| 295 |
prefixParam := &helpers.QueryParam{ |
| 296 |
Key: "testParam", |
| 297 |
Values: []string{"bad"}, |
| 298 |
Property: "nested", |
| 299 |
PropertyPath: []string{"nested"}, |
| 300 |
} |
| 301 |
nestedParam := &helpers.QueryParam{ |
| 302 |
Key: "testParam", |
| 303 |
Values: []string{"ok"}, |
| 304 |
Property: "nested", |
| 305 |
PropertyPath: []string{"nested", "child"}, |
| 306 |
} |
| 307 |
|
| 308 |
err := InvalidDeepObjectPathConflict(param, prefixParam, nestedParam) |
| 309 |
|
| 310 |
require.NotNil(t, err) |
| 311 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 312 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 313 |
require.Equal(t, "testParam", err.ParameterName) |
| 314 |
require.Contains(t, err.Message, "Query parameter 'testParam' is not a valid deepObject") |
| 315 |
require.Contains(t, err.Reason, "property path 'nested'") |
| 316 |
require.Contains(t, err.Reason, "'nested.child'") |
| 317 |
require.Contains(t, err.HowToFix, "testParam[nested]") |
| 318 |
require.Contains(t, err.HowToFix, "testParam[nested][child]") |
| 319 |
} |
| 320 |
|
| 321 |
func TestInvalidDeepObjectPathConflict_NilPaths(t *testing.T) { |
| 322 |
param := createMockParameterWithDeepObjectStyle() |
| 323 |
|
| 324 |
err := InvalidDeepObjectPathConflict(param, nil, nil) |
| 325 |
|
| 326 |
require.NotNil(t, err) |
| 327 |
require.Contains(t, err.Reason, "property path ''") |
| 328 |
require.Contains(t, err.HowToFix, "testParam[]") |
| 329 |
} |
| 330 |
|
| 331 |
func TestInvalidDeepObjectPathConflict_PropertyFallback(t *testing.T) { |
| 332 |
param := createMockParameterWithDeepObjectStyle() |
| 333 |
prefixParam := &helpers.QueryParam{ |
| 334 |
Key: "testParam", |
| 335 |
Values: []string{"bad"}, |
| 336 |
Property: "nested", |
| 337 |
} |
| 338 |
nestedParam := &helpers.QueryParam{ |
| 339 |
Key: "testParam", |
| 340 |
Values: []string{"ok"}, |
| 341 |
Property: "nested.child", |
| 342 |
} |
| 343 |
|
| 344 |
err := InvalidDeepObjectPathConflict(param, prefixParam, nestedParam) |
| 345 |
|
| 346 |
require.NotNil(t, err) |
| 347 |
require.Contains(t, err.Reason, "property path 'nested'") |
| 348 |
require.Contains(t, err.Reason, "'nested.child'") |
| 349 |
require.Contains(t, err.HowToFix, "testParam[nested]") |
| 350 |
require.Contains(t, err.HowToFix, "testParam[nested.child]") |
| 351 |
} |
| 352 |
|
| 353 |
func createMockParameterForBooleanArray() *v3.Parameter { |
| 354 |
param := &lowv3.Parameter{ |
| 355 |
Name: low.NodeReference[string]{Value: "testCookieParam"}, |
| 356 |
} |
| 357 |
return v3.NewParameter(param) |
| 358 |
} |
| 359 |
|
| 360 |
// Helper function to create a mock base.Schema with boolean items schema |
| 361 |
func createMockLowBaseSchemaForBooleanArray() *lowbase.Schema { |
| 362 |
itemsSchema := &lowbase.Schema{ |
| 363 |
Type: low.NodeReference[lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]]{ |
| 364 |
Value: lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]{ |
| 365 |
A: "boolean", |
| 366 |
}, |
| 367 |
KeyNode: &yaml.Node{}, |
| 368 |
ValueNode: &yaml.Node{}, |
| 369 |
}, |
| 370 |
} |
| 371 |
|
| 372 |
schemaProxy := &lowbase.SchemaProxy{} |
| 373 |
|
| 374 |
itemsSchema.Items = low.NodeReference[*lowbase.SchemaDynamicValue[*lowbase.SchemaProxy, bool]]{ |
| 375 |
Value: &lowbase.SchemaDynamicValue[*lowbase.SchemaProxy, bool]{ |
| 376 |
A: schemaProxy, |
| 377 |
}, |
| 378 |
KeyNode: &yaml.Node{}, |
| 379 |
ValueNode: &yaml.Node{}, |
| 380 |
} |
| 381 |
|
| 382 |
_ = schemaProxy.Build(context.Background(), &yaml.Node{}, &yaml.Node{}, nil) |
| 383 |
schemaProxy.Schema().Type = low.NodeReference[lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]]{ |
| 384 |
KeyNode: &yaml.Node{}, |
| 385 |
ValueNode: &yaml.Node{}, |
| 386 |
Value: lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]{ |
| 387 |
A: "string", |
| 388 |
}, |
| 389 |
} |
| 390 |
|
| 391 |
return itemsSchema |
| 392 |
} |
| 393 |
|
| 394 |
func TestIncorrectCookieParamArrayBoolean(t *testing.T) { |
| 395 |
// Create mock parameter and schemas |
| 396 |
param := createMockParameterForBooleanArray() |
| 397 |
baseSchema := createMockLowBaseSchemaForBooleanArray() |
| 398 |
s := base.NewSchema(baseSchema) |
| 399 |
itemsSchema := base.NewSchema(baseSchema.Items.Value.A.Schema()) |
| 400 |
|
| 401 |
// Call the function with an invalid boolean value in the array |
| 402 |
err := IncorrectCookieParamArrayBoolean(param, "notBoolean", s, itemsSchema, "/test-path", "get", "{}") |
| 403 |
|
| 404 |
// Validate the error |
| 405 |
require.NotNil(t, err) |
| 406 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 407 |
require.Equal(t, helpers.ParameterValidationCookie, err.ValidationSubType) |
| 408 |
require.Equal(t, "testCookieParam", err.ParameterName) |
| 409 |
require.Contains(t, err.Message, "Cookie array parameter 'testCookieParam' is not a valid boolean") |
| 410 |
require.Contains(t, err.Reason, "the value 'notBoolean' is not a valid true/false value") |
| 411 |
require.Contains(t, err.HowToFix, "true/false") |
| 412 |
} |
| 413 |
|
| 414 |
// Helper function to create a mock v3.Parameter for number array validation |
| 415 |
func createMockParameterForNumberArray() *v3.Parameter { |
| 416 |
param := &lowv3.Parameter{ |
| 417 |
Name: low.NodeReference[string]{Value: "testQueryParam"}, |
| 418 |
} |
| 419 |
return v3.NewParameter(param) |
| 420 |
} |
| 421 |
|
| 422 |
// Helper function to create a mock base.Schema with number items schema |
| 423 |
func createMockLowBaseSchemaForNumberArray() *lowbase.Schema { |
| 424 |
itemsSchema := &lowbase.Schema{ |
| 425 |
Type: low.NodeReference[lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]]{ |
| 426 |
Value: lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]{ |
| 427 |
A: "number", |
| 428 |
}, |
| 429 |
KeyNode: &yaml.Node{}, |
| 430 |
ValueNode: &yaml.Node{}, |
| 431 |
}, |
| 432 |
} |
| 433 |
|
| 434 |
schemaProxy := &lowbase.SchemaProxy{} |
| 435 |
|
| 436 |
itemsSchema.Items = low.NodeReference[*lowbase.SchemaDynamicValue[*lowbase.SchemaProxy, bool]]{ |
| 437 |
Value: &lowbase.SchemaDynamicValue[*lowbase.SchemaProxy, bool]{ |
| 438 |
A: schemaProxy, |
| 439 |
}, |
| 440 |
KeyNode: &yaml.Node{}, |
| 441 |
ValueNode: &yaml.Node{}, |
| 442 |
} |
| 443 |
|
| 444 |
_ = schemaProxy.Build(context.Background(), &yaml.Node{}, &yaml.Node{}, nil) |
| 445 |
schemaProxy.Schema().Type = low.NodeReference[lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]]{ |
| 446 |
KeyNode: &yaml.Node{}, |
| 447 |
ValueNode: &yaml.Node{}, |
| 448 |
Value: lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]{ |
| 449 |
A: "string", |
| 450 |
}, |
| 451 |
} |
| 452 |
|
| 453 |
return itemsSchema |
| 454 |
} |
| 455 |
|
| 456 |
func TestIncorrectQueryParamArrayInteger(t *testing.T) { |
| 457 |
// Create mock parameter and schemas |
| 458 |
param := createMockParameterForNumberArray() |
| 459 |
baseSchema := createMockLowBaseSchemaForNumberArray() |
| 460 |
s := base.NewSchema(baseSchema) |
| 461 |
itemsSchema := base.NewSchema(baseSchema.Items.Value.A.Schema()) |
| 462 |
|
| 463 |
// Call the function with an invalid number value in the array |
| 464 |
err := IncorrectQueryParamArrayInteger(param, "notNumber", s, itemsSchema, "/test-path", "get", "{}") |
| 465 |
|
| 466 |
// Validate the error |
| 467 |
require.NotNil(t, err) |
| 468 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 469 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 470 |
require.Equal(t, "testQueryParam", err.ParameterName) |
| 471 |
require.Contains(t, err.Message, "Query array parameter 'testQueryParam' is not a valid integer") |
| 472 |
require.Contains(t, err.Reason, "the value 'notNumber' is not a valid integer") |
| 473 |
require.Contains(t, err.HowToFix, "notNumber") |
| 474 |
} |
| 475 |
|
| 476 |
func TestIncorrectQueryParamArrayNumber(t *testing.T) { |
| 477 |
// Create mock parameter and schemas |
| 478 |
param := createMockParameterForNumberArray() |
| 479 |
baseSchema := createMockLowBaseSchemaForNumberArray() |
| 480 |
s := base.NewSchema(baseSchema) |
| 481 |
itemsSchema := base.NewSchema(baseSchema.Items.Value.A.Schema()) |
| 482 |
|
| 483 |
// Call the function with an invalid number value in the array |
| 484 |
err := IncorrectQueryParamArrayNumber(param, "notNumber", s, itemsSchema, "/test-path", "get", "{}") |
| 485 |
|
| 486 |
// Validate the error |
| 487 |
require.NotNil(t, err) |
| 488 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 489 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 490 |
require.Equal(t, "testQueryParam", err.ParameterName) |
| 491 |
require.Contains(t, err.Message, "Query array parameter 'testQueryParam' is not a valid number") |
| 492 |
require.Contains(t, err.Reason, "the value 'notNumber' is not a valid number") |
| 493 |
require.Contains(t, err.HowToFix, "notNumber") |
| 494 |
} |
| 495 |
|
| 496 |
// Helper function to create a mock v3.Parameter for cookie number array validation |
| 497 |
func createMockParameterForCookieNumberArray() *v3.Parameter { |
| 498 |
param := &lowv3.Parameter{ |
| 499 |
Name: low.NodeReference[string]{Value: "testCookieParam"}, |
| 500 |
} |
| 501 |
return v3.NewParameter(param) |
| 502 |
} |
| 503 |
|
| 504 |
// Helper function to create a mock base.Schema with number items schema |
| 505 |
func createMockLowBaseSchemaForCookieNumberArray() *lowbase.Schema { |
| 506 |
itemsSchema := &lowbase.Schema{ |
| 507 |
Type: low.NodeReference[lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]]{ |
| 508 |
Value: lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]{ |
| 509 |
A: "number", |
| 510 |
}, |
| 511 |
KeyNode: &yaml.Node{}, |
| 512 |
ValueNode: &yaml.Node{}, |
| 513 |
}, |
| 514 |
} |
| 515 |
|
| 516 |
schemaProxy := &lowbase.SchemaProxy{} |
| 517 |
|
| 518 |
itemsSchema.Items = low.NodeReference[*lowbase.SchemaDynamicValue[*lowbase.SchemaProxy, bool]]{ |
| 519 |
Value: &lowbase.SchemaDynamicValue[*lowbase.SchemaProxy, bool]{ |
| 520 |
A: schemaProxy, |
| 521 |
}, |
| 522 |
KeyNode: &yaml.Node{}, |
| 523 |
ValueNode: &yaml.Node{}, |
| 524 |
} |
| 525 |
|
| 526 |
_ = schemaProxy.Build(context.Background(), &yaml.Node{}, &yaml.Node{}, nil) |
| 527 |
schemaProxy.Schema().Type = low.NodeReference[lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]]{ |
| 528 |
KeyNode: &yaml.Node{}, |
| 529 |
ValueNode: &yaml.Node{}, |
| 530 |
Value: lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]{ |
| 531 |
A: "string", |
| 532 |
}, |
| 533 |
} |
| 534 |
|
| 535 |
return itemsSchema |
| 536 |
} |
| 537 |
|
| 538 |
func TestIncorrectCookieParamArrayNumber(t *testing.T) { |
| 539 |
// Create mock parameter and schemas |
| 540 |
param := createMockParameterForCookieNumberArray() |
| 541 |
baseSchema := createMockLowBaseSchemaForCookieNumberArray() |
| 542 |
s := base.NewSchema(baseSchema) |
| 543 |
itemsSchema := base.NewSchema(baseSchema.Items.Value.A.Schema()) |
| 544 |
|
| 545 |
// Call the function with an invalid number value in the cookie array |
| 546 |
err := IncorrectCookieParamArrayNumber(param, "notNumber", s, itemsSchema, "/test-path", "get", "{}") |
| 547 |
|
| 548 |
// Validate the error |
| 549 |
require.NotNil(t, err) |
| 550 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 551 |
require.Equal(t, helpers.ParameterValidationCookie, err.ValidationSubType) |
| 552 |
require.Equal(t, "testCookieParam", err.ParameterName) |
| 553 |
require.Contains(t, err.Message, "Cookie array parameter 'testCookieParam' is not a valid number") |
| 554 |
require.Contains(t, err.Reason, "the value 'notNumber' is not a valid number") |
| 555 |
require.Contains(t, err.HowToFix, "notNumber") |
| 556 |
} |
| 557 |
|
| 558 |
// Helper function to create a mock v3.Parameter |
| 559 |
func createMockParameter() *v3.Parameter { |
| 560 |
schemaProxy := &lowbase.SchemaProxy{} |
| 561 |
_ = schemaProxy.Build(context.Background(), &yaml.Node{}, &yaml.Node{}, nil) |
| 562 |
|
| 563 |
m := orderedmap.New[low.KeyReference[string], low.ValueReference[*lowv3.MediaType]]() |
| 564 |
m.Set(low.KeyReference[string]{Value: "application/json"}, low.ValueReference[*lowv3.MediaType]{ValueNode: &yaml.Node{}, Value: &lowv3.MediaType{}}) |
| 565 |
param := &lowv3.Parameter{ |
| 566 |
Name: low.NodeReference[string]{Value: "testQueryParam"}, |
| 567 |
Content: low.NodeReference[*orderedmap.Map[low.KeyReference[string], low.ValueReference[*lowv3.MediaType]]]{ |
| 568 |
Value: m, |
| 569 |
KeyNode: &yaml.Node{}, |
| 570 |
ValueNode: &yaml.Node{}, |
| 571 |
}, |
| 572 |
Schema: low.NodeReference[*lowbase.SchemaProxy]{ |
| 573 |
Value: schemaProxy, |
| 574 |
KeyNode: &yaml.Node{}, |
| 575 |
ValueNode: &yaml.Node{}, |
| 576 |
}, |
| 577 |
Required: low.NodeReference[bool]{ |
| 578 |
KeyNode: &yaml.Node{}, |
| 579 |
}, |
| 580 |
} |
| 581 |
return v3.NewParameter(param) |
| 582 |
} |
| 583 |
|
| 584 |
// Helper function to create a mock base.Schema |
| 585 |
func createMockLowBaseSchema() *lowbase.Schema { |
| 586 |
itemsSchema := &lowbase.Schema{ |
| 587 |
Type: low.NodeReference[lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]]{ |
| 588 |
Value: lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]{ |
| 589 |
A: "boolean", |
| 590 |
}, |
| 591 |
KeyNode: &yaml.Node{}, |
| 592 |
ValueNode: &yaml.Node{}, |
| 593 |
}, |
| 594 |
} |
| 595 |
|
| 596 |
schemaProxy := &lowbase.SchemaProxy{} |
| 597 |
|
| 598 |
itemsSchema.Items = low.NodeReference[*lowbase.SchemaDynamicValue[*lowbase.SchemaProxy, bool]]{ |
| 599 |
Value: &lowbase.SchemaDynamicValue[*lowbase.SchemaProxy, bool]{ |
| 600 |
A: schemaProxy, |
| 601 |
}, |
| 602 |
KeyNode: &yaml.Node{}, |
| 603 |
ValueNode: &yaml.Node{}, |
| 604 |
} |
| 605 |
|
| 606 |
_ = schemaProxy.Build(context.Background(), &yaml.Node{}, &yaml.Node{}, nil) |
| 607 |
schemaProxy.Schema().Type = low.NodeReference[lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]]{ |
| 608 |
KeyNode: &yaml.Node{}, |
| 609 |
ValueNode: &yaml.Node{}, |
| 610 |
Value: lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]{ |
| 611 |
A: "string", |
| 612 |
}, |
| 613 |
} |
| 614 |
|
| 615 |
return itemsSchema |
| 616 |
} |
| 617 |
|
| 618 |
func TestIncorrectParamEncodingJSON(t *testing.T) { |
| 619 |
param := createMockParameter() |
| 620 |
baseSchema := createMockLowBaseSchema() |
| 621 |
|
| 622 |
// Call the function with an invalid JSON value |
| 623 |
err := IncorrectParamEncodingJSON(param, "invalidJSON", base.NewSchema(baseSchema), "/test-path", "get", "{}") |
| 624 |
|
| 625 |
// Validate the error |
| 626 |
require.NotNil(t, err) |
| 627 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 628 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 629 |
require.Equal(t, "testQueryParam", err.ParameterName) |
| 630 |
require.Contains(t, err.Message, "Query parameter 'testQueryParam' is not valid JSON") |
| 631 |
require.Contains(t, err.Reason, "the value 'invalidJSON' is not valid JSON") |
| 632 |
require.Equal(t, HowToFixInvalidJSON, err.HowToFix) |
| 633 |
} |
| 634 |
|
| 635 |
func TestIncorrectQueryParamBool(t *testing.T) { |
| 636 |
param := createMockParameter() |
| 637 |
baseSchema := createMockLowBaseSchema() |
| 638 |
|
| 639 |
lschemaProxy := &lowbase.SchemaProxy{} |
| 640 |
require.NoError(t, lschemaProxy.Build(context.Background(), &yaml.Node{}, &yaml.Node{}, nil)) |
| 641 |
lschemaProxy.Schema().Type = low.NodeReference[lowbase.SchemaDynamicValue[string, []low.ValueReference[string]]]{ |
| 642 |
KeyNode: &yaml.Node{}, |
| 643 |
ValueNode: &yaml.Node{}, |
| 644 |
} |
| 645 |
param.GoLow().Schema.KeyNode = &yaml.Node{} |
| 646 |
param.Schema = base.NewSchemaProxy(&low.NodeReference[*lowbase.SchemaProxy]{ |
| 647 |
Value: lschemaProxy, |
| 648 |
KeyNode: &yaml.Node{}, |
| 649 |
ValueNode: &yaml.Node{}, |
| 650 |
}) |
| 651 |
|
| 652 |
// Call the function with an invalid boolean value |
| 653 |
err := IncorrectQueryParamBool(param, "notBoolean", base.NewSchema(baseSchema), "/test-path", "get", "{}") |
| 654 |
|
| 655 |
// Validate the error |
| 656 |
require.NotNil(t, err) |
| 657 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 658 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 659 |
require.Equal(t, "testQueryParam", err.ParameterName) |
| 660 |
require.Contains(t, err.Message, "Query parameter 'testQueryParam' is not a valid boolean") |
| 661 |
require.Contains(t, err.Reason, "the value 'notBoolean' is not a valid boolean") |
| 662 |
require.Contains(t, err.HowToFix, "true/false") |
| 663 |
} |
| 664 |
|
| 665 |
func TestInvalidQueryParamNumber(t *testing.T) { |
| 666 |
param := createMockParameter() |
| 667 |
baseSchema := createMockLowBaseSchema() |
| 668 |
|
| 669 |
// Call the function with an invalid number value |
| 670 |
err := InvalidQueryParamNumber(param, "notNumber", base.NewSchema(baseSchema), "/test-path", "get", "{}") |
| 671 |
|
| 672 |
// Validate the error |
| 673 |
require.NotNil(t, err) |
| 674 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 675 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 676 |
require.Equal(t, "testQueryParam", err.ParameterName) |
| 677 |
require.Contains(t, err.Message, "Query parameter 'testQueryParam' is not a valid number") |
| 678 |
require.Contains(t, err.Reason, "the value 'notNumber' is not a valid number") |
| 679 |
require.Contains(t, err.HowToFix, "notNumber") |
| 680 |
} |
| 681 |
|
| 682 |
func TestInvalidQueryParamInteger(t *testing.T) { |
| 683 |
param := createMockParameter() |
| 684 |
baseSchema := createMockLowBaseSchema() |
| 685 |
|
| 686 |
// Call the function with an invalid number value |
| 687 |
err := InvalidQueryParamInteger(param, "notNumber", base.NewSchema(baseSchema), "/test-path", "get", "{}") |
| 688 |
|
| 689 |
// Validate the error |
| 690 |
require.NotNil(t, err) |
| 691 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 692 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 693 |
require.Equal(t, "testQueryParam", err.ParameterName) |
| 694 |
require.Contains(t, err.Message, "Query parameter 'testQueryParam' is not a valid integer") |
| 695 |
require.Contains(t, err.Reason, "the value 'notNumber' is not a valid integer") |
| 696 |
require.Contains(t, err.HowToFix, "notNumber") |
| 697 |
} |
| 698 |
|
| 699 |
func TestIncorrectQueryParamEnum(t *testing.T) { |
| 700 |
enum := `enum: [fish, crab, lobster]` |
| 701 |
var n yaml.Node |
| 702 |
_ = yaml.Unmarshal([]byte(enum), &n) |
| 703 |
|
| 704 |
schemaProxy := &lowbase.SchemaProxy{} |
| 705 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 706 |
|
| 707 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 708 |
param := createMockParameter() |
| 709 |
param.Schema = base.CreateSchemaProxy(highSchema) |
| 710 |
param.GoLow().Schema.Value.Schema().Enum.KeyNode = &yaml.Node{} |
| 711 |
|
| 712 |
// Call the function with an invalid enum value |
| 713 |
err := IncorrectQueryParamEnum(param, "invalidEnum", highSchema, "/test-path", "get", "{}") |
| 714 |
|
| 715 |
// Validate the error |
| 716 |
require.NotNil(t, err) |
| 717 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 718 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 719 |
require.Equal(t, "testQueryParam", err.ParameterName) |
| 720 |
require.Contains(t, err.Message, "Query parameter 'testQueryParam' does not match allowed values") |
| 721 |
require.Contains(t, err.Reason, "'invalidEnum' is not one of those values") |
| 722 |
require.Contains(t, err.HowToFix, "fish, crab, lobster") |
| 723 |
} |
| 724 |
|
| 725 |
func TestIncorrectQueryParamEnumArray(t *testing.T) { |
| 726 |
enum := `items: |
| 727 |
enum: [fish, crab, lobster]` |
| 728 |
var n yaml.Node |
| 729 |
_ = yaml.Unmarshal([]byte(enum), &n) |
| 730 |
|
| 731 |
schemaProxy := &lowbase.SchemaProxy{} |
| 732 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 733 |
|
| 734 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 735 |
param := createMockParameter() |
| 736 |
param.Schema = base.CreateSchemaProxy(highSchema) |
| 737 |
param.GoLow().Schema.Value = schemaProxy |
| 738 |
param.GoLow().Schema.Value.Schema().Items.Value.A.Schema().Enum.Value = []low.ValueReference[*yaml.Node]{ |
| 739 |
{Value: &yaml.Node{Value: "fish, crab, lobster"}}, |
| 740 |
} |
| 741 |
|
| 742 |
// Call the function with an invalid enum value |
| 743 |
err := IncorrectQueryParamEnumArray(param, "invalidEnum", highSchema, "/test-path", "get", "{}") |
| 744 |
|
| 745 |
// Validate the error |
| 746 |
require.NotNil(t, err) |
| 747 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 748 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 749 |
require.Equal(t, "testQueryParam", err.ParameterName) |
| 750 |
require.Contains(t, err.Message, "Query array parameter 'testQueryParam' does not match allowed values") |
| 751 |
require.Contains(t, err.Reason, "'invalidEnum' is not one of those values") |
| 752 |
require.Contains(t, err.HowToFix, "fish, crab, lobster") |
| 753 |
} |
| 754 |
|
| 755 |
func TestIncorrectReservedValues(t *testing.T) { |
| 756 |
enum := `name: bork` |
| 757 |
var n yaml.Node |
| 758 |
_ = yaml.Unmarshal([]byte(enum), &n) |
| 759 |
|
| 760 |
schemaProxy := &lowbase.SchemaProxy{} |
| 761 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 762 |
|
| 763 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 764 |
param := createMockParameter() |
| 765 |
param.Name = "borked::?^&*" |
| 766 |
|
| 767 |
err := IncorrectReservedValues(param, "borked::?^&*", highSchema, "/test-path", "get", "{}") |
| 768 |
|
| 769 |
// Validate the error |
| 770 |
require.NotNil(t, err) |
| 771 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 772 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 773 |
require.Equal(t, "borked::?^&*", err.ParameterName) |
| 774 |
require.Contains(t, err.Message, "Query parameter 'borked::?^&*' value contains reserved values") |
| 775 |
require.Contains(t, err.Reason, "The query parameter 'borked::?^&*' has 'allowReserved' set to false") |
| 776 |
require.Contains(t, err.HowToFix, "borked%3A%3A%3F%5E%26%2A") |
| 777 |
} |
| 778 |
|
| 779 |
func TestInvalidHeaderParamInteger(t *testing.T) { |
| 780 |
enum := `name: blip` |
| 781 |
var n yaml.Node |
| 782 |
_ = yaml.Unmarshal([]byte(enum), &n) |
| 783 |
|
| 784 |
schemaProxy := &lowbase.SchemaProxy{} |
| 785 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 786 |
|
| 787 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 788 |
param := createMockParameter() |
| 789 |
param.Name = "bunny" |
| 790 |
|
| 791 |
err := InvalidHeaderParamInteger(param, "bunmy", highSchema, "/test-path", "get", "{}") |
| 792 |
|
| 793 |
// Validate the error |
| 794 |
require.NotNil(t, err) |
| 795 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 796 |
require.Equal(t, helpers.ParameterValidationHeader, err.ValidationSubType) |
| 797 |
require.Equal(t, "bunny", err.ParameterName) |
| 798 |
require.Contains(t, err.Message, "Header parameter 'bunny' is not a valid integer") |
| 799 |
require.Contains(t, err.Reason, "The header parameter 'bunny' is defined as being an integer") |
| 800 |
require.Contains(t, err.HowToFix, "bunmy") |
| 801 |
} |
| 802 |
|
| 803 |
func TestInvalidHeaderParamNumber(t *testing.T) { |
| 804 |
enum := `name: blip` |
| 805 |
var n yaml.Node |
| 806 |
_ = yaml.Unmarshal([]byte(enum), &n) |
| 807 |
|
| 808 |
schemaProxy := &lowbase.SchemaProxy{} |
| 809 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 810 |
|
| 811 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 812 |
param := createMockParameter() |
| 813 |
param.Name = "bunny" |
| 814 |
|
| 815 |
err := InvalidHeaderParamNumber(param, "bunmy", highSchema, "/test-path", "get", "{}") |
| 816 |
|
| 817 |
// Validate the error |
| 818 |
require.NotNil(t, err) |
| 819 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 820 |
require.Equal(t, helpers.ParameterValidationHeader, err.ValidationSubType) |
| 821 |
require.Equal(t, "bunny", err.ParameterName) |
| 822 |
require.Contains(t, err.Message, "Header parameter 'bunny' is not a valid number") |
| 823 |
require.Contains(t, err.Reason, "The header parameter 'bunny' is defined as being a number") |
| 824 |
require.Contains(t, err.HowToFix, "bunmy") |
| 825 |
} |
| 826 |
|
| 827 |
func TestInvalidCookieParamNumber(t *testing.T) { |
| 828 |
enum := `name: blip` |
| 829 |
var n yaml.Node |
| 830 |
_ = yaml.Unmarshal([]byte(enum), &n) |
| 831 |
|
| 832 |
schemaProxy := &lowbase.SchemaProxy{} |
| 833 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 834 |
|
| 835 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 836 |
param := createMockParameter() |
| 837 |
param.Name = "cookies" |
| 838 |
|
| 839 |
err := InvalidCookieParamNumber(param, "milky", highSchema, "/test-path", "get", "{}") |
| 840 |
|
| 841 |
// Validate the error |
| 842 |
require.NotNil(t, err) |
| 843 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 844 |
require.Equal(t, helpers.ParameterValidationCookie, err.ValidationSubType) |
| 845 |
require.Equal(t, "cookies", err.ParameterName) |
| 846 |
require.Contains(t, err.Message, "Cookie parameter 'cookies' is not a valid number") |
| 847 |
require.Contains(t, err.Reason, "The cookie parameter 'cookies' is defined as being a number") |
| 848 |
require.Contains(t, err.HowToFix, "milky") |
| 849 |
} |
| 850 |
|
| 851 |
func TestInvalidCookieParamInteger(t *testing.T) { |
| 852 |
enum := `name: blip` |
| 853 |
var n yaml.Node |
| 854 |
_ = yaml.Unmarshal([]byte(enum), &n) |
| 855 |
|
| 856 |
schemaProxy := &lowbase.SchemaProxy{} |
| 857 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 858 |
|
| 859 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 860 |
param := createMockParameter() |
| 861 |
param.Name = "cookies" |
| 862 |
|
| 863 |
err := InvalidCookieParamInteger(param, "milky", highSchema, "/test-path", "get", "{}") |
| 864 |
|
| 865 |
// Validate the error |
| 866 |
require.NotNil(t, err) |
| 867 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 868 |
require.Equal(t, helpers.ParameterValidationCookie, err.ValidationSubType) |
| 869 |
require.Equal(t, "cookies", err.ParameterName) |
| 870 |
require.Contains(t, err.Message, "Cookie parameter 'cookies' is not a valid integer") |
| 871 |
require.Contains(t, err.Reason, "The cookie parameter 'cookies' is defined as being an integer") |
| 872 |
require.Contains(t, err.HowToFix, "milky") |
| 873 |
} |
| 874 |
|
| 875 |
func TestIncorrectHeaderParamBool(t *testing.T) { |
| 876 |
enum := `name: blip` |
| 877 |
var n yaml.Node |
| 878 |
_ = yaml.Unmarshal([]byte(enum), &n) |
| 879 |
|
| 880 |
schemaProxy := &lowbase.SchemaProxy{} |
| 881 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 882 |
|
| 883 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 884 |
param := createMockParameter() |
| 885 |
param.Name = "cookies" |
| 886 |
|
| 887 |
err := IncorrectHeaderParamBool(param, "milky", highSchema, "/test-path", "get", "{}") |
| 888 |
|
| 889 |
// Validate the error |
| 890 |
require.NotNil(t, err) |
| 891 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 892 |
require.Equal(t, helpers.ParameterValidationHeader, err.ValidationSubType) |
| 893 |
require.Equal(t, "cookies", err.ParameterName) |
| 894 |
require.Contains(t, err.Message, "Header parameter 'cookies' is not a valid boolean") |
| 895 |
require.Contains(t, err.Reason, "The header parameter 'cookies' is defined as being a boolean") |
| 896 |
require.Contains(t, err.HowToFix, "milky") |
| 897 |
} |
| 898 |
|
| 899 |
func TestIncorrectCookieParamBool(t *testing.T) { |
| 900 |
enum := `name: blip` |
| 901 |
var n yaml.Node |
| 902 |
_ = yaml.Unmarshal([]byte(enum), &n) |
| 903 |
|
| 904 |
schemaProxy := &lowbase.SchemaProxy{} |
| 905 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 906 |
|
| 907 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 908 |
param := createMockParameter() |
| 909 |
param.Name = "cookies" |
| 910 |
|
| 911 |
err := IncorrectCookieParamBool(param, "milky", highSchema, "/test-path", "get", "{}") |
| 912 |
|
| 913 |
// Validate the error |
| 914 |
require.NotNil(t, err) |
| 915 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 916 |
require.Equal(t, helpers.ParameterValidationCookie, err.ValidationSubType) |
| 917 |
require.Equal(t, "cookies", err.ParameterName) |
| 918 |
require.Contains(t, err.Message, "Cookie parameter 'cookies' is not a valid boolean") |
| 919 |
require.Contains(t, err.Reason, "The cookie parameter 'cookies' is defined as being a boolean") |
| 920 |
require.Contains(t, err.HowToFix, "milky") |
| 921 |
} |
| 922 |
|
| 923 |
func TestIncorrectCookieParamEnum(t *testing.T) { |
| 924 |
enum := `enum: [fish, crab, lobster] |
| 925 |
items: |
| 926 |
enum: [fish, crab, lobster]` |
| 927 |
var n yaml.Node |
| 928 |
_ = yaml.Unmarshal([]byte(enum), &n) |
| 929 |
|
| 930 |
schemaProxy := &lowbase.SchemaProxy{} |
| 931 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 932 |
|
| 933 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 934 |
param := createMockParameter() |
| 935 |
param.Schema = base.CreateSchemaProxy(highSchema) |
| 936 |
param.GoLow().Schema.Value = schemaProxy |
| 937 |
param.GoLow().Schema.Value.Schema().Enum.Value = []low.ValueReference[*yaml.Node]{ |
| 938 |
{Value: &yaml.Node{Value: "fish, crab, lobster"}}, |
| 939 |
} |
| 940 |
param.GoLow().Schema.Value.Schema().Enum.KeyNode = &yaml.Node{} |
| 941 |
|
| 942 |
err := IncorrectCookieParamEnum(param, "milky", highSchema, "/test-path", "get", "{}") |
| 943 |
|
| 944 |
// Validate the error |
| 945 |
require.NotNil(t, err) |
| 946 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 947 |
require.Equal(t, helpers.ParameterValidationCookie, err.ValidationSubType) |
| 948 |
require.Equal(t, "testQueryParam", err.ParameterName) |
| 949 |
require.Contains(t, err.Message, "Cookie parameter 'testQueryParam' does not match allowed values") |
| 950 |
require.Contains(t, err.Reason, "The cookie parameter 'testQueryParam' has pre-defined values set via an enum") |
| 951 |
require.Contains(t, err.HowToFix, "milky") |
| 952 |
} |
| 953 |
|
| 954 |
func TestIncorrectHeaderParamArrayBoolean(t *testing.T) { |
| 955 |
items := `items: |
| 956 |
type: boolean` |
| 957 |
var n yaml.Node |
| 958 |
_ = yaml.Unmarshal([]byte(items), &n) |
| 959 |
|
| 960 |
schemaProxy := &lowbase.SchemaProxy{} |
| 961 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 962 |
|
| 963 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 964 |
highSchema.GoLow().Items.Value.A.Schema() |
| 965 |
|
| 966 |
param := createMockParameter() |
| 967 |
param.Name = "bubbles" |
| 968 |
|
| 969 |
err := IncorrectHeaderParamArrayBoolean(param, "milky", highSchema, nil, "/test-path", "get", "{}") |
| 970 |
|
| 971 |
// Validate the error |
| 972 |
require.NotNil(t, err) |
| 973 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 974 |
require.Equal(t, helpers.ParameterValidationHeader, err.ValidationSubType) |
| 975 |
require.Equal(t, "bubbles", err.ParameterName) |
| 976 |
require.Contains(t, err.Message, "Header array parameter 'bubbles' is not a valid boolean") |
| 977 |
require.Contains(t, err.Reason, "The header parameter (which is an array) 'bubbles' is defined as being a boolean") |
| 978 |
require.Contains(t, err.HowToFix, "milky") |
| 979 |
} |
| 980 |
|
| 981 |
func TestIncorrectHeaderParamArrayNumber(t *testing.T) { |
| 982 |
items := `items: |
| 983 |
type: number` |
| 984 |
var n yaml.Node |
| 985 |
_ = yaml.Unmarshal([]byte(items), &n) |
| 986 |
|
| 987 |
schemaProxy := &lowbase.SchemaProxy{} |
| 988 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 989 |
|
| 990 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 991 |
highSchema.GoLow().Items.Value.A.Schema() |
| 992 |
|
| 993 |
param := createMockParameter() |
| 994 |
param.Name = "bubbles" |
| 995 |
|
| 996 |
err := IncorrectHeaderParamArrayNumber(param, "milky", highSchema, nil, "/test-path", "get", "{}") |
| 997 |
|
| 998 |
// Validate the error |
| 999 |
require.NotNil(t, err) |
| 1000 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 1001 |
require.Equal(t, helpers.ParameterValidationHeader, err.ValidationSubType) |
| 1002 |
require.Equal(t, "bubbles", err.ParameterName) |
| 1003 |
require.Contains(t, err.Message, "Header array parameter 'bubbles' is not a valid number") |
| 1004 |
require.Contains(t, err.Reason, "The header parameter (which is an array) 'bubbles' is defined as being a number") |
| 1005 |
require.Contains(t, err.HowToFix, "milky") |
| 1006 |
} |
| 1007 |
|
| 1008 |
func TestIncorrectPathParamBool(t *testing.T) { |
| 1009 |
items := `items: |
| 1010 |
type: number` |
| 1011 |
var n yaml.Node |
| 1012 |
_ = yaml.Unmarshal([]byte(items), &n) |
| 1013 |
|
| 1014 |
schemaProxy := &lowbase.SchemaProxy{} |
| 1015 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 1016 |
|
| 1017 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 1018 |
param := createMockParameter() |
| 1019 |
param.Schema = base.CreateSchemaProxy(highSchema) |
| 1020 |
param.GoLow().Schema.KeyNode = &yaml.Node{} |
| 1021 |
|
| 1022 |
err := IncorrectPathParamBool(param, "milky", highSchema, "/test-path", "{}") |
| 1023 |
|
| 1024 |
// Validate the error |
| 1025 |
require.NotNil(t, err) |
| 1026 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 1027 |
require.Equal(t, helpers.ParameterValidationPath, err.ValidationSubType) |
| 1028 |
require.Equal(t, "testQueryParam", err.ParameterName) |
| 1029 |
require.Contains(t, err.Message, "Path parameter 'testQueryParam' is not a valid boolean") |
| 1030 |
require.Contains(t, err.Reason, "The path parameter 'testQueryParam' is defined as being a boolean") |
| 1031 |
require.Contains(t, err.HowToFix, "milky") |
| 1032 |
} |
| 1033 |
|
| 1034 |
func TestIncorrectPathParamEnum(t *testing.T) { |
| 1035 |
items := `enum: [fish, crab, lobster] |
| 1036 |
items: |
| 1037 |
enum: [fish, crab, lobster]` |
| 1038 |
|
| 1039 |
var n yaml.Node |
| 1040 |
_ = yaml.Unmarshal([]byte(items), &n) |
| 1041 |
|
| 1042 |
schemaProxy := &lowbase.SchemaProxy{} |
| 1043 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 1044 |
|
| 1045 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 1046 |
param := createMockParameter() |
| 1047 |
param.Schema = base.CreateSchemaProxy(highSchema) |
| 1048 |
param.GoLow().Schema.Value = schemaProxy |
| 1049 |
param.GoLow().Schema.Value.Schema().Enum.Value = []low.ValueReference[*yaml.Node]{ |
| 1050 |
{Value: &yaml.Node{Value: "fish, crab, lobster"}}, |
| 1051 |
} |
| 1052 |
param.GoLow().Schema.Value.Schema().Enum.KeyNode = &yaml.Node{} |
| 1053 |
|
| 1054 |
err := IncorrectPathParamEnum(param, "milky", highSchema, "/test-path", "{}") |
| 1055 |
|
| 1056 |
// Validate the error |
| 1057 |
require.NotNil(t, err) |
| 1058 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 1059 |
require.Equal(t, helpers.ParameterValidationPath, err.ValidationSubType) |
| 1060 |
require.Equal(t, "testQueryParam", err.ParameterName) |
| 1061 |
require.Contains(t, err.Message, "Path parameter 'testQueryParam' does not match allowed values") |
| 1062 |
require.Contains(t, err.Reason, "The path parameter 'testQueryParam' has pre-defined values set via an enum") |
| 1063 |
require.Contains(t, err.HowToFix, "milky") |
| 1064 |
} |
| 1065 |
|
| 1066 |
func TestIncorrectPathParamNumber(t *testing.T) { |
| 1067 |
items := `items: |
| 1068 |
type: number` |
| 1069 |
var n yaml.Node |
| 1070 |
_ = yaml.Unmarshal([]byte(items), &n) |
| 1071 |
|
| 1072 |
schemaProxy := &lowbase.SchemaProxy{} |
| 1073 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 1074 |
|
| 1075 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 1076 |
param := createMockParameter() |
| 1077 |
param.Schema = base.CreateSchemaProxy(highSchema) |
| 1078 |
param.GoLow().Schema.KeyNode = &yaml.Node{} |
| 1079 |
|
| 1080 |
err := IncorrectPathParamNumber(param, "milky", highSchema, "/test-path", "{}") |
| 1081 |
|
| 1082 |
// Validate the error |
| 1083 |
require.NotNil(t, err) |
| 1084 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 1085 |
require.Equal(t, helpers.ParameterValidationPath, err.ValidationSubType) |
| 1086 |
require.Equal(t, "testQueryParam", err.ParameterName) |
| 1087 |
require.Contains(t, err.Message, "Path parameter 'testQueryParam' is not a valid number") |
| 1088 |
require.Contains(t, err.Reason, "The path parameter 'testQueryParam' is defined as being a number") |
| 1089 |
require.Contains(t, err.HowToFix, "milky") |
| 1090 |
} |
| 1091 |
|
| 1092 |
func TestIncorrectPathParamInteger(t *testing.T) { |
| 1093 |
items := `items: |
| 1094 |
type: integer` |
| 1095 |
var n yaml.Node |
| 1096 |
_ = yaml.Unmarshal([]byte(items), &n) |
| 1097 |
|
| 1098 |
schemaProxy := &lowbase.SchemaProxy{} |
| 1099 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 1100 |
|
| 1101 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 1102 |
param := createMockParameter() |
| 1103 |
param.Schema = base.CreateSchemaProxy(highSchema) |
| 1104 |
param.GoLow().Schema.KeyNode = &yaml.Node{} |
| 1105 |
|
| 1106 |
err := IncorrectPathParamInteger(param, "milky", highSchema, "/test-path", "{}") |
| 1107 |
|
| 1108 |
// Validate the error |
| 1109 |
require.NotNil(t, err) |
| 1110 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 1111 |
require.Equal(t, helpers.ParameterValidationPath, err.ValidationSubType) |
| 1112 |
require.Equal(t, "testQueryParam", err.ParameterName) |
| 1113 |
require.Contains(t, err.Message, "Path parameter 'testQueryParam' is not a valid integer") |
| 1114 |
require.Contains(t, err.Reason, "The path parameter 'testQueryParam' is defined as being an integer") |
| 1115 |
require.Contains(t, err.HowToFix, "milky") |
| 1116 |
} |
| 1117 |
|
| 1118 |
func TestIncorrectPathParamArrayNumber(t *testing.T) { |
| 1119 |
items := `items: |
| 1120 |
type: number` |
| 1121 |
var n yaml.Node |
| 1122 |
_ = yaml.Unmarshal([]byte(items), &n) |
| 1123 |
|
| 1124 |
schemaProxy := &lowbase.SchemaProxy{} |
| 1125 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 1126 |
|
| 1127 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 1128 |
highSchema.GoLow().Items.Value.A.Schema() |
| 1129 |
|
| 1130 |
param := createMockParameter() |
| 1131 |
param.Name = "bubbles" |
| 1132 |
|
| 1133 |
err := IncorrectPathParamArrayNumber(param, "milky", highSchema, nil, "/test-path", "{}") |
| 1134 |
|
| 1135 |
// Validate the error |
| 1136 |
require.NotNil(t, err) |
| 1137 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 1138 |
require.Equal(t, helpers.ParameterValidationPath, err.ValidationSubType) |
| 1139 |
require.Equal(t, "bubbles", err.ParameterName) |
| 1140 |
require.Contains(t, err.Message, "Path array parameter 'bubbles' is not a valid number") |
| 1141 |
require.Contains(t, err.Reason, "The path parameter (which is an array) 'bubbles' is defined as being a number") |
| 1142 |
require.Contains(t, err.HowToFix, "milky") |
| 1143 |
} |
| 1144 |
|
| 1145 |
func TestIncorrectPathParamArrayInteger(t *testing.T) { |
| 1146 |
items := `items: |
| 1147 |
type: integer` |
| 1148 |
var n yaml.Node |
| 1149 |
_ = yaml.Unmarshal([]byte(items), &n) |
| 1150 |
|
| 1151 |
schemaProxy := &lowbase.SchemaProxy{} |
| 1152 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 1153 |
|
| 1154 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 1155 |
highSchema.GoLow().Items.Value.A.Schema() |
| 1156 |
|
| 1157 |
param := createMockParameter() |
| 1158 |
param.Name = "bubbles" |
| 1159 |
|
| 1160 |
err := IncorrectPathParamArrayInteger(param, "milky", highSchema, nil, "/test-path", "{}") |
| 1161 |
|
| 1162 |
// Validate the error |
| 1163 |
require.NotNil(t, err) |
| 1164 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 1165 |
require.Equal(t, helpers.ParameterValidationPath, err.ValidationSubType) |
| 1166 |
require.Equal(t, "bubbles", err.ParameterName) |
| 1167 |
require.Contains(t, err.Message, "Path array parameter 'bubbles' is not a valid integer") |
| 1168 |
require.Contains(t, err.Reason, "The path parameter (which is an array) 'bubbles' is defined as being an integer") |
| 1169 |
require.Contains(t, err.HowToFix, "milky") |
| 1170 |
} |
| 1171 |
|
| 1172 |
func TestIncorrectPathParamArrayBoolean(t *testing.T) { |
| 1173 |
items := `items: |
| 1174 |
type: number` |
| 1175 |
var n yaml.Node |
| 1176 |
_ = yaml.Unmarshal([]byte(items), &n) |
| 1177 |
|
| 1178 |
schemaProxy := &lowbase.SchemaProxy{} |
| 1179 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 1180 |
|
| 1181 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 1182 |
highSchema.GoLow().Items.Value.A.Schema() |
| 1183 |
|
| 1184 |
param := createMockParameter() |
| 1185 |
param.Name = "bubbles" |
| 1186 |
|
| 1187 |
err := IncorrectPathParamArrayBoolean(param, "milky", highSchema, nil, "/test-path", "{}") |
| 1188 |
|
| 1189 |
// Validate the error |
| 1190 |
require.NotNil(t, err) |
| 1191 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 1192 |
require.Equal(t, helpers.ParameterValidationPath, err.ValidationSubType) |
| 1193 |
require.Equal(t, "bubbles", err.ParameterName) |
| 1194 |
require.Contains(t, err.Message, "Path array parameter 'bubbles' is not a valid boolean") |
| 1195 |
require.Contains(t, err.Reason, "The path parameter (which is an array) 'bubbles' is defined as being a boolean") |
| 1196 |
require.Contains(t, err.HowToFix, "milky") |
| 1197 |
} |
| 1198 |
|
| 1199 |
func TestPathParameterMissing(t *testing.T) { |
| 1200 |
items := `required: |
| 1201 |
- testQueryParam` |
| 1202 |
var n yaml.Node |
| 1203 |
_ = yaml.Unmarshal([]byte(items), &n) |
| 1204 |
|
| 1205 |
schemaProxy := &lowbase.SchemaProxy{} |
| 1206 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 1207 |
|
| 1208 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 1209 |
param := createMockParameter() |
| 1210 |
param.Schema = base.CreateSchemaProxy(highSchema) |
| 1211 |
param.GoLow().Schema.KeyNode = &yaml.Node{} |
| 1212 |
|
| 1213 |
err := PathParameterMissing(param, "/test/{testQueryParam}", "/test/") |
| 1214 |
|
| 1215 |
// Validate the error |
| 1216 |
require.NotNil(t, err) |
| 1217 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 1218 |
require.Equal(t, helpers.ParameterValidationPath, err.ValidationSubType) |
| 1219 |
require.Equal(t, "testQueryParam", err.ParameterName) |
| 1220 |
require.Contains(t, err.Message, "Path parameter 'testQueryParam' is missing") |
| 1221 |
require.Contains(t, err.Reason, "The path parameter 'testQueryParam' is defined as being required") |
| 1222 |
require.Contains(t, err.HowToFix, "Ensure the value has been set") |
| 1223 |
} |
| 1224 |
|
| 1225 |
func TestPathParameterMaxItems(t *testing.T) { |
| 1226 |
items := `maxItems: 5 |
| 1227 |
items: |
| 1228 |
type: string` |
| 1229 |
var n yaml.Node |
| 1230 |
_ = yaml.Unmarshal([]byte(items), &n) |
| 1231 |
|
| 1232 |
schemaProxy := &lowbase.SchemaProxy{} |
| 1233 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 1234 |
|
| 1235 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 1236 |
param := createMockParameter() |
| 1237 |
param.Schema = base.CreateSchemaProxy(highSchema) |
| 1238 |
param.GoLow().Schema.KeyNode = &yaml.Node{} |
| 1239 |
|
| 1240 |
err := IncorrectParamArrayMaxNumItems(param, param.Schema.Schema(), 10, 25, "/test-path", "get", "{}") |
| 1241 |
|
| 1242 |
// Validate the error |
| 1243 |
require.NotNil(t, err) |
| 1244 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 1245 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 1246 |
require.Equal(t, "testQueryParam", err.ParameterName) |
| 1247 |
require.Contains(t, err.Message, "Query array parameter 'testQueryParam' has too many items") |
| 1248 |
require.Contains(t, err.Reason, "The query parameter (which is an array) 'testQueryParam' has a maximum item length of 10, however the request provided 25 items") |
| 1249 |
require.Contains(t, err.HowToFix, "Reduce the number of items in the array to 10 or less") |
| 1250 |
} |
| 1251 |
|
| 1252 |
func TestPathParameterMinItems(t *testing.T) { |
| 1253 |
items := `minItems: 5 |
| 1254 |
items: |
| 1255 |
type: string` |
| 1256 |
var n yaml.Node |
| 1257 |
_ = yaml.Unmarshal([]byte(items), &n) |
| 1258 |
|
| 1259 |
schemaProxy := &lowbase.SchemaProxy{} |
| 1260 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 1261 |
|
| 1262 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 1263 |
param := createMockParameter() |
| 1264 |
param.Schema = base.CreateSchemaProxy(highSchema) |
| 1265 |
param.GoLow().Schema.KeyNode = &yaml.Node{} |
| 1266 |
|
| 1267 |
err := IncorrectParamArrayMinNumItems(param, param.Schema.Schema(), 10, 5, "/test-path", "get", "{}") |
| 1268 |
|
| 1269 |
// Validate the error |
| 1270 |
require.NotNil(t, err) |
| 1271 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 1272 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 1273 |
require.Equal(t, "testQueryParam", err.ParameterName) |
| 1274 |
require.Contains(t, err.Message, "Query array parameter 'testQueryParam' does not have enough items") |
| 1275 |
require.Contains(t, err.Reason, "The query parameter (which is an array) 'testQueryParam' has a minimum items length of 10, however the request provided 5 items") |
| 1276 |
require.Contains(t, err.HowToFix, "Increase the number of items in the array to 10 or more") |
| 1277 |
} |
| 1278 |
|
| 1279 |
func TestPathParameterUniqueItems(t *testing.T) { |
| 1280 |
items := `uniqueItems: true |
| 1281 |
items: |
| 1282 |
type: string` |
| 1283 |
var n yaml.Node |
| 1284 |
_ = yaml.Unmarshal([]byte(items), &n) |
| 1285 |
|
| 1286 |
schemaProxy := &lowbase.SchemaProxy{} |
| 1287 |
require.NoError(t, schemaProxy.Build(context.Background(), n.Content[0], n.Content[0], nil)) |
| 1288 |
|
| 1289 |
highSchema := base.NewSchema(schemaProxy.Schema()) |
| 1290 |
param := createMockParameter() |
| 1291 |
param.Schema = base.CreateSchemaProxy(highSchema) |
| 1292 |
param.GoLow().Schema.KeyNode = &yaml.Node{} |
| 1293 |
|
| 1294 |
err := IncorrectParamArrayUniqueItems(param, param.Schema.Schema(), "fish, cake", "/test-path", "get", "{}") |
| 1295 |
|
| 1296 |
// Validate the error |
| 1297 |
require.NotNil(t, err) |
| 1298 |
require.Equal(t, helpers.ParameterValidation, err.ValidationType) |
| 1299 |
require.Equal(t, helpers.ParameterValidationQuery, err.ValidationSubType) |
| 1300 |
require.Equal(t, "testQueryParam", err.ParameterName) |
| 1301 |
require.Contains(t, err.Message, "Query array parameter 'testQueryParam' contains non-unique items") |
| 1302 |
require.Contains(t, err.Reason, "The query parameter (which is an array) 'testQueryParam' contains the following duplicates: 'fish, cake'") |
| 1303 |
require.Contains(t, err.HowToFix, "Ensure the array values are all unique") |
| 1304 |
} |
| 1305 |
|
| 1306 |
// createMinimalParameter creates a parameter with nil GoLow nodes to test nil safety. |
| 1307 |
func createMinimalParameter() *v3.Parameter { |
| 1308 |
param := &lowv3.Parameter{ |
| 1309 |
Name: low.NodeReference[string]{Value: "minParam"}, |
| 1310 |
// All node references intentionally left with nil KeyNode/ValueNode |
| 1311 |
} |
| 1312 |
return v3.NewParameter(param) |
| 1313 |
} |
| 1314 |
|
| 1315 |
func TestParameterErrors_NilGoLowNodes(t *testing.T) { |
| 1316 |
// Tests that all parameter error constructors handle nil GoLow nodes |
| 1317 |
// without panicking. This covers the crash scenario from wiretap #134. |
| 1318 |
param := createMinimalParameter() |
| 1319 |
qp := &helpers.QueryParam{ |
| 1320 |
Key: "minParam", |
| 1321 |
Values: []string{"value"}, |
| 1322 |
} |
| 1323 |
sch := &base.Schema{} |
| 1324 |
|
| 1325 |
t.Run("IncorrectFormEncoding", func(t *testing.T) { |
| 1326 |
err := IncorrectFormEncoding(param, qp, 0) |
| 1327 |
require.NotNil(t, err) |
| 1328 |
require.Equal(t, 1, err.SpecLine) |
| 1329 |
require.Equal(t, 0, err.SpecCol) |
| 1330 |
}) |
| 1331 |
|
| 1332 |
t.Run("IncorrectSpaceDelimiting", func(t *testing.T) { |
| 1333 |
err := IncorrectSpaceDelimiting(param, qp) |
| 1334 |
require.NotNil(t, err) |
| 1335 |
require.Equal(t, 1, err.SpecLine) |
| 1336 |
require.Equal(t, 0, err.SpecCol) |
| 1337 |
}) |
| 1338 |
|
| 1339 |
t.Run("IncorrectPipeDelimiting", func(t *testing.T) { |
| 1340 |
err := IncorrectPipeDelimiting(param, qp) |
| 1341 |
require.NotNil(t, err) |
| 1342 |
require.Equal(t, 1, err.SpecLine) |
| 1343 |
require.Equal(t, 0, err.SpecCol) |
| 1344 |
}) |
| 1345 |
|
| 1346 |
t.Run("InvalidDeepObject", func(t *testing.T) { |
| 1347 |
err := InvalidDeepObject(param, qp) |
| 1348 |
require.NotNil(t, err) |
| 1349 |
require.Equal(t, 1, err.SpecLine) |
| 1350 |
require.Equal(t, 0, err.SpecCol) |
| 1351 |
}) |
| 1352 |
|
| 1353 |
t.Run("InvalidDeepObjectPathConflict", func(t *testing.T) { |
| 1354 |
err := InvalidDeepObjectPathConflict(param, qp, &helpers.QueryParam{ |
| 1355 |
Key: "test", |
| 1356 |
Values: []string{"ok"}, |
| 1357 |
Property: "foo", |
| 1358 |
PropertyPath: []string{"foo", "bar"}, |
| 1359 |
}) |
| 1360 |
require.NotNil(t, err) |
| 1361 |
require.Equal(t, 1, err.SpecLine) |
| 1362 |
require.Equal(t, 0, err.SpecCol) |
| 1363 |
}) |
| 1364 |
|
| 1365 |
t.Run("QueryParameterMissing", func(t *testing.T) { |
| 1366 |
err := QueryParameterMissing(param, "/test", "get", "{}") |
| 1367 |
require.NotNil(t, err) |
| 1368 |
require.Equal(t, 1, err.SpecLine) |
| 1369 |
require.Equal(t, 0, err.SpecCol) |
| 1370 |
}) |
| 1371 |
|
| 1372 |
t.Run("HeaderParameterMissing", func(t *testing.T) { |
| 1373 |
err := HeaderParameterMissing(param, "/test", "get", "{}") |
| 1374 |
require.NotNil(t, err) |
| 1375 |
require.Equal(t, 1, err.SpecLine) |
| 1376 |
require.Equal(t, 0, err.SpecCol) |
| 1377 |
}) |
| 1378 |
|
| 1379 |
t.Run("CookieParameterMissing", func(t *testing.T) { |
| 1380 |
err := CookieParameterMissing(param, "/test", "get", "{}") |
| 1381 |
require.NotNil(t, err) |
| 1382 |
require.Equal(t, 1, err.SpecLine) |
| 1383 |
require.Equal(t, 0, err.SpecCol) |
| 1384 |
}) |
| 1385 |
|
| 1386 |
t.Run("HeaderParameterCannotBeDecoded", func(t *testing.T) { |
| 1387 |
err := HeaderParameterCannotBeDecoded(param, "bad", "/test", "get", "{}") |
| 1388 |
require.NotNil(t, err) |
| 1389 |
require.Equal(t, 1, err.SpecLine) |
| 1390 |
require.Equal(t, 0, err.SpecCol) |
| 1391 |
}) |
| 1392 |
|
| 1393 |
t.Run("IncorrectHeaderParamEnum", func(t *testing.T) { |
| 1394 |
err := IncorrectHeaderParamEnum(param, "bad", sch, "/test", "get", "{}") |
| 1395 |
require.NotNil(t, err) |
| 1396 |
require.Equal(t, 1, err.SpecLine) |
| 1397 |
require.Equal(t, 0, err.SpecCol) |
| 1398 |
}) |
| 1399 |
|
| 1400 |
t.Run("IncorrectQueryParamEnum", func(t *testing.T) { |
| 1401 |
err := IncorrectQueryParamEnum(param, "bad", sch, "/test", "get", "{}") |
| 1402 |
require.NotNil(t, err) |
| 1403 |
require.Equal(t, 1, err.SpecLine) |
| 1404 |
require.Equal(t, 0, err.SpecCol) |
| 1405 |
}) |
| 1406 |
|
| 1407 |
t.Run("IncorrectCookieParamEnum", func(t *testing.T) { |
| 1408 |
err := IncorrectCookieParamEnum(param, "bad", sch, "/test", "get", "{}") |
| 1409 |
require.NotNil(t, err) |
| 1410 |
require.Equal(t, 1, err.SpecLine) |
| 1411 |
require.Equal(t, 0, err.SpecCol) |
| 1412 |
}) |
| 1413 |
|
| 1414 |
t.Run("IncorrectPathParamEnum", func(t *testing.T) { |
| 1415 |
err := IncorrectPathParamEnum(param, "bad", sch, "/test", "{}") |
| 1416 |
require.NotNil(t, err) |
| 1417 |
require.Equal(t, 1, err.SpecLine) |
| 1418 |
require.Equal(t, 0, err.SpecCol) |
| 1419 |
}) |
| 1420 |
|
| 1421 |
t.Run("IncorrectQueryParamBool", func(t *testing.T) { |
| 1422 |
err := IncorrectQueryParamBool(param, "bad", sch, "/test", "get", "{}") |
| 1423 |
require.NotNil(t, err) |
| 1424 |
require.Equal(t, 1, err.SpecLine) |
| 1425 |
require.Equal(t, 0, err.SpecCol) |
| 1426 |
}) |
| 1427 |
|
| 1428 |
t.Run("InvalidQueryParamInteger", func(t *testing.T) { |
| 1429 |
err := InvalidQueryParamInteger(param, "bad", sch, "/test", "get", "{}") |
| 1430 |
require.NotNil(t, err) |
| 1431 |
require.Equal(t, 1, err.SpecLine) |
| 1432 |
require.Equal(t, 0, err.SpecCol) |
| 1433 |
}) |
| 1434 |
|
| 1435 |
t.Run("InvalidQueryParamNumber", func(t *testing.T) { |
| 1436 |
err := InvalidQueryParamNumber(param, "bad", sch, "/test", "get", "{}") |
| 1437 |
require.NotNil(t, err) |
| 1438 |
require.Equal(t, 1, err.SpecLine) |
| 1439 |
require.Equal(t, 0, err.SpecCol) |
| 1440 |
}) |
| 1441 |
|
| 1442 |
t.Run("IncorrectReservedValues", func(t *testing.T) { |
| 1443 |
err := IncorrectReservedValues(param, "a:b", sch, "/test", "get", "{}") |
| 1444 |
require.NotNil(t, err) |
| 1445 |
require.Equal(t, 1, err.SpecLine) |
| 1446 |
require.Equal(t, 0, err.SpecCol) |
| 1447 |
}) |
| 1448 |
|
| 1449 |
t.Run("InvalidHeaderParamInteger", func(t *testing.T) { |
| 1450 |
err := InvalidHeaderParamInteger(param, "bad", sch, "/test", "get", "{}") |
| 1451 |
require.NotNil(t, err) |
| 1452 |
require.Equal(t, 1, err.SpecLine) |
| 1453 |
require.Equal(t, 0, err.SpecCol) |
| 1454 |
}) |
| 1455 |
|
| 1456 |
t.Run("InvalidHeaderParamNumber", func(t *testing.T) { |
| 1457 |
err := InvalidHeaderParamNumber(param, "bad", sch, "/test", "get", "{}") |
| 1458 |
require.NotNil(t, err) |
| 1459 |
require.Equal(t, 1, err.SpecLine) |
| 1460 |
require.Equal(t, 0, err.SpecCol) |
| 1461 |
}) |
| 1462 |
|
| 1463 |
t.Run("InvalidCookieParamInteger", func(t *testing.T) { |
| 1464 |
err := InvalidCookieParamInteger(param, "bad", sch, "/test", "get", "{}") |
| 1465 |
require.NotNil(t, err) |
| 1466 |
require.Equal(t, 1, err.SpecLine) |
| 1467 |
require.Equal(t, 0, err.SpecCol) |
| 1468 |
}) |
| 1469 |
|
| 1470 |
t.Run("InvalidCookieParamNumber", func(t *testing.T) { |
| 1471 |
err := InvalidCookieParamNumber(param, "bad", sch, "/test", "get", "{}") |
| 1472 |
require.NotNil(t, err) |
| 1473 |
require.Equal(t, 1, err.SpecLine) |
| 1474 |
require.Equal(t, 0, err.SpecCol) |
| 1475 |
}) |
| 1476 |
|
| 1477 |
t.Run("IncorrectHeaderParamBool", func(t *testing.T) { |
| 1478 |
err := IncorrectHeaderParamBool(param, "bad", sch, "/test", "get", "{}") |
| 1479 |
require.NotNil(t, err) |
| 1480 |
require.Equal(t, 1, err.SpecLine) |
| 1481 |
require.Equal(t, 0, err.SpecCol) |
| 1482 |
}) |
| 1483 |
|
| 1484 |
t.Run("IncorrectCookieParamBool", func(t *testing.T) { |
| 1485 |
err := IncorrectCookieParamBool(param, "bad", sch, "/test", "get", "{}") |
| 1486 |
require.NotNil(t, err) |
| 1487 |
require.Equal(t, 1, err.SpecLine) |
| 1488 |
require.Equal(t, 0, err.SpecCol) |
| 1489 |
}) |
| 1490 |
|
| 1491 |
t.Run("IncorrectPathParamBool", func(t *testing.T) { |
| 1492 |
err := IncorrectPathParamBool(param, "bad", sch, "/test", "{}") |
| 1493 |
require.NotNil(t, err) |
| 1494 |
require.Equal(t, 1, err.SpecLine) |
| 1495 |
require.Equal(t, 0, err.SpecCol) |
| 1496 |
}) |
| 1497 |
|
| 1498 |
t.Run("IncorrectPathParamInteger", func(t *testing.T) { |
| 1499 |
err := IncorrectPathParamInteger(param, "bad", sch, "/test", "{}") |
| 1500 |
require.NotNil(t, err) |
| 1501 |
require.Equal(t, 1, err.SpecLine) |
| 1502 |
require.Equal(t, 0, err.SpecCol) |
| 1503 |
}) |
| 1504 |
|
| 1505 |
t.Run("IncorrectPathParamNumber", func(t *testing.T) { |
| 1506 |
err := IncorrectPathParamNumber(param, "bad", sch, "/test", "{}") |
| 1507 |
require.NotNil(t, err) |
| 1508 |
require.Equal(t, 1, err.SpecLine) |
| 1509 |
require.Equal(t, 0, err.SpecCol) |
| 1510 |
}) |
| 1511 |
|
| 1512 |
t.Run("IncorrectParamEncodingJSON", func(t *testing.T) { |
| 1513 |
err := IncorrectParamEncodingJSON(param, "bad", sch, "/test", "get", "{}") |
| 1514 |
require.NotNil(t, err) |
| 1515 |
require.Equal(t, 1, err.SpecLine) |
| 1516 |
require.Equal(t, 0, err.SpecCol) |
| 1517 |
}) |
| 1518 |
|
| 1519 |
t.Run("IncorrectQueryParamEnumArray", func(t *testing.T) { |
| 1520 |
err := IncorrectQueryParamEnumArray(param, "bad", sch, "/test", "get", "{}") |
| 1521 |
require.NotNil(t, err) |
| 1522 |
require.Equal(t, 1, err.SpecLine) |
| 1523 |
require.Equal(t, 0, err.SpecCol) |
| 1524 |
}) |
| 1525 |
|
| 1526 |
t.Run("PathParameterMissing", func(t *testing.T) { |
| 1527 |
err := PathParameterMissing(param, "/test/{id}", "/test/123") |
| 1528 |
require.NotNil(t, err) |
| 1529 |
require.Equal(t, 1, err.SpecLine) |
| 1530 |
require.Equal(t, 0, err.SpecCol) |
| 1531 |
}) |
| 1532 |
} |
| 1533 |
|
| 1534 |
func TestParameterErrors_NilSchemaItems(t *testing.T) { |
| 1535 |
// Tests array parameter error constructors with nil Items in schema. |
| 1536 |
param := createMinimalParameter() |
| 1537 |
sch := &base.Schema{} // no Items set |
| 1538 |
|
| 1539 |
t.Run("IncorrectQueryParamArrayBoolean", func(t *testing.T) { |
| 1540 |
err := IncorrectQueryParamArrayBoolean(param, "bad", sch, sch, "/test", "get", "{}") |
| 1541 |
require.NotNil(t, err) |
| 1542 |
require.Equal(t, 1, err.SpecLine) |
| 1543 |
require.Equal(t, 0, err.SpecCol) |
| 1544 |
}) |
| 1545 |
|
| 1546 |
t.Run("IncorrectParamArrayMaxNumItems", func(t *testing.T) { |
| 1547 |
err := IncorrectParamArrayMaxNumItems(param, sch, 5, 10, "/test", "get", "{}") |
| 1548 |
require.NotNil(t, err) |
| 1549 |
require.Equal(t, 1, err.SpecLine) |
| 1550 |
require.Equal(t, 0, err.SpecCol) |
| 1551 |
}) |
| 1552 |
|
| 1553 |
t.Run("IncorrectParamArrayMinNumItems", func(t *testing.T) { |
| 1554 |
err := IncorrectParamArrayMinNumItems(param, sch, 5, 2, "/test", "get", "{}") |
| 1555 |
require.NotNil(t, err) |
| 1556 |
require.Equal(t, 1, err.SpecLine) |
| 1557 |
require.Equal(t, 0, err.SpecCol) |
| 1558 |
}) |
| 1559 |
|
| 1560 |
t.Run("IncorrectParamArrayUniqueItems", func(t *testing.T) { |
| 1561 |
err := IncorrectParamArrayUniqueItems(param, sch, "dup", "/test", "get", "{}") |
| 1562 |
require.NotNil(t, err) |
| 1563 |
require.Equal(t, 1, err.SpecLine) |
| 1564 |
require.Equal(t, 0, err.SpecCol) |
| 1565 |
}) |
| 1566 |
|
| 1567 |
t.Run("IncorrectCookieParamArrayBoolean", func(t *testing.T) { |
| 1568 |
err := IncorrectCookieParamArrayBoolean(param, "bad", sch, sch, "/test", "get", "{}") |
| 1569 |
require.NotNil(t, err) |
| 1570 |
require.Equal(t, 1, err.SpecLine) |
| 1571 |
require.Equal(t, 0, err.SpecCol) |
| 1572 |
}) |
| 1573 |
|
| 1574 |
t.Run("IncorrectQueryParamArrayInteger", func(t *testing.T) { |
| 1575 |
err := IncorrectQueryParamArrayInteger(param, "bad", sch, sch, "/test", "get", "{}") |
| 1576 |
require.NotNil(t, err) |
| 1577 |
require.Equal(t, 1, err.SpecLine) |
| 1578 |
require.Equal(t, 0, err.SpecCol) |
| 1579 |
}) |
| 1580 |
|
| 1581 |
t.Run("IncorrectQueryParamArrayNumber", func(t *testing.T) { |
| 1582 |
err := IncorrectQueryParamArrayNumber(param, "bad", sch, sch, "/test", "get", "{}") |
| 1583 |
require.NotNil(t, err) |
| 1584 |
require.Equal(t, 1, err.SpecLine) |
| 1585 |
require.Equal(t, 0, err.SpecCol) |
| 1586 |
}) |
| 1587 |
|
| 1588 |
t.Run("IncorrectCookieParamArrayNumber", func(t *testing.T) { |
| 1589 |
err := IncorrectCookieParamArrayNumber(param, "bad", sch, sch, "/test", "get", "{}") |
| 1590 |
require.NotNil(t, err) |
| 1591 |
require.Equal(t, 1, err.SpecLine) |
| 1592 |
require.Equal(t, 0, err.SpecCol) |
| 1593 |
}) |
| 1594 |
|
| 1595 |
t.Run("IncorrectHeaderParamArrayBoolean", func(t *testing.T) { |
| 1596 |
err := IncorrectHeaderParamArrayBoolean(param, "bad", sch, sch, "/test", "get", "{}") |
| 1597 |
require.NotNil(t, err) |
| 1598 |
require.Equal(t, 1, err.SpecLine) |
| 1599 |
require.Equal(t, 0, err.SpecCol) |
| 1600 |
}) |
| 1601 |
|
| 1602 |
t.Run("IncorrectHeaderParamArrayNumber", func(t *testing.T) { |
| 1603 |
err := IncorrectHeaderParamArrayNumber(param, "bad", sch, sch, "/test", "get", "{}") |
| 1604 |
require.NotNil(t, err) |
| 1605 |
require.Equal(t, 1, err.SpecLine) |
| 1606 |
require.Equal(t, 0, err.SpecCol) |
| 1607 |
}) |
| 1608 |
|
| 1609 |
t.Run("IncorrectPathParamArrayNumber", func(t *testing.T) { |
| 1610 |
err := IncorrectPathParamArrayNumber(param, "bad", sch, sch, "/test", "{}") |
| 1611 |
require.NotNil(t, err) |
| 1612 |
require.Equal(t, 1, err.SpecLine) |
| 1613 |
require.Equal(t, 0, err.SpecCol) |
| 1614 |
}) |
| 1615 |
|
| 1616 |
t.Run("IncorrectPathParamArrayInteger", func(t *testing.T) { |
| 1617 |
err := IncorrectPathParamArrayInteger(param, "bad", sch, sch, "/test", "{}") |
| 1618 |
require.NotNil(t, err) |
| 1619 |
require.Equal(t, 1, err.SpecLine) |
| 1620 |
require.Equal(t, 0, err.SpecCol) |
| 1621 |
}) |
| 1622 |
|
| 1623 |
t.Run("IncorrectPathParamArrayBoolean", func(t *testing.T) { |
| 1624 |
err := IncorrectPathParamArrayBoolean(param, "bad", sch, sch, "/test", "{}") |
| 1625 |
require.NotNil(t, err) |
| 1626 |
require.Equal(t, 1, err.SpecLine) |
| 1627 |
require.Equal(t, 0, err.SpecCol) |
| 1628 |
}) |
| 1629 |
} |