2
0
mirror of https://github.com/status-im/consul.git synced 2025-01-12 06:44:41 +00:00
consul/proto-public/pbauth/v2beta1/traffic_permission_extras_test.go
skpratt 57bad0df85
add traffic permissions excludes and tests ()
* add traffic permissions tests

* review fixes

* Update internal/mesh/internal/controllers/sidecarproxy/builder/local_app.go

Co-authored-by: John Landa <jonathanlanda@gmail.com>

---------

Co-authored-by: John Landa <jonathanlanda@gmail.com>
2024-02-07 20:21:44 +00:00

64 lines
1.6 KiB
Go

package authv2beta1
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestTrafficPermissions_PortsOnly(t *testing.T) {
t.Run("nil", func(t *testing.T) {
var dr *DestinationRule
require.False(t, dr.PortsOnly())
})
t.Run("empty", func(t *testing.T) {
dr := &DestinationRule{}
require.False(t, dr.PortsOnly())
})
t.Run("ports", func(t *testing.T) {
dr := &DestinationRule{
PortNames: []string{"foo"},
}
require.True(t, dr.PortsOnly())
})
t.Run("excl-ports", func(t *testing.T) {
dr := &DestinationRule{
Exclude: []*ExcludePermissionRule{{PortNames: []string{"foo"}}},
}
require.True(t, dr.PortsOnly())
})
t.Run("ports-and-excl-ports", func(t *testing.T) {
dr := &DestinationRule{
PortNames: []string{"foo", "bar"},
Exclude: []*ExcludePermissionRule{{PortNames: []string{"foo"}}},
}
require.True(t, dr.PortsOnly())
})
t.Run("methods", func(t *testing.T) {
dr := &DestinationRule{
Methods: []string{"put"},
}
require.False(t, dr.PortsOnly())
})
t.Run("path", func(t *testing.T) {
dr := &DestinationRule{
PathRegex: "*",
PortNames: []string{"foo"},
}
require.False(t, dr.PortsOnly())
})
t.Run("headers", func(t *testing.T) {
dr := &DestinationRule{
Exclude: []*ExcludePermissionRule{{Headers: []*DestinationRuleHeader{{Name: "Authorization"}}, PortNames: []string{"foo"}}},
}
require.False(t, dr.PortsOnly())
})
t.Run("path-and-exclports", func(t *testing.T) {
dr := &DestinationRule{
PathExact: "/",
Exclude: []*ExcludePermissionRule{{PortNames: []string{"foo"}}},
}
require.False(t, dr.PortsOnly())
})
}