consul: fail badly if an unsupported type is passed to the ACL filter

This commit is contained in:
Ryan Uber 2015-06-11 16:46:15 -07:00
parent f5f7e401d5
commit 389f89274a
3 changed files with 22 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package consul
import (
"errors"
"fmt"
"log"
"os"
"strings"
@ -355,6 +356,9 @@ func (s *Server) filterACL(token string, subj interface{}) error {
case *structs.IndexedNodeDump:
filt.filterNodeDump(&v.Dump)
default:
panic(fmt.Errorf("Unhandled type passed to ACL filter: %#v", subj))
}
return nil

View File

@ -861,6 +861,23 @@ func TestACL_filterNodeDump(t *testing.T) {
}
}
func TestACL_unhandledFilterType(t *testing.T) {
defer func(t *testing.T) {
if recover() == nil {
t.Fatalf("should panic")
}
}(t)
// Create the server
dir, token, srv, client := testACLFilterServer(t)
defer os.RemoveAll(dir)
defer srv.Shutdown()
defer client.Close()
// Pass an unhandled type into the ACL filter.
srv.filterACL(token, &structs.HealthCheck{})
}
var testACLPolicy = `
key "" {
policy = "deny"

View File

@ -126,7 +126,7 @@ func (c *Catalog) ListNodes(args *structs.DCSpecificRequest, reply *structs.Inde
state.QueryTables("Nodes"),
func() error {
reply.Index, reply.Nodes = state.Nodes()
return c.srv.filterACL(args.Token, reply)
return nil
})
}