|
|
@ -2767,31 +2767,57 @@ service "bar" {
|
|
|
|
|
|
|
|
|
|
|
|
func TestACL_filterCoordinates(t *testing.T) {
|
|
|
|
func TestACL_filterCoordinates(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
t.Parallel()
|
|
|
|
// Create some coordinates.
|
|
|
|
|
|
|
|
coords := structs.Coordinates{
|
|
|
|
|
|
|
|
&structs.Coordinate{
|
|
|
|
|
|
|
|
Node: "node1",
|
|
|
|
|
|
|
|
Coord: generateRandomCoordinate(),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
&structs.Coordinate{
|
|
|
|
|
|
|
|
Node: "node2",
|
|
|
|
|
|
|
|
Coord: generateRandomCoordinate(),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Try permissive filtering.
|
|
|
|
logger := hclog.NewNullLogger()
|
|
|
|
filt := newACLFilter(acl.AllowAll(), nil)
|
|
|
|
|
|
|
|
filt.filterCoordinates(&coords)
|
|
|
|
|
|
|
|
if len(coords) != 2 {
|
|
|
|
|
|
|
|
t.Fatalf("bad: %#v", coords)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Try restrictive filtering
|
|
|
|
makeList := func() *structs.IndexedCoordinates {
|
|
|
|
filt = newACLFilter(acl.DenyAll(), nil)
|
|
|
|
return &structs.IndexedCoordinates{
|
|
|
|
filt.filterCoordinates(&coords)
|
|
|
|
Coordinates: structs.Coordinates{
|
|
|
|
if len(coords) != 0 {
|
|
|
|
{Node: "node1", Coord: generateRandomCoordinate()},
|
|
|
|
t.Fatalf("bad: %#v", coords)
|
|
|
|
{Node: "node2", Coord: generateRandomCoordinate()},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.Run("allowed", func(t *testing.T) {
|
|
|
|
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
list := makeList()
|
|
|
|
|
|
|
|
filterACLWithAuthorizer(logger, acl.AllowAll(), list)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require.Len(list.Coordinates, 2)
|
|
|
|
|
|
|
|
require.False(list.QueryMeta.ResultsFilteredByACLs, "ResultsFilteredByACLs should be false")
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.Run("allowed to read one node", func(t *testing.T) {
|
|
|
|
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
policy, err := acl.NewPolicyFromSource(`
|
|
|
|
|
|
|
|
node "node1" {
|
|
|
|
|
|
|
|
policy = "read"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
`, acl.SyntaxLegacy, nil, nil)
|
|
|
|
|
|
|
|
require.NoError(err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
authz, err := acl.NewPolicyAuthorizerWithDefaults(acl.DenyAll(), []*acl.Policy{policy}, nil)
|
|
|
|
|
|
|
|
require.NoError(err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
list := makeList()
|
|
|
|
|
|
|
|
filterACLWithAuthorizer(logger, authz, list)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require.Len(list.Coordinates, 1)
|
|
|
|
|
|
|
|
require.True(list.QueryMeta.ResultsFilteredByACLs, "ResultsFilteredByACLs should be true")
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.Run("denied", func(t *testing.T) {
|
|
|
|
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
list := makeList()
|
|
|
|
|
|
|
|
filterACLWithAuthorizer(logger, acl.DenyAll(), list)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require.Empty(list.Coordinates)
|
|
|
|
|
|
|
|
require.True(list.QueryMeta.ResultsFilteredByACLs, "ResultsFilteredByACLs should be true")
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestACL_filterSessions(t *testing.T) {
|
|
|
|
func TestACL_filterSessions(t *testing.T) {
|
|
|
|