34140ff3e0
Previously, public referred to gRPC services that are both exposed on the dedicated gRPC port and have their definitions in the proto-public directory (so were considered usable by 3rd parties). Whereas private referred to services on the multiplexed server port that are only usable by agents and other servers. Now, we're splitting these definitions, such that external/internal refers to the port and public/private refers to whether they can be used by 3rd parties. This is necessary because the peering replication API needs to be exposed on the dedicated port, but is not (yet) suitable for use by 3rd parties.
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package testutils
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/hashicorp/consul/acl"
|
|
"github.com/hashicorp/consul/acl/resolver"
|
|
)
|
|
|
|
func TestAuthorizerAllowAll(t *testing.T) resolver.Result {
|
|
t.Helper()
|
|
|
|
return resolver.Result{Authorizer: acl.AllowAll()}
|
|
}
|
|
|
|
func TestAuthorizerDenyAll(t *testing.T) resolver.Result {
|
|
t.Helper()
|
|
|
|
return resolver.Result{Authorizer: acl.DenyAll()}
|
|
}
|
|
|
|
func TestAuthorizerServiceWriteAny(t *testing.T) resolver.Result {
|
|
t.Helper()
|
|
|
|
policy, err := acl.NewPolicyFromSource(`
|
|
service "foo" {
|
|
policy = "write"
|
|
}
|
|
`, acl.SyntaxCurrent, nil, nil)
|
|
require.NoError(t, err)
|
|
|
|
authz, err := acl.NewPolicyAuthorizerWithDefaults(acl.DenyAll(), []*acl.Policy{policy}, nil)
|
|
require.NoError(t, err)
|
|
|
|
return resolver.Result{Authorizer: authz}
|
|
}
|
|
|
|
func TestAuthorizerServiceRead(t *testing.T, serviceName string) resolver.Result {
|
|
t.Helper()
|
|
|
|
aclRule := &acl.Policy{
|
|
PolicyRules: acl.PolicyRules{
|
|
Services: []*acl.ServiceRule{
|
|
{
|
|
Name: serviceName,
|
|
Policy: acl.PolicyRead,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
authz, err := acl.NewPolicyAuthorizerWithDefaults(acl.DenyAll(), []*acl.Policy{aclRule}, nil)
|
|
require.NoError(t, err)
|
|
|
|
return resolver.Result{Authorizer: authz}
|
|
}
|