Check nil parameter value when processing an ACL.

This commit is contained in:
mgritter 2019-04-26 15:57:00 -07:00
parent 25cd6da6a4
commit be2f69bc4a
2 changed files with 11 additions and 1 deletions

View File

@ -709,7 +709,14 @@ func valueInParameterList(v interface{}, list []interface{}) bool {
func valueInSlice(v interface{}, list []interface{}) bool {
for _, el := range list {
if reflect.TypeOf(el).String() == "string" && reflect.TypeOf(v).String() == "string" {
if el == nil || v == nil {
// It doesn't seem possible to set up a nil entry in the list, but it is possible
// to pass in a null entry in the API request being checked. Just in case,
// nil will match nil.
if el == v {
return true
}
} else if reflect.TypeOf(el).String() == "string" && reflect.TypeOf(v).String() == "string" {
item := el.(string)
val := v.(string)

View File

@ -549,6 +549,8 @@ func testACLValuePermissions(t *testing.T, ns *namespace.Namespace) {
{"foo/bar", []string{"deny"}, []interface{}{"bad glob"}, false},
{"foo/bar", []string{"deny"}, []interface{}{"good"}, true},
{"foo/bar", []string{"allow"}, []interface{}{"good"}, true},
{"foo/bar", []string{"deny"}, []interface{}{nil}, true},
{"foo/bar", []string{"allow"}, []interface{}{nil}, true},
{"foo/baz", []string{"aLLow"}, []interface{}{"good"}, true},
{"foo/baz", []string{"deny"}, []interface{}{"bad"}, false},
{"foo/baz", []string{"deny"}, []interface{}{"good"}, false},
@ -557,6 +559,7 @@ func testACLValuePermissions(t *testing.T, ns *namespace.Namespace) {
{"foo/baz", []string{"deNy", "allow"}, []interface{}{"bad", "good"}, false},
{"foo/baz", []string{"aLLow"}, []interface{}{"bad"}, false},
{"foo/baz", []string{"Neither"}, []interface{}{"bad"}, false},
{"foo/baz", []string{"allow"}, []interface{}{nil}, false},
{"fizz/buzz", []string{"allow_multi"}, []interface{}{"good"}, true},
{"fizz/buzz", []string{"allow_multi"}, []interface{}{"good1"}, true},
{"fizz/buzz", []string{"allow_multi"}, []interface{}{"good2"}, true},