mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
Every command is cd-*: cd, cd-server, cd-repo-server, cd-application-controller, cd-applicationset-controller, cd-cmp-server, cd-commit-server, cd-dex, cd-git-ask-pass, cd-k8s-auth, cd-notification. util/argo is util/cd; util/notification/argocd is util/notification/cd. Preserved deliberately: github.com/argoproj/argocd-example-apps is an EXTERNAL repo used as an e2e fixture, and notifications-engine + pkg/v2 are real dependencies. Renaming a URL we do not own would break the tests. Two bugs I made and caught, both from a careless sed: - s/argo/cd/g turned 'argocd' into 'cdcd' in two directory names - renaming the package declaration left every call site saying argo.X go build ./... exit 0. Co-authored-by: Hanzo Dev <[email protected]>
79 lines
1.3 KiB
Go
79 lines
1.3 KiB
Go
package security
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_IsNamespaceEnabled(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
testCases := []struct {
|
|
name string
|
|
namespace string
|
|
serverNamespace string
|
|
enabledNamespaces []string
|
|
expectedResult bool
|
|
}{
|
|
{
|
|
"namespace is empty",
|
|
"cd",
|
|
"cd",
|
|
[]string{},
|
|
true,
|
|
},
|
|
{
|
|
"namespace is explicitly server namespace",
|
|
"cd",
|
|
"cd",
|
|
[]string{},
|
|
true,
|
|
},
|
|
{
|
|
"namespace is allowed namespace",
|
|
"allowed",
|
|
"cd",
|
|
[]string{"allowed"},
|
|
true,
|
|
},
|
|
{
|
|
"namespace matches pattern",
|
|
"test-ns",
|
|
"cd",
|
|
[]string{"test-*"},
|
|
true,
|
|
},
|
|
{
|
|
"namespace is not allowed namespace",
|
|
"disallowed",
|
|
"cd",
|
|
[]string{"allowed"},
|
|
false,
|
|
},
|
|
{
|
|
"match everything but specified word: fail",
|
|
"disallowed",
|
|
"cd",
|
|
[]string{"/^((?!disallowed).)*$/"},
|
|
false,
|
|
},
|
|
{
|
|
"match everything but specified word: pass",
|
|
"allowed",
|
|
"cd",
|
|
[]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)
|
|
})
|
|
}
|
|
}
|