@@ -3,7 +3,7 @@ package replica_set_remove_user
3
3
import (
4
4
"context"
5
5
"fmt"
6
- v1 "github.com/mongodb/mongodb-kubernetes-operator/api/v1"
6
+ mdbv1 "github.com/mongodb/mongodb-kubernetes-operator/api/v1"
7
7
"github.com/mongodb/mongodb-kubernetes-operator/pkg/automationconfig"
8
8
e2eutil "github.com/mongodb/mongodb-kubernetes-operator/test/e2e"
9
9
"github.com/mongodb/mongodb-kubernetes-operator/test/e2e/mongodbtests"
@@ -36,28 +36,6 @@ func TestCleanupUsers(t *testing.T) {
36
36
t .Fatal (err )
37
37
}
38
38
39
- lcr := automationconfig.CrdLogRotate {
40
- // fractional values are supported
41
- SizeThresholdMB : "0.1" ,
42
- LogRotate : automationconfig.LogRotate {
43
- TimeThresholdHrs : 1 ,
44
- NumUncompressed : 10 ,
45
- NumTotal : 10 ,
46
- IncludeAuditLogsWithMongoDBLogs : false ,
47
- },
48
- PercentOfDiskspace : "1" ,
49
- }
50
-
51
- systemLog := automationconfig.SystemLog {
52
- Destination : automationconfig .File ,
53
- Path : "/tmp/mongod.log" ,
54
- LogAppend : false ,
55
- }
56
-
57
- // logRotate can only be configured if systemLog to file has been configured
58
- mdb .Spec .AgentConfiguration .LogRotate = & lcr
59
- mdb .Spec .AgentConfiguration .SystemLog = & systemLog
60
-
61
39
// config member options
62
40
memberOptions := []automationconfig.MemberOptions {
63
41
{
@@ -81,8 +59,46 @@ func TestCleanupUsers(t *testing.T) {
81
59
settings := map [string ]interface {}{
82
60
"electionTimeoutMillis" : float64 (20 ),
83
61
}
84
- mdb .Spec .AutomationConfigOverride = & v1.AutomationConfigOverride {
85
- ReplicaSet : v1.OverrideReplicaSet {Settings : v1.MapWrapper {Object : settings }},
62
+ mdb .Spec .AutomationConfigOverride = & mdbv1.AutomationConfigOverride {
63
+ ReplicaSet : mdbv1.OverrideReplicaSet {Settings : mdbv1.MapWrapper {Object : settings }},
64
+ }
65
+
66
+ newUser := mdbv1.MongoDBUser {
67
+ Name : fmt .Sprintf ("%s-user-2" , "mdb-0" ),
68
+ PasswordSecretRef : mdbv1.SecretKeyReference {
69
+ Key : fmt .Sprintf ("%s-password-2" , "mdb-0" ),
70
+ Name : fmt .Sprintf ("%s-%s-password-secret-2" , "mdb-0" , testCtx .ExecutionId ),
71
+ },
72
+ Roles : []mdbv1.Role {
73
+ // roles on testing db for general connectivity
74
+ {
75
+ DB : "testing" ,
76
+ Name : "readWrite" ,
77
+ },
78
+ {
79
+ DB : "testing" ,
80
+ Name : "clusterAdmin" ,
81
+ },
82
+ // admin roles for reading FCV
83
+ {
84
+ DB : "admin" ,
85
+ Name : "readWrite" ,
86
+ },
87
+ {
88
+ DB : "admin" ,
89
+ Name : "clusterAdmin" ,
90
+ },
91
+ {
92
+ DB : "admin" ,
93
+ Name : "userAdmin" ,
94
+ },
95
+ },
96
+ ScramCredentialsSecretName : fmt .Sprintf ("%s-my-scram-2" , "mdb-0" ),
97
+ }
98
+
99
+ _ , err = setup .GeneratePasswordForUser (testCtx , newUser , "" )
100
+ if err != nil {
101
+ t .Fatal (err )
86
102
}
87
103
88
104
tester , err := FromResource (ctx , t , mdb )
@@ -93,11 +109,16 @@ func TestCleanupUsers(t *testing.T) {
93
109
t .Run ("Create MongoDB Resource" , mongodbtests .CreateMongoDBResource (& mdb , testCtx ))
94
110
t .Run ("Basic tests" , mongodbtests .BasicFunctionality (ctx , & mdb ))
95
111
t .Run ("Keyfile authentication is configured" , tester .HasKeyfileAuth (3 ))
96
- t .Run ("AutomationConfig has the correct logRotateConfig" , mongodbtests .AutomationConfigHasLogRotationConfig (ctx , & mdb , & lcr ))
97
112
t .Run ("Test Basic Connectivity" , tester .ConnectivitySucceeds ())
98
113
t .Run ("Test SRV Connectivity" , tester .ConnectivitySucceeds (WithURI (mdb .MongoSRVURI ("" )), WithoutTls (), WithReplicaSet (mdb .Name )))
99
- deletedUser := mdb .Spec .Users [0 ]
100
- t .Run ("Delete user from MongoDB Resource" , mongodbtests .RemoveAllUsersFromResource (ctx , & mdb ))
114
+ t .Run ("Add new user to MongoDB Resource" , mongodbtests .AddUserToMongoDBCommunity (ctx , & mdb , newUser ))
115
+ t .Run ("MongoDB reaches Running phase" , mongodbtests .MongoDBReachesRunningPhase (ctx , & mdb ))
116
+ editedUser := mdb .Spec .Users [1 ]
117
+ t .Run ("Edit connection string secret name of the added user" , mongodbtests .EditConnectionStringSecretNameOfLastUser (ctx , & mdb , "other-secret-name" ))
118
+ t .Run ("MongoDB reaches Running phase" , mongodbtests .MongoDBReachesRunningPhase (ctx , & mdb ))
119
+ t .Run ("Old connection string secret is cleaned up" , mongodbtests .ConnectionStringSecretIsCleanedUp (ctx , & mdb , editedUser .GetConnectionStringSecretName (mdb .Name )))
120
+ deletedUser := mdb .Spec .Users [1 ]
121
+ t .Run ("Remove last user from MongoDB Resource" , mongodbtests .RemoveLastUserFromMongoDBCommunity (ctx , & mdb ))
101
122
t .Run ("MongoDB reaches Pending phase" , mongodbtests .MongoDBReachesPendingPhase (ctx , & mdb ))
102
123
t .Run ("Removed users are added to automation config" , mongodbtests .AuthUsersDeletedIsUpdated (ctx , & mdb , deletedUser ))
103
124
t .Run ("MongoDB reaches Running phase" , mongodbtests .MongoDBReachesRunningPhase (ctx , & mdb ))
0 commit comments