@@ -461,7 +461,9 @@ func createMockParameter() *v3.Parameter {
461461 ValueNode : & yaml.Node {},
462462 },
463463 Schema : low.NodeReference [* lowbase.SchemaProxy ]{
464- Value : schemaProxy ,
464+ Value : schemaProxy ,
465+ KeyNode : & yaml.Node {},
466+ ValueNode : & yaml.Node {},
465467 },
466468 }
467469 return v3 .NewParameter (param )
@@ -545,3 +547,147 @@ func TestIncorrectQueryParamBool(t *testing.T) {
545547 require .Contains (t , err .Reason , "the value 'notBoolean' is not a valid boolean" )
546548 require .Contains (t , err .HowToFix , "true/false" )
547549}
550+
551+ func TestInvalidQueryParamNumber (t * testing.T ) {
552+ param := createMockParameter ()
553+ baseSchema := createMockLowBaseSchema ()
554+
555+ // Call the function with an invalid number value
556+ err := InvalidQueryParamNumber (param , "notNumber" , base .NewSchema (baseSchema ))
557+
558+ // Validate the error
559+ require .NotNil (t , err )
560+ require .Equal (t , helpers .ParameterValidation , err .ValidationType )
561+ require .Equal (t , helpers .ParameterValidationQuery , err .ValidationSubType )
562+ require .Contains (t , err .Message , "Query parameter 'testQueryParam' is not a valid number" )
563+ require .Contains (t , err .Reason , "the value 'notNumber' is not a valid number" )
564+ require .Contains (t , err .HowToFix , "notNumber" )
565+ }
566+
567+ func TestIncorrectQueryParamEnum (t * testing.T ) {
568+
569+ enum := `enum: [fish, crab, lobster]`
570+ var n yaml.Node
571+ _ = yaml .Unmarshal ([]byte (enum ), & n )
572+
573+ schemaProxy := & lowbase.SchemaProxy {}
574+ schemaProxy .Build (context .Background (), n .Content [0 ], n .Content [0 ], nil )
575+
576+ highSchema := base .NewSchema (schemaProxy .Schema ())
577+ param := createMockParameter ()
578+ param .Schema = base .CreateSchemaProxy (highSchema )
579+ param .GoLow ().Schema .Value .Schema ().Enum .KeyNode = & yaml.Node {}
580+
581+ // Call the function with an invalid enum value
582+ err := IncorrectQueryParamEnum (param , "invalidEnum" , highSchema )
583+
584+ // Validate the error
585+ require .NotNil (t , err )
586+ require .Equal (t , helpers .ParameterValidation , err .ValidationType )
587+ require .Equal (t , helpers .ParameterValidationQuery , err .ValidationSubType )
588+ require .Contains (t , err .Message , "Query parameter 'testQueryParam' does not match allowed values" )
589+ require .Contains (t , err .Reason , "'invalidEnum' is not one of those values" )
590+ require .Contains (t , err .HowToFix , "fish, crab, lobster" )
591+ }
592+
593+ func TestIncorrectQueryParamEnumArray (t * testing.T ) {
594+
595+ enum := `items:
596+ enum: [fish, crab, lobster]`
597+ var n yaml.Node
598+ _ = yaml .Unmarshal ([]byte (enum ), & n )
599+
600+ schemaProxy := & lowbase.SchemaProxy {}
601+ schemaProxy .Build (context .Background (), n .Content [0 ], n .Content [0 ], nil )
602+
603+ highSchema := base .NewSchema (schemaProxy .Schema ())
604+ param := createMockParameter ()
605+ param .Schema = base .CreateSchemaProxy (highSchema )
606+ param .GoLow ().Schema .Value = schemaProxy
607+ param .GoLow ().Schema .Value .Schema ().Items .Value .A .Schema ().Enum .Value = []low.ValueReference [* yaml.Node ]{
608+ {Value : & yaml.Node {Value : "fish, crab, lobster" }},
609+ }
610+
611+ // Call the function with an invalid enum value
612+ err := IncorrectQueryParamEnumArray (param , "invalidEnum" , highSchema )
613+
614+ // Validate the error
615+ require .NotNil (t , err )
616+ require .Equal (t , helpers .ParameterValidation , err .ValidationType )
617+ require .Equal (t , helpers .ParameterValidationQuery , err .ValidationSubType )
618+ require .Contains (t , err .Message , "Query array parameter 'testQueryParam' does not match allowed values" )
619+ require .Contains (t , err .Reason , "'invalidEnum' is not one of those values" )
620+ require .Contains (t , err .HowToFix , "fish, crab, lobster" )
621+ }
622+
623+ func TestIncorrectReservedValues (t * testing.T ) {
624+
625+ enum := `name: bork`
626+ var n yaml.Node
627+ _ = yaml .Unmarshal ([]byte (enum ), & n )
628+
629+ schemaProxy := & lowbase.SchemaProxy {}
630+ schemaProxy .Build (context .Background (), n .Content [0 ], n .Content [0 ], nil )
631+
632+ highSchema := base .NewSchema (schemaProxy .Schema ())
633+ param := createMockParameter ()
634+ param .Name = "borked::?^&*"
635+
636+ err := IncorrectReservedValues (param , "borked::?^&*" , highSchema )
637+
638+ // Validate the error
639+ require .NotNil (t , err )
640+ require .Equal (t , helpers .ParameterValidation , err .ValidationType )
641+ require .Equal (t , helpers .ParameterValidationQuery , err .ValidationSubType )
642+ require .Contains (t , err .Message , "Query parameter 'borked::?^&*' value contains reserved values" )
643+ require .Contains (t , err .Reason , "The query parameter 'borked::?^&*' has 'allowReserved' set to false" )
644+ require .Contains (t , err .HowToFix , "borked%3A%3A%3F%5E%26%2A" )
645+ }
646+
647+ func TestInvalidHeaderParamNumber (t * testing.T ) {
648+
649+ enum := `name: blip`
650+ var n yaml.Node
651+ _ = yaml .Unmarshal ([]byte (enum ), & n )
652+
653+ schemaProxy := & lowbase.SchemaProxy {}
654+ schemaProxy .Build (context .Background (), n .Content [0 ], n .Content [0 ], nil )
655+
656+ highSchema := base .NewSchema (schemaProxy .Schema ())
657+ param := createMockParameter ()
658+ param .Name = "bunny"
659+
660+ err := InvalidHeaderParamNumber (param , "bunmy" , highSchema )
661+
662+ // Validate the error
663+ require .NotNil (t , err )
664+ require .Equal (t , helpers .ParameterValidation , err .ValidationType )
665+ require .Equal (t , helpers .ParameterValidationHeader , err .ValidationSubType )
666+ require .Contains (t , err .Message , "Header parameter 'bunny' is not a valid number" )
667+ require .Contains (t , err .Reason , "The header parameter 'bunny' is defined as being a number" )
668+ require .Contains (t , err .HowToFix , "bunmy" )
669+ }
670+
671+ func TestInvalidCookieParamNumber (t * testing.T ) {
672+
673+ enum := `name: blip`
674+ var n yaml.Node
675+ _ = yaml .Unmarshal ([]byte (enum ), & n )
676+
677+ schemaProxy := & lowbase.SchemaProxy {}
678+ schemaProxy .Build (context .Background (), n .Content [0 ], n .Content [0 ], nil )
679+
680+ highSchema := base .NewSchema (schemaProxy .Schema ())
681+ param := createMockParameter ()
682+ param .Name = "cookies"
683+
684+ err := InvalidCookieParamNumber (param , "milky" , highSchema )
685+
686+ // Validate the error
687+ require .NotNil (t , err )
688+ require .Equal (t , helpers .ParameterValidation , err .ValidationType )
689+ require .Equal (t , helpers .ParameterValidationCookie , err .ValidationSubType )
690+ require .Contains (t , err .Message , "Cookie parameter 'cookies' is not a valid number" )
691+ require .Contains (t , err .Reason , "The cookie parameter 'cookies' is defined as being a number" )
692+ require .Contains (t , err .HowToFix , "milky" )
693+ }
0 commit comments