5
5
create_secret ,
6
6
find_fixture ,
7
7
read_secret ,
8
+ try_load ,
8
9
update_secret ,
9
10
wait_until ,
10
11
)
22
23
USER_DATABASE = "admin"
23
24
24
25
25
- @fixture (scope = "module" )
26
+ def create_password_secret (namespace : str ) -> str :
27
+ create_or_update_secret (
28
+ namespace ,
29
+ PASSWORD_SECRET_NAME ,
30
+ {"password" : USER_PASSWORD },
31
+ )
32
+ return PASSWORD_SECRET_NAME
33
+
34
+
35
+ @fixture (scope = "function" )
26
36
def replica_set (namespace : str , custom_mdb_version ) -> MongoDB :
27
37
resource = MongoDB .from_yaml (
28
38
find_fixture ("replica-set-scram-sha-256.yaml" ),
@@ -36,21 +46,16 @@ def replica_set(namespace: str, custom_mdb_version) -> MongoDB:
36
46
"enabled" : True ,
37
47
"modes" : ["SCRAM" ],
38
48
}
39
-
40
- return resource . update ()
49
+ try_load ( resource )
50
+ return resource
41
51
42
52
43
53
@fixture (scope = "function" )
44
54
def scram_user (namespace : str ) -> MongoDBUser :
45
55
resource = MongoDBUser .from_yaml (find_fixture ("scram-sha-user.yaml" ), namespace = namespace )
46
56
47
- create_or_update_secret (
48
- KubernetesTester .get_namespace (),
49
- resource .get_secret_name (),
50
- {"password" : USER_PASSWORD },
51
- )
52
-
53
- return resource .update ()
57
+ try_load (resource )
58
+ return resource
54
59
55
60
56
61
@fixture (scope = "function" )
@@ -67,6 +72,7 @@ def connection_string_secret(replica_set: MongoDB):
67
72
@mark .e2e_replica_set_scram_sha_256_user_connectivity
68
73
class TestReplicaSetCreation (KubernetesTester ):
69
74
def test_replica_set_created (self , replica_set : MongoDB ):
75
+ replica_set .create ()
70
76
replica_set .assert_reaches_phase (Phase .Running , timeout = 400 )
71
77
72
78
def test_replica_set_connectivity (self , replica_set : MongoDB ):
@@ -82,7 +88,9 @@ def test_ops_manager_state_correctly_updated(self, replica_set: MongoDB):
82
88
83
89
84
90
@mark .e2e_replica_set_scram_sha_256_user_connectivity
85
- def test_create_user (scram_user : MongoDBUser ):
91
+ def test_create_user (scram_user : MongoDBUser , namespace : str ):
92
+ create_password_secret (namespace )
93
+ scram_user .create ()
86
94
scram_user .assert_reaches_phase (Phase .Updated )
87
95
88
96
@@ -124,10 +132,15 @@ def test_user_cannot_authenticate_with_incorrect_password(self, replica_set: Mon
124
132
125
133
@mark .e2e_replica_set_scram_sha_256_user_connectivity
126
134
class TestCanChangePassword (KubernetesTester ):
127
- def test_user_can_authenticate_with_new_password (self , namespace : str , replica_set : MongoDB ):
128
- update_secret (namespace , PASSWORD_SECRET_NAME , {"password" : "my-new-password7" })
135
+ def test_user_can_authenticate_with_new_password (
136
+ self , scram_user : MongoDBUser , namespace : str , replica_set : MongoDB
137
+ ):
138
+ new_password = "my-new-password7"
139
+ update_secret (namespace , PASSWORD_SECRET_NAME , {"password" : new_password })
140
+ scram_user .assert_reaches_phase (Phase .Updated )
141
+
129
142
replica_set .tester ().assert_scram_sha_authentication (
130
- password = "my-new-password7" ,
143
+ password = new_password ,
131
144
username = "mms-user-1" ,
132
145
auth_mechanism = "SCRAM-SHA-256" ,
133
146
)
0 commit comments