@@ -4861,6 +4861,137 @@ def test_retrieve_mysql_json_time_types(self):
4861
4861
mysql_type , expected_type )
4862
4862
4863
4863
4864
+ unittest .skipIf (tests .MYSQL_VERSION < (5 , 6 , 7 ),
4865
+ "BugOra16217765 not tested with MySQL version < 5.6.7" )
4866
+ @unittest .skipIf (not CMySQLConnection , ERR_NO_CEXT )
4867
+ class Bug28443941 (tests .MySQLConnectorTests ):
4868
+ """BUG#28443941: DIFFERENCE PURE AND C-EXT ON CMD_CHANGE_USER()
4869
+ """
4870
+
4871
+ users = {
4872
+ 'sha256user' : {
4873
+ 'username' : 'sha256user' ,
4874
+ 'password' : 'sha256P@ss' ,
4875
+ 'auth_plugin' : 'sha256_password' ,
4876
+ },
4877
+ 'nativeuser' : {
4878
+ 'username' : 'nativeuser' ,
4879
+ 'password' : 'nativeP@ss' ,
4880
+ 'auth_plugin' : 'mysql_native_password' ,
4881
+ }
4882
+ }
4883
+
4884
+ def _create_user (self , cnx , user , password , host , database ,
4885
+ plugin ):
4886
+
4887
+ self ._drop_user (user , host )
4888
+ create_user = ("CREATE USER '{user}'@'{host}' "
4889
+ "IDENTIFIED WITH {plugin}" )
4890
+ cnx .cmd_query (create_user .format (user = user , host = host , plugin = plugin ))
4891
+
4892
+ if tests .MYSQL_VERSION [0 :3 ] < (8 , 0 , 5 ):
4893
+ if plugin == 'sha256_password' :
4894
+ cnx .cmd_query ("SET old_passwords = 2" )
4895
+ else :
4896
+ cnx .cmd_query ("SET old_passwords = 0" )
4897
+
4898
+ if tests .MYSQL_VERSION < (5 , 7 , 5 ):
4899
+ passwd = ("SET PASSWORD FOR '{user}'@'{host}' = "
4900
+ "PASSWORD('{password}')" ).format (user = user , host = host ,
4901
+ password = password )
4902
+ else :
4903
+ passwd = ("ALTER USER '{user}'@'{host}' IDENTIFIED BY "
4904
+ "'{password}'" ).format (user = user , host = host ,
4905
+ password = password )
4906
+ cnx .cmd_query (passwd )
4907
+
4908
+ grant = "GRANT ALL ON {database}.* TO '{user}'@'{host}'"
4909
+ cnx .cmd_query (grant .format (database = database , user = user , host = host ))
4910
+
4911
+ def _drop_user (self , user , host ):
4912
+ try :
4913
+ self .admin_cnx .cmd_query ("DROP USER '{user}'@'{host}'" .format (
4914
+ host = host ,
4915
+ user = user ))
4916
+ except errors .DatabaseError :
4917
+ # It's OK when drop fails
4918
+ pass
4919
+
4920
+ def setUp (self ):
4921
+ config = tests .get_mysql_config ()
4922
+ self .admin_cnx = connection .MySQLConnection (** config )
4923
+ for _ , user in self .users .items ():
4924
+ self ._create_user (self .admin_cnx , user ['username' ],
4925
+ user ['password' ],
4926
+ config ['host' ],
4927
+ config ['database' ],
4928
+ plugin = user ['auth_plugin' ])
4929
+
4930
+ def tearDown (self ):
4931
+ config = tests .get_mysql_config ()
4932
+ for _ , user in self .users .items ():
4933
+ self ._drop_user (user ['username' ], config ['host' ])
4934
+
4935
+ def test_cmd_change_user (self ):
4936
+ config = tests .get_mysql_config ()
4937
+ config ['unix_socket' ] = None
4938
+
4939
+ user = self .users ['sha256user' ]
4940
+ config ['user' ] = user ['username' ]
4941
+ config ['password' ] = user ['password' ]
4942
+ config ['client_flags' ] = [constants .ClientFlag .PLUGIN_AUTH ]
4943
+ config ['auth_plugin' ] = user ['auth_plugin' ]
4944
+
4945
+ try :
4946
+ cnx = connection .MySQLConnection (** config )
4947
+ except Exception as exc :
4948
+ import traceback
4949
+ traceback .print_exc ()
4950
+ self .fail (self .errmsg .format (config ['auth_plugin' ], exc ))
4951
+
4952
+ user2 = self .users ['nativeuser' ]
4953
+ config2 = {'user' : user2 ['username' ],
4954
+ 'password' : user2 ['password' ],
4955
+ 'client_flags' : [constants .ClientFlag .PLUGIN_AUTH ],
4956
+ 'auth_plugin' : user2 ['auth_plugin' ]}
4957
+ try :
4958
+ status_p = cnx .cmd_change_user (config2 ['user' ],
4959
+ config2 ['password' ])
4960
+ except :
4961
+ self .fail ("Changing user failed with pure Python connector" )
4962
+
4963
+ try :
4964
+ cnx = CMySQLConnection (** config )
4965
+ except Exception as exc :
4966
+ import traceback
4967
+ traceback .print_exc ()
4968
+ self .fail (self .errmsg .format (config ['auth_plugin' ], exc ))
4969
+
4970
+ try :
4971
+ status_c = cnx .cmd_change_user (config2 ['user' ],
4972
+ config2 ['password' ])
4973
+ except :
4974
+ self .fail ("cmd_change_user did not return any result." )
4975
+
4976
+ if status_c is None :
4977
+ self .fail ("Changing user failed with c-extension" )
4978
+
4979
+ # Server status can be different, therefore we only check that exists.
4980
+ for key in status_p .keys ():
4981
+ try :
4982
+ value = status_c .pop (key )
4983
+ if key is not 'status_flag' :
4984
+ self .assertEqual (status_p [key ], value , "status {} not "
4985
+ "equal: {} differs from {}"
4986
+ "" .format (key , value , status_p [key ]))
4987
+ except KeyError as err :
4988
+ self .fail ("The cmd_change_user from c-ext is missing an"
4989
+ "element: {}" .format (err ))
4990
+ if status_c :
4991
+ self .fail ("The cmd_change_user from c-ext has additional elements:"
4992
+ " {}" .format (status_c ))
4993
+
4994
+
4864
4995
class BugOra27364914 (tests .MySQLConnectorTests ):
4865
4996
"""BUG#27364914: CURSOR PREPARED STATEMENTS DO NOT CONVERT STRINGS
4866
4997
"""
0 commit comments