@@ -2211,23 +2211,25 @@ class BugOra16217765(tests.MySQLConnectorTests):
2211
2211
"""
2212
2212
2213
2213
users = {
2214
- 'sha256_password ' : {
2214
+ 'sha256user ' : {
2215
2215
'username' : 'sha256user' ,
2216
2216
'password' : 'sha256P@ss' ,
2217
+ 'auth_plugin' : 'sha256_password' ,
2217
2218
},
2218
- 'mysql_native_password ' : {
2219
+ 'nativeuser ' : {
2219
2220
'username' : 'nativeuser' ,
2220
2221
'password' : 'nativeP@ss' ,
2222
+ 'auth_plugin' : 'mysql_native_password' ,
2221
2223
},
2222
- }
2223
- users_nopass = {
2224
- 'sha256_password' : {
2224
+ 'sha256user_np' : {
2225
2225
'username' : 'sha256user_np' ,
2226
2226
'password' : '' ,
2227
+ 'auth_plugin' : 'sha256_password' ,
2227
2228
},
2228
- 'mysql_native_password ' : {
2229
+ 'nativeuser_np ' : {
2229
2230
'username' : 'nativeuser_np' ,
2230
2231
'password' : '' ,
2232
+ 'auth_plugin' : 'mysql_native_password' ,
2231
2233
},
2232
2234
}
2233
2235
@@ -2271,9 +2273,16 @@ def setUp(self):
2271
2273
self .host = config ['host' ]
2272
2274
self .admin_cnx = connection .MySQLConnection (** config )
2273
2275
2276
+ for key , user in self .users .items ():
2277
+ self ._create_user (self .admin_cnx , user ['username' ],
2278
+ user ['password' ],
2279
+ self .host ,
2280
+ config ['database' ],
2281
+ plugin = user ['auth_plugin' ])
2282
+
2274
2283
def tearDown (self ):
2275
- for plugin_name , info in self .users .items ():
2276
- self ._drop_user (self .admin_cnx , info ['username' ], self .host )
2284
+ for key , user in self .users .items ():
2285
+ self ._drop_user (self .admin_cnx , user ['username' ], self .host )
2277
2286
2278
2287
@unittest .skipIf (tests .MYSQL_VERSION < (5 , 6 , 6 ),
2279
2288
"MySQL {0} does not support sha256_password auth" .format (
@@ -2290,50 +2299,53 @@ def test_sha256(self):
2290
2299
'ssl_key' : tests .SSL_KEY ,
2291
2300
})
2292
2301
2293
- auth_plugin = 'sha256_password'
2294
- for user in (self .users [auth_plugin ], self .users_nopass [auth_plugin ]):
2295
- self ._create_user (self .admin_cnx , user ['username' ],
2296
- user ['password' ],
2297
- self .host ,
2298
- config ['database' ],
2299
- plugin = auth_plugin )
2302
+ user = self .users ['sha256user' ]
2303
+ config ['user' ] = user ['username' ]
2304
+ config ['password' ] = user ['password' ]
2305
+ config ['client_flags' ] = [constants .ClientFlag .PLUGIN_AUTH ]
2306
+ config ['auth_plugin' ] = user ['auth_plugin' ]
2307
+
2308
+ try :
2309
+ cnx = connection .MySQLConnection (** config )
2310
+ except Exception as exc :
2311
+ import traceback
2312
+ traceback .print_exc ()
2313
+ self .fail (self .errmsg .format (config ['auth_plugin' ], exc ))
2300
2314
2301
- config ['user' ] = user ['username' ]
2302
- config ['password' ] = user ['password' ]
2303
- config ['client_flags' ] = [constants .ClientFlag .PLUGIN_AUTH ]
2315
+ try :
2316
+ cnx .cmd_change_user (config ['user' ], config ['password' ])
2317
+ except :
2318
+ self .fail ("Changing user using sha256_password auth failed "
2319
+ "with pure Python connector" )
2304
2320
2321
+ if CMySQLConnection :
2305
2322
try :
2306
- cnx = connection . MySQLConnection (** config )
2307
- except :
2323
+ cnx = CMySQLConnection (** config )
2324
+ except Exception as exc :
2308
2325
import traceback
2309
2326
traceback .print_exc ()
2310
- self .fail ("Connecting using sha256_password auth failed" )
2311
-
2327
+ self .fail (self .errmsg .format (config ['auth_plugin' ], exc ))
2312
2328
try :
2313
2329
cnx .cmd_change_user (config ['user' ], config ['password' ])
2314
2330
except :
2315
- self .fail ("Changing user using sha256_password auth failed" )
2331
+ self .fail ("Changing user using sha256_password auth failed "
2332
+ "with CExtension" )
2316
2333
2317
2334
@unittest .skipIf (tests .MYSQL_VERSION < (5 , 6 , 6 ),
2318
2335
"MySQL {0} does not support sha256_password auth" .format (
2319
2336
tests .MYSQL_VERSION_TXT ))
2320
2337
def test_sha256_nonssl (self ):
2321
2338
config = tests .get_mysql_config ()
2322
2339
config ['unix_socket' ] = None
2340
+ config ['client_flags' ] = [constants .ClientFlag .PLUGIN_AUTH ]
2323
2341
2324
- auth_plugin = 'sha256_password'
2325
- for user in (self .users [auth_plugin ], self .users_nopass [auth_plugin ]):
2326
- self ._create_user (self .admin_cnx , user ['username' ],
2327
- user ['password' ],
2328
- self .host ,
2329
- config ['database' ],
2330
- plugin = auth_plugin )
2331
-
2332
- config ['user' ] = user ['username' ]
2333
- config ['password' ] = user ['password' ]
2334
- config ['client_flags' ] = [constants .ClientFlag .PLUGIN_AUTH ]
2335
- self .assertRaises (errors .InterfaceError , connection .MySQLConnection ,
2336
- ** config )
2342
+ user = self .users ['sha256user' ]
2343
+ config ['user' ] = user ['username' ]
2344
+ config ['password' ] = user ['password' ]
2345
+ self .assertRaises (errors .InterfaceError , connection .MySQLConnection ,
2346
+ ** config )
2347
+ if CMySQLConnection :
2348
+ self .assertRaises (errors .InterfaceError , CMySQLConnection , ** config )
2337
2349
2338
2350
@unittest .skipIf (tests .MYSQL_VERSION < (5 , 5 , 7 ),
2339
2351
"MySQL {0} does not support authentication plugins" .format (
@@ -2342,22 +2354,21 @@ def test_native(self):
2342
2354
config = tests .get_mysql_config ()
2343
2355
config ['unix_socket' ] = None
2344
2356
2345
- auth_plugin = 'mysql_native_password'
2346
- for user in (self .users [auth_plugin ], self .users_nopass [auth_plugin ]):
2347
- self ._create_user (self .admin_cnx , user ['username' ],
2348
- user ['password' ],
2349
- self .host ,
2350
- config ['database' ],
2351
- plugin = auth_plugin )
2357
+ user = self .users ['nativeuser' ]
2358
+ config ['user' ] = user ['username' ]
2359
+ config ['password' ] = user ['password' ]
2360
+ config ['client_flags' ] = [constants .ClientFlag .PLUGIN_AUTH ]
2361
+ config ['auth_plugin' ] = user ['auth_plugin' ]
2362
+ try :
2363
+ cnx = connection .MySQLConnection (** config )
2364
+ except Exception as exc :
2365
+ self .fail (self .errmsg .format (config ['auth_plugin' ], exc ))
2352
2366
2353
- config ['user' ] = user ['username' ]
2354
- config ['password' ] = user ['password' ]
2355
- config ['client_flags' ] = [constants .ClientFlag .PLUGIN_AUTH ]
2367
+ if CMySQLConnection :
2356
2368
try :
2357
- cnx = connection . MySQLConnection (** config )
2369
+ cnx = CMySQLConnection (** config )
2358
2370
except Exception as exc :
2359
- self .fail ("Connecting using {0} auth failed: {1}" .format (
2360
- auth_plugin , exc ))
2371
+ self .fail (self .errmsg .format (config ['auth_plugin' ], exc ))
2361
2372
2362
2373
2363
2374
class BugOra18144971 (tests .MySQLConnectorTests ):
0 commit comments