@@ -13,16 +13,15 @@ class TestMySqlPasswordContainer:
1313 """
1414
1515 def setup_method (self ):
16- self .ssl_db = ContainerTestLib (image_name = VARS .IMAGE_NAME )
17- self .ssl_db .set_new_db_type (db_type = "mysql" )
18- self .db_connector = DatabaseWrapper (image_name = VARS .IMAGE_NAME , db_type = "mysql" )
16+ self .pwd_change = ContainerTestLib (image_name = VARS .IMAGE_NAME )
17+ self .pwd_change .set_new_db_type (db_type = "mysql" )
1918
2019 def teardown_method (self ):
21- self .ssl_db .cleanup ()
20+ self .pwd_change .cleanup ()
2221
2322 def test_password_change (self ):
2423 """ """
25- cid_file_name = "test_password_change"
24+ cid_file_name1 = "test_password_change"
2625 pwd_dir = tempfile .mkdtemp (prefix = "/tmp/mysql-pwd" )
2726 username = "user"
2827 password = "foo"
@@ -31,41 +30,50 @@ def test_password_change(self):
3130 f"chmod -R a+rwx { pwd_dir } " ,
3231 ]
3332 )
34- assert self .ssl_db .create_container (
35- cid_file_name = cid_file_name ,
33+ assert self .pwd_change .create_container (
34+ cid_file_name = cid_file_name1 ,
3635 container_args = [
3736 f"-e MYSQL_USER={ username } " ,
3837 f"-e MYSQL_PASSWORD={ password } " ,
3938 "-e MYSQL_DATABASE=db" ,
4039 f"-v { pwd_dir } :/var/lib/mysql/data:Z" ,
4140 ],
4241 )
43- cip = self .ssl_db .get_cip (cid_file_name = cid_file_name )
44- assert cip
45- assert self .ssl_db .test_db_connection (
46- container_ip = cip , username = username , password = password
42+ cip1 = self .pwd_change .get_cip (cid_file_name = cid_file_name1 )
43+ assert cip1
44+ assert self .pwd_change .test_db_connection (
45+ container_ip = cip1 , username = username , password = password
4746 )
48- cid = self .ssl_db .get_cid (cid_file_name = cid_file_name )
49- assert cid
50- PodmanCLIWrapper .call_podman_command (cmd = f"stop { cid } " )
51- cid_file_name = "test_password_change_2"
47+ cid1 = self .pwd_change .get_cid (cid_file_name = cid_file_name1 )
48+ assert cid1
49+ PodmanCLIWrapper .call_podman_command (cmd = f"stop { cid1 } " )
50+ cid_file_name2 = "test_password_change_2"
5251 new_password = "bar"
53- assert self .ssl_db .create_container (
54- cid_file_name = cid_file_name ,
52+ assert self .pwd_change .create_container (
53+ cid_file_name = cid_file_name2 ,
5554 container_args = [
5655 f"-e MYSQL_USER={ username } " ,
5756 f"-e MYSQL_PASSWORD={ new_password } " ,
5857 "-e MYSQL_DATABASE=db" ,
5958 f"-v { pwd_dir } :/var/lib/mysql/data:Z" ,
6059 ],
6160 )
61+ cip2 = self .pwd_change .get_cip (cid_file_name = cid_file_name2 )
62+ assert cip2
63+ assert self .pwd_change .test_db_connection (
64+ container_ip = cip2 , username = username , password = new_password
65+ )
6266 podman_cmd = (
63- f"--rm { VARS .IMAGE_NAME } mysql --host { cip } -u{ username } -p{ password } "
67+ f"--rm { VARS .IMAGE_NAME } mysql --host { cip2 } -u{ username } -p{ password } "
6468 )
6569 output = PodmanCLIWrapper .podman_run_command (
6670 cmd = f"{ podman_cmd } -e 'SELECT 1;' db" ,
71+ ignore_error = True ,
72+ )
73+ print (output )
74+ assert f"Access denied for user '{ username } '@" in output , (
75+ f"The old password { password } should not work, but it does"
6776 )
68- assert output == "1"
6977
7078 def test_password_change_new_user_test (self ):
7179 """ """
@@ -78,7 +86,7 @@ def test_password_change_new_user_test(self):
7886 f"chmod -R a+rwx { pwd_dir } " ,
7987 ]
8088 )
81- assert self .ssl_db .create_container (
89+ assert self .pwd_change .create_container (
8290 cid_file_name = cid_file_name ,
8391 container_args = [
8492 f"-e MYSQL_USER={ username1 } " ,
@@ -87,19 +95,19 @@ def test_password_change_new_user_test(self):
8795 f"-v { pwd_dir } :/var/lib/mysql/data:Z" ,
8896 ],
8997 )
90- cip = self .ssl_db .get_cip (cid_file_name = cid_file_name )
91- assert cip
92- assert self .ssl_db .test_db_connection (
93- container_ip = cip , username = username1 , password = password1
98+ cip1 = self .pwd_change .get_cip (cid_file_name = cid_file_name )
99+ assert cip1
100+ assert self .pwd_change .test_db_connection (
101+ container_ip = cip1 , username = username1 , password = password1
94102 )
95- cid = self .ssl_db .get_cid (cid_file_name = cid_file_name )
103+ cid = self .pwd_change .get_cid (cid_file_name = cid_file_name )
96104 assert cid
97105 PodmanCLIWrapper .call_podman_command (cmd = f"stop { cid } " )
98106 cid_file_name = "test_password_change2"
99107 username2 = "user2"
100108 password2 = "bar"
101109 # Create second container with changed password
102- assert self .ssl_db .create_container (
110+ assert self .pwd_change .create_container (
103111 cid_file_name = cid_file_name ,
104112 container_args = [
105113 f"-e MYSQL_USER={ username2 } " ,
@@ -108,20 +116,23 @@ def test_password_change_new_user_test(self):
108116 f"-v { pwd_dir } :/var/lib/mysql/data:Z" ,
109117 ],
110118 )
111- cip2 = self .ssl_db .get_cip (cid_file_name = cid_file_name )
119+ cip2 = self .pwd_change .get_cip (cid_file_name = cid_file_name )
112120 assert cip2
113- assert self .ssl_db .test_db_connection (
121+ assert self .pwd_change .test_db_connection (
114122 container_ip = cip2 , username = username1 , password = password1
115123 )
116- cid2 = self .ssl_db .get_cid (cid_file_name = cid_file_name )
124+ cid2 = self .pwd_change .get_cid (cid_file_name = cid_file_name )
117125 mysql_logs = PodmanCLIWrapper .podman_logs (
118- conatiner_id = cid2 ,
126+ container_id = cid2 ,
119127 )
120128 assert "User user2 does not exist in database" in mysql_logs
121129 podman_cmd = (
122130 f"--rm { VARS .IMAGE_NAME } mysql --host { cip2 } -u{ username1 } -p{ password2 } "
123131 )
124132 output = PodmanCLIWrapper .podman_run_command (
125133 cmd = f"{ podman_cmd } -e 'SELECT 1;' db" ,
134+ ignore_error = True ,
135+ )
136+ assert f"Access denied for user '{ username1 } '@" in output , (
137+ f"The new password { password2 } should not work, but it does"
126138 )
127- assert output == "1"
0 commit comments