github.com/argoproj/argo-cd/v3@v3.2.1/util/security/application_namespaces_test.go (about) 1 package security 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func Test_IsNamespaceEnabled(t *testing.T) { 10 t.Parallel() 11 12 testCases := []struct { 13 name string 14 namespace string 15 serverNamespace string 16 enabledNamespaces []string 17 expectedResult bool 18 }{ 19 { 20 "namespace is empty", 21 "argocd", 22 "argocd", 23 []string{}, 24 true, 25 }, 26 { 27 "namespace is explicitly server namespace", 28 "argocd", 29 "argocd", 30 []string{}, 31 true, 32 }, 33 { 34 "namespace is allowed namespace", 35 "allowed", 36 "argocd", 37 []string{"allowed"}, 38 true, 39 }, 40 { 41 "namespace matches pattern", 42 "test-ns", 43 "argocd", 44 []string{"test-*"}, 45 true, 46 }, 47 { 48 "namespace is not allowed namespace", 49 "disallowed", 50 "argocd", 51 []string{"allowed"}, 52 false, 53 }, 54 { 55 "match everything but specified word: fail", 56 "disallowed", 57 "argocd", 58 []string{"/^((?!disallowed).)*$/"}, 59 false, 60 }, 61 { 62 "match everything but specified word: pass", 63 "allowed", 64 "argocd", 65 []string{"/^((?!disallowed).)*$/"}, 66 true, 67 }, 68 } 69 70 for _, tc := range testCases { 71 tcc := tc 72 t.Run(tcc.name, func(t *testing.T) { 73 t.Parallel() 74 result := IsNamespaceEnabled(tcc.namespace, tcc.serverNamespace, tcc.enabledNamespaces) 75 assert.Equal(t, tcc.expectedResult, result) 76 }) 77 } 78 }