Documentation
¶
Overview ¶
Package providertest provides conformance tests for authz.Provider implementations.
Package providertest provides conformance tests for authz provider implementations.
This package follows the omnivoice testing pattern with three-tier testing:
- Interface tests: Basic interface contract compliance (always run)
- Behavior tests: Edge cases and contract guarantees (always run)
- Integration tests: Tests requiring external setup (conditional)
Example usage:
func TestConformance(t *testing.T) {
provider := simple.New()
providertest.RunAll(t, providertest.Config{
Provider: provider,
})
}
Index ¶
- func RunAll(t *testing.T, cfg Config)
- func RunBehaviorTests(t *testing.T, cfg Config)
- func RunIntegrationTests(t *testing.T, cfg Config)
- func RunInterfaceTests(t *testing.T, cfg Config)
- type Config
- type MockProvider
- func (m *MockProvider) Can(ctx context.Context, principal authz.Principal, action authz.Action, ...) (bool, error)
- func (m *MockProvider) CanAll(ctx context.Context, principal authz.Principal, actions []authz.Action, ...) (bool, error)
- func (m *MockProvider) CanAny(ctx context.Context, principal authz.Principal, actions []authz.Action, ...) (bool, error)
- func (m *MockProvider) CanForOrg(ctx context.Context, principal authz.Principal, orgID uuid.UUID, ...) (bool, error)
- func (m *MockProvider) Decide(ctx context.Context, principal authz.Principal, action authz.Action, ...) (authz.Decision, error)
- func (m *MockProvider) Filter(ctx context.Context, principal authz.Principal, action authz.Action, ...) ([]authz.Resource, error)
- func (m *MockProvider) GetRole(ctx context.Context, principal authz.Principal, orgID uuid.UUID) (string, error)
- func (m *MockProvider) IsMember(ctx context.Context, principal authz.Principal, orgID uuid.UUID) (bool, error)
- func (m *MockProvider) IsPlatformAdmin(ctx context.Context, principal authz.Principal) (bool, error)
- func (m *MockProvider) Name() string
- func (m *MockProvider) SetHierarchy(h authz.RoleHierarchy)
- func (m *MockProvider) SetPermissions(p authz.RolePermissions)
- func (m *MockProvider) SetPlatformAdmin(principalID uuid.UUID, isAdmin bool)
- func (m *MockProvider) SetRole(principalID, orgID uuid.UUID, role string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunBehaviorTests ¶
RunBehaviorTests runs edge case and contract guarantee tests.
func RunIntegrationTests ¶
RunIntegrationTests runs tests that may require external setup.
func RunInterfaceTests ¶
RunInterfaceTests runs basic interface contract compliance tests. These tests verify that the provider correctly implements the interfaces.
Types ¶
type Config ¶
type Config struct {
// Provider is the authz.Authorizer implementation to test (required).
Provider authz.Authorizer
// OrgProvider is the authz.OrgAuthorizer implementation to test (optional).
// If nil and Provider implements OrgAuthorizer, Provider will be used.
OrgProvider authz.OrgAuthorizer
// PlatformProvider is the authz.PlatformAuthorizer implementation to test (optional).
// If nil and Provider implements PlatformAuthorizer, Provider will be used.
PlatformProvider authz.PlatformAuthorizer
// DecisionProvider is the authz.DecisionAuthorizer implementation to test (optional).
// If nil and Provider implements DecisionAuthorizer, Provider will be used.
DecisionProvider authz.DecisionAuthorizer
// SkipIntegration skips integration tests that may require external setup.
SkipIntegration bool
// Timeout for test operations. Default: 30 seconds.
Timeout time.Duration
// TestPrincipalID is a UUID for test principals. Default: random UUID.
TestPrincipalID uuid.UUID
// TestOrgID is a UUID for test organizations. Default: random UUID.
TestOrgID uuid.UUID
// TestResourceID is a UUID for test resources. Default: random UUID.
TestResourceID uuid.UUID
// SetupFunc is called before each test to configure the provider.
// Use this to set up roles, permissions, etc.
SetupFunc func(t *testing.T)
}
Config configures the provider test suite.
type MockProvider ¶
type MockProvider struct {
// Test hooks for customization
CanFunc func(ctx context.Context, principal authz.Principal, action authz.Action, resource authz.Resource) (bool, error)
IsPlatformAdminFunc func(ctx context.Context, principal authz.Principal) (bool, error)
// contains filtered or unexported fields
}
MockProvider is a mock implementation of authz interfaces for testing.
func NewMockProvider ¶
func NewMockProvider() *MockProvider
NewMockProvider creates a new mock provider with default configuration.
func (*MockProvider) Can ¶
func (m *MockProvider) Can(ctx context.Context, principal authz.Principal, action authz.Action, resource authz.Resource) (bool, error)
Can checks if a principal can perform an action on a resource.
func (*MockProvider) CanAll ¶
func (m *MockProvider) CanAll(ctx context.Context, principal authz.Principal, actions []authz.Action, resource authz.Resource) (bool, error)
CanAll checks if a principal can perform all specified actions on a resource.
func (*MockProvider) CanAny ¶
func (m *MockProvider) CanAny(ctx context.Context, principal authz.Principal, actions []authz.Action, resource authz.Resource) (bool, error)
CanAny checks if a principal can perform any of the specified actions on a resource.
func (*MockProvider) CanForOrg ¶
func (m *MockProvider) CanForOrg(ctx context.Context, principal authz.Principal, orgID uuid.UUID, action authz.Action, resource authz.Resource) (bool, error)
CanForOrg checks permission scoped to a specific organization.
func (*MockProvider) Decide ¶
func (m *MockProvider) Decide(ctx context.Context, principal authz.Principal, action authz.Action, resource authz.Resource) (authz.Decision, error)
Decide returns a detailed authorization decision.
func (*MockProvider) Filter ¶
func (m *MockProvider) Filter(ctx context.Context, principal authz.Principal, action authz.Action, resources []authz.Resource) ([]authz.Resource, error)
Filter returns only the resources the principal can access with the given action.
func (*MockProvider) GetRole ¶
func (m *MockProvider) GetRole(ctx context.Context, principal authz.Principal, orgID uuid.UUID) (string, error)
GetRole returns the principal's role in an organization.
func (*MockProvider) IsMember ¶
func (m *MockProvider) IsMember(ctx context.Context, principal authz.Principal, orgID uuid.UUID) (bool, error)
IsMember checks if a principal is a member of an organization.
func (*MockProvider) IsPlatformAdmin ¶
func (m *MockProvider) IsPlatformAdmin(ctx context.Context, principal authz.Principal) (bool, error)
IsPlatformAdmin checks if a principal has platform-wide admin access.
func (*MockProvider) SetHierarchy ¶
func (m *MockProvider) SetHierarchy(h authz.RoleHierarchy)
SetHierarchy sets the role hierarchy.
func (*MockProvider) SetPermissions ¶
func (m *MockProvider) SetPermissions(p authz.RolePermissions)
SetPermissions sets the role permissions.
func (*MockProvider) SetPlatformAdmin ¶
func (m *MockProvider) SetPlatformAdmin(principalID uuid.UUID, isAdmin bool)
SetPlatformAdmin sets a principal's platform admin status.