1- // Copyright 2023 Princess B33f Heavy Industries / Dave Shanley
1+ // Copyright 2023-2026 Princess Beef Heavy Industries, LLC / Dave Shanley
22// SPDX-License-Identifier: MIT
33
44package helpers
@@ -938,7 +938,7 @@ func TestConstructParamMapFromPipeEncodingWithSchema(t *testing.T) {
938938 }
939939 result := ConstructParamMapFromPipeEncodingWithSchema (params , sch )
940940 props := result ["key1" ].(map [string ]interface {})
941- require .Equal (t , "123" , props ["name" ]) // string because schema says string
941+ require .Equal (t , "123" , props ["name" ]) // string because schema says string
942942 require .Equal (t , int64 (42 ), props ["count" ]) // int because schema says integer
943943}
944944
@@ -964,8 +964,8 @@ func TestConstructMapFromCSVWithSchema(t *testing.T) {
964964 }),
965965 }
966966 result := ConstructMapFromCSVWithSchema ("id,99,rank,3.5" , sch )
967- require .Equal (t , "99" , result ["id" ]) // string
968- require .Equal (t , 3.5 , result ["rank" ]) // number
967+ require .Equal (t , "99" , result ["id" ]) // string
968+ require .Equal (t , 3.5 , result ["rank" ]) // number
969969
970970 // odd number of values
971971 result = ConstructMapFromCSVWithSchema ("id,99,rank" , sch )
@@ -1042,3 +1042,65 @@ func TestConstructParamMapFromFormEncodingArrayWithSchema(t *testing.T) {
10421042 require .Equal (t , "val" , props ["key1" ])
10431043 require .NotContains (t , props , "key2" )
10441044}
1045+
1046+ func TestEffectiveSecurityForOperation (t * testing.T ) {
1047+ globalSecurity := []* base.SecurityRequirement {
1048+ {
1049+ Requirements : orderedmap .ToOrderedMap (map [string ][]string {
1050+ "GlobalAuth" : {},
1051+ }),
1052+ },
1053+ }
1054+
1055+ opSecurity := []* base.SecurityRequirement {
1056+ {
1057+ Requirements : orderedmap .ToOrderedMap (map [string ][]string {
1058+ "OpAuth" : {},
1059+ }),
1060+ },
1061+ }
1062+
1063+ t .Run ("operation-level security wins over global" , func (t * testing.T ) {
1064+ pathItem := & v3.PathItem {
1065+ Get : & v3.Operation {Security : opSecurity },
1066+ }
1067+ request , _ := http .NewRequest (http .MethodGet , "/" , nil )
1068+ result := EffectiveSecurityForOperation (request , pathItem , globalSecurity )
1069+ require .Equal (t , opSecurity , result )
1070+ })
1071+
1072+ t .Run ("nil operation security falls back to global" , func (t * testing.T ) {
1073+ pathItem := & v3.PathItem {
1074+ Get : & v3.Operation {}, // Security is nil
1075+ }
1076+ request , _ := http .NewRequest (http .MethodGet , "/" , nil )
1077+ result := EffectiveSecurityForOperation (request , pathItem , globalSecurity )
1078+ require .Equal (t , globalSecurity , result )
1079+ })
1080+
1081+ t .Run ("empty operation security means no security (opt-out)" , func (t * testing.T ) {
1082+ pathItem := & v3.PathItem {
1083+ Get : & v3.Operation {Security : []* base.SecurityRequirement {}},
1084+ }
1085+ request , _ := http .NewRequest (http .MethodGet , "/" , nil )
1086+ result := EffectiveSecurityForOperation (request , pathItem , globalSecurity )
1087+ require .NotNil (t , result )
1088+ require .Len (t , result , 0 )
1089+ })
1090+
1091+ t .Run ("both nil returns nil" , func (t * testing.T ) {
1092+ pathItem := & v3.PathItem {
1093+ Get : & v3.Operation {},
1094+ }
1095+ request , _ := http .NewRequest (http .MethodGet , "/" , nil )
1096+ result := EffectiveSecurityForOperation (request , pathItem , nil )
1097+ require .Nil (t , result )
1098+ })
1099+
1100+ t .Run ("nil operation falls back to global" , func (t * testing.T ) {
1101+ pathItem := & v3.PathItem {} // no Get operation
1102+ request , _ := http .NewRequest (http .MethodGet , "/" , nil )
1103+ result := EffectiveSecurityForOperation (request , pathItem , globalSecurity )
1104+ require .Equal (t , globalSecurity , result )
1105+ })
1106+ }
0 commit comments