Skip to content

Commit 06effa5

Browse files
committed
address feedback
1 parent 71f26d5 commit 06effa5

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

docker/mongodb-kubernetes-tests/tests/authentication/replica_set_scram_sha_256_connectivity.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
create_secret,
66
find_fixture,
77
read_secret,
8+
try_load,
89
update_secret,
910
wait_until,
1011
)
@@ -22,7 +23,16 @@
2223
USER_DATABASE = "admin"
2324

2425

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")
2636
def replica_set(namespace: str, custom_mdb_version) -> MongoDB:
2737
resource = MongoDB.from_yaml(
2838
find_fixture("replica-set-scram-sha-256.yaml"),
@@ -36,21 +46,16 @@ def replica_set(namespace: str, custom_mdb_version) -> MongoDB:
3646
"enabled": True,
3747
"modes": ["SCRAM"],
3848
}
39-
40-
return resource.update()
49+
try_load(resource)
50+
return resource
4151

4252

4353
@fixture(scope="function")
4454
def scram_user(namespace: str) -> MongoDBUser:
4555
resource = MongoDBUser.from_yaml(find_fixture("scram-sha-user.yaml"), namespace=namespace)
4656

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
5459

5560

5661
@fixture(scope="function")
@@ -67,6 +72,7 @@ def connection_string_secret(replica_set: MongoDB):
6772
@mark.e2e_replica_set_scram_sha_256_user_connectivity
6873
class TestReplicaSetCreation(KubernetesTester):
6974
def test_replica_set_created(self, replica_set: MongoDB):
75+
replica_set.create()
7076
replica_set.assert_reaches_phase(Phase.Running, timeout=400)
7177

7278
def test_replica_set_connectivity(self, replica_set: MongoDB):
@@ -82,7 +88,9 @@ def test_ops_manager_state_correctly_updated(self, replica_set: MongoDB):
8288

8389

8490
@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()
8694
scram_user.assert_reaches_phase(Phase.Updated)
8795

8896

@@ -124,10 +132,15 @@ def test_user_cannot_authenticate_with_incorrect_password(self, replica_set: Mon
124132

125133
@mark.e2e_replica_set_scram_sha_256_user_connectivity
126134
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+
129142
replica_set.tester().assert_scram_sha_authentication(
130-
password="my-new-password7",
143+
password=new_password,
131144
username="mms-user-1",
132145
auth_mechanism="SCRAM-SHA-256",
133146
)

0 commit comments

Comments
 (0)