@@ -48,10 +48,21 @@ func newMockedSecretGetUpdateCreateDeleter(secrets ...corev1.Secret) secret.GetU
4848 }
4949 return mockSecretGetUpdateCreateDeleter
5050}
51+
5152func notFoundError () error {
5253 return & errors.StatusError {ErrStatus : metav1.Status {Reason : metav1 .StatusReasonNotFound }}
5354}
5455
56+ func TestUsernameIsTransformedAndValid (t * testing.T ) {
57+ user := buildMongoDBUser ("name_with@weird?chars" )
58+ mdb := buildConfigurable ("mdb" )
59+ assert .Equal (t , "mdb-admin-name-with-weird-chars-user" , user .GetConnectionStringSecretName (mdb ))
60+ }
61+
62+ func TestUsernameCanHaveAn (t * testing.T ) {
63+ assert .Equal (t , "normalize-username-with-no-allowed-chars-only" , normalizeUsername ("?_normalize/_-username/?@with/[]?no]?/:allowed:chars[only?" ))
64+ }
65+
5566func TestReadExistingCredentials (t * testing.T ) {
5667 mdbObjectKey := types.NamespacedName {Name : "mdb-0" , Namespace : "default" }
5768 user := buildMongoDBUser ("mdbuser-0" )
@@ -74,7 +85,6 @@ func TestReadExistingCredentials(t *testing.T) {
7485 _ , _ , err := readExistingCredentials (newMockedSecretGetUpdateCreateDeleter (scramCredsSecret ), mdbObjectKey , "different-username" )
7586 assert .Error (t , err )
7687 })
77-
7888}
7989
8090func TestComputeScramCredentials_ComputesSameStoredAndServerKey_WithSameSalt (t * testing.T ) {
@@ -136,7 +146,6 @@ func TestEnsureScramCredentials(t *testing.T) {
136146 assert .NotEmpty (t , scram256Creds .ServerKey )
137147 assert .Equal (t , 15000 , scram256Creds .IterationCount )
138148 })
139-
140149}
141150
142151func TestConvertMongoDBUserToAutomationConfigUser (t * testing.T ) {
0 commit comments