Skip to content

Commit 2d25558

Browse files
committed
Fix test_container_password typos in parameterization.
Update also test_replication.py file (pre-commit issues) Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
1 parent 6e98ee0 commit 2d25558

File tree

2 files changed

+40
-17
lines changed

2 files changed

+40
-17
lines changed

test/test_container_password.py

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88

99
from conftest import VARS
1010

11-
pwd_dir = tempfile.mkdtemp(prefix="/tmp/mysql-pwd")
11+
pwd_dir_change = tempfile.mkdtemp(prefix="/tmp/mysql-pwd")
1212
assert ContainerTestLibUtils.commands_to_run(
1313
commands_to_run=[
14-
f"chmod -R a+rwx {pwd_dir}",
14+
f"chmod -R a+rwx {pwd_dir_change}",
1515
]
1616
)
1717

18-
user_dir = tempfile.mkdtemp(prefix="/tmp/mysql-user")
18+
user_dir_change = tempfile.mkdtemp(prefix="/tmp/mysql-user")
1919
assert ContainerTestLibUtils.commands_to_run(
2020
commands_to_run=[
21-
f"chmod -R a+rwx {user_dir}",
21+
f"chmod -R a+rwx {user_dir_change}",
2222
]
2323
)
2424

@@ -45,28 +45,28 @@ def teardown_method(self):
4545
@pytest.mark.parametrize(
4646
"username, password, pwd_change, user_change, test_dir",
4747
[
48-
("user", "foo", False, False, pwd_dir),
49-
("user", "bar", True, False, pwd_dir),
50-
("user", "foo", False, True, user_dir),
51-
("user2", "bar", False, True, user_dir),
48+
("user", "foo", False, False, pwd_dir_change),
49+
("user", "bar", True, False, pwd_dir_change),
50+
("user", "foo", False, False, user_dir_change),
51+
("user2", "bar", False, True, user_dir_change),
5252
],
5353
)
5454
def test_password_change(
55-
self, username, password, pwd_change, user_change, test_dir
55+
self, username, password, pwd_change, user_change, pwd_dir
5656
):
5757
"""
5858
Test password change.
5959
"""
6060
self.password_change_test(
6161
username=username,
6262
password=password,
63-
pwd_change=pwd_change,
63+
pwd_dir=pwd_dir,
6464
user_change=user_change,
65-
test_dir=test_dir,
65+
pwd_change=pwd_change,
6666
)
6767

6868
def password_change_test(
69-
self, username, password, pwd_change, user_change, test_dir
69+
self, username, password, pwd_dir, user_change=False, pwd_change=False
7070
):
7171
"""
7272
Test password change.
@@ -81,29 +81,53 @@ def password_change_test(
8181
6. If pwd_change is True, then 'user' and 'pwdfoo' should not work and should return an error message
8282
"""
8383
cid_file_name = f"test_{username}_{password}_{user_change}"
84+
8485
container_args = [
8586
f"-e MYSQL_USER={username}",
8687
f"-e MYSQL_PASSWORD={password}",
8788
"-e MYSQL_DATABASE=db",
88-
f"-v {test_dir}:/var/lib/mysql/data:Z",
89+
f"-v {pwd_dir}:/var/lib/mysql/data:Z",
8990
]
9091
assert self.pwd_change.create_container(
9192
cid_file_name=cid_file_name,
9293
container_args=container_args,
9394
)
9495
cip, cid = self.pwd_change.get_cip_cid(cid_file_name=cid_file_name)
9596
assert cip, cid
97+
if user_change:
98+
username = "user"
99+
password = "foo"
100+
# Test if the database connection works with the old connection parameters
96101
assert self.pwd_change.test_db_connection(
97-
container_ip=cip, username=username, password=password
102+
container_ip=cip,
103+
username=username,
104+
password=password,
98105
)
99-
if pwd_change:
106+
if user_change:
107+
mariadb_logs = PodmanCLIWrapper.podman_logs(
108+
container_id=cid,
109+
)
110+
assert "User user2 does not exist in database" in mariadb_logs
111+
username = "user"
112+
password = "bar"
100113
output = self.dw_api.run_sql_command(
101114
container_ip=cip,
102115
username=username,
103116
password=password,
104117
container_id=VARS.IMAGE_NAME,
105118
ignore_error=True,
106119
)
120+
assert f"Access denied for user '{username}'@" in output, (
121+
f"The new password {password} should not work, but it does"
122+
)
123+
if pwd_change:
124+
output = self.dw_api.run_sql_command(
125+
container_ip=cip,
126+
username=username,
127+
password="pwdfoo",
128+
container_id=VARS.IMAGE_NAME,
129+
ignore_error=True,
130+
)
107131
assert f"Access denied for user '{username}'@" in output, (
108132
f"The old password {password} should not work, but it does"
109133
)

test/test_container_replication.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import tempfile
21
import re
2+
33
from time import sleep
44

55
from container_ci_suite.container_lib import ContainerTestLib
66
from container_ci_suite.engines.database import DatabaseWrapper
7-
from container_ci_suite.engines.podman_wrapper import PodmanCLIWrapper
87

98
from conftest import VARS
109

0 commit comments

Comments
 (0)