Files
argo-cd/util/security/application_namespaces_test.go
Arthur Vardevanyan 588b251acc feat(sourceNamespace): Regex Support (#19016) (#19017)
* feat(sourceNamespace): Regex Support

Signed-off-by: Arthur <arthur@arthurvardevanyan.com>

* feat(sourceNamespace): Separate exactMatch into patternMatch

Signed-off-by: Arthur <arthur@arthurvardevanyan.com>

---------

Signed-off-by: Arthur <arthur@arthurvardevanyan.com>
2024-08-13 08:46:25 -04:00

77 lines
1.3 KiB
Go

package security
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_IsNamespaceEnabled(t *testing.T) {
testCases := []struct {
name string
namespace string
serverNamespace string
enabledNamespaces []string
expectedResult bool
}{
{
"namespace is empty",
"argocd",
"argocd",
[]string{},
true,
},
{
"namespace is explicitly server namespace",
"argocd",
"argocd",
[]string{},
true,
},
{
"namespace is allowed namespace",
"allowed",
"argocd",
[]string{"allowed"},
true,
},
{
"namespace matches pattern",
"test-ns",
"argocd",
[]string{"test-*"},
true,
},
{
"namespace is not allowed namespace",
"disallowed",
"argocd",
[]string{"allowed"},
false,
},
{
"match everything but specified word: fail",
"disallowed",
"argocd",
[]string{"/^((?!disallowed).)*$/"},
false,
},
{
"match everything but specified word: pass",
"allowed",
"argocd",
[]string{"/^((?!disallowed).)*$/"},
true,
},
}
for _, tc := range testCases {
tcc := tc
t.Run(tcc.name, func(t *testing.T) {
t.Parallel()
result := IsNamespaceEnabled(tcc.namespace, tcc.serverNamespace, tcc.enabledNamespaces)
assert.Equal(t, tcc.expectedResult, result)
})
}
}