@@ -467,6 +467,51 @@ def verify_avro_https():
467
467
c .close ()
468
468
469
469
470
+ def verify_avro_basic_auth (mode_conf ):
471
+
472
+ if mode_conf is None :
473
+ raise ValueError ("Misisng configuration" )
474
+
475
+ url = {
476
+ 'schema.registry.basic.auth.credentials.source' : 'URL'
477
+ }
478
+
479
+ user_info = {
480
+ 'schema.registry.basic.auth.credentials.source' : 'USER_INFO' ,
481
+ 'schema.registry.basic.auth.user.info' : mode_conf .get ('schema.registry.basic.auth.user.info' )
482
+ }
483
+
484
+ sasl_inherit = {
485
+ 'schema.registry.basic.auth.credentials.source' : 'sasl_inherit' ,
486
+ 'schema.registry.sasl.username' : mode_conf .get ('sasl.username' , None ),
487
+ 'schema.registry.sasl.password' : mode_conf .get ('sasl.password' , None )
488
+ }
489
+
490
+ base_conf = {
491
+ 'bootstrap.servers' : bootstrap_servers ,
492
+ 'error_cb' : error_cb ,
493
+ 'api.version.request' : api_version_request ,
494
+ 'schema.registry.url' : schema_registry_url
495
+ }
496
+
497
+ consumer_conf = {'group.id' : generate_group_id (),
498
+ 'session.timeout.ms' : 6000 ,
499
+ 'enable.auto.commit' : False ,
500
+ 'default.topic.config' : {
501
+ 'auto.offset.reset' : 'earliest'
502
+ }}
503
+ consumer_conf .update (base_conf )
504
+
505
+ print ('-' * 10 , 'Verifying basic auth source USER_INFO' , '-' * 10 )
506
+ run_avro_loop (dict (base_conf , ** user_info ), dict (consumer_conf , ** user_info ))
507
+
508
+ print ('-' * 10 , 'Verifying basic auth source SASL_INHERIT' , '-' * 10 )
509
+ run_avro_loop (dict (base_conf , ** sasl_inherit ), dict (consumer_conf , ** sasl_inherit ))
510
+
511
+ print ('-' * 10 , 'Verifying basic auth source URL' , '-' * 10 )
512
+ run_avro_loop (dict (base_conf , ** url ), dict (consumer_conf , ** url ))
513
+
514
+
470
515
def verify_producer_performance (with_dr_cb = True ):
471
516
""" Time how long it takes to produce and delivery X messages """
472
517
conf = {'bootstrap.servers' : bootstrap_servers ,
@@ -1218,7 +1263,7 @@ def verify_config(expconfig, configs):
1218
1263
1219
1264
# Exclude throttle since from default list
1220
1265
default_modes = ['consumer' , 'producer' , 'avro' , 'performance' , 'admin' ]
1221
- all_modes = default_modes + ['throttle' , 'avro-https' , 'none' ]
1266
+ all_modes = default_modes + ['throttle' , 'avro-https' , 'avro-basic-auth' , ' none' ]
1222
1267
"""All test modes"""
1223
1268
1224
1269
@@ -1233,6 +1278,76 @@ def print_usage(exitcode, reason=None):
1233
1278
sys .exit (exitcode )
1234
1279
1235
1280
1281
+ def run_avro_loop (producer_conf , consumer_conf ):
1282
+ from confluent_kafka import avro
1283
+ avsc_dir = os .path .join (os .path .dirname (__file__ ), os .pardir , 'tests' , 'avro' )
1284
+
1285
+ p = avro .AvroProducer (producer_conf )
1286
+
1287
+ prim_float = avro .load (os .path .join (avsc_dir , "primitive_float.avsc" ))
1288
+ prim_string = avro .load (os .path .join (avsc_dir , "primitive_string.avsc" ))
1289
+ basic = avro .load (os .path .join (avsc_dir , "basic_schema.avsc" ))
1290
+ str_value = 'abc'
1291
+ float_value = 32.0
1292
+
1293
+ combinations = [
1294
+ dict (key = float_value , key_schema = prim_float ),
1295
+ dict (value = float_value , value_schema = prim_float ),
1296
+ dict (key = {'name' : 'abc' }, key_schema = basic ),
1297
+ dict (value = {'name' : 'abc' }, value_schema = basic ),
1298
+ dict (value = {'name' : 'abc' }, value_schema = basic , key = float_value , key_schema = prim_float ),
1299
+ dict (value = {'name' : 'abc' }, value_schema = basic , key = str_value , key_schema = prim_string ),
1300
+ dict (value = float_value , value_schema = prim_float , key = {'name' : 'abc' }, key_schema = basic ),
1301
+ dict (value = float_value , value_schema = prim_float , key = str_value , key_schema = prim_string ),
1302
+ dict (value = str_value , value_schema = prim_string , key = {'name' : 'abc' }, key_schema = basic ),
1303
+ dict (value = str_value , value_schema = prim_string , key = float_value , key_schema = prim_float ),
1304
+ # Verify identity check allows Falsy object values(e.g., 0, empty string) to be handled properly (issue #342)
1305
+ dict (value = '' , value_schema = prim_string , key = 0.0 , key_schema = prim_float ),
1306
+ dict (value = 0.0 , value_schema = prim_float , key = '' , key_schema = prim_string ),
1307
+ ]
1308
+
1309
+ for i , combo in enumerate (combinations ):
1310
+ combo ['topic' ] = str (uuid .uuid4 ())
1311
+ combo ['headers' ] = [('index' , str (i ))]
1312
+ p .produce (** combo )
1313
+ p .flush ()
1314
+
1315
+ c = avro .AvroConsumer (consumer_conf )
1316
+ c .subscribe ([(t ['topic' ]) for t in combinations ])
1317
+
1318
+ msgcount = 0
1319
+ while msgcount < len (combinations ):
1320
+ msg = c .poll (0 )
1321
+
1322
+ if msg is None or msg .error ():
1323
+ continue
1324
+
1325
+ tstype , timestamp = msg .timestamp ()
1326
+ print ('%s[%d]@%d: key=%s, value=%s, tstype=%d, timestamp=%s' %
1327
+ (msg .topic (), msg .partition (), msg .offset (),
1328
+ msg .key (), msg .value (), tstype , timestamp ))
1329
+
1330
+ # omit empty Avro fields from payload for comparison
1331
+ record_key = msg .key ()
1332
+ record_value = msg .value ()
1333
+ index = int (dict (msg .headers ())['index' ])
1334
+
1335
+ if isinstance (msg .key (), dict ):
1336
+ record_key = {k : v for k , v in msg .key ().items () if v is not None }
1337
+
1338
+ if isinstance (msg .value (), dict ):
1339
+ record_value = {k : v for k , v in msg .value ().items () if v is not None }
1340
+
1341
+ assert combinations [index ].get ('key' ) == record_key
1342
+ assert combinations [index ].get ('value' ) == record_value
1343
+
1344
+ c .commit ()
1345
+ msgcount += 1
1346
+
1347
+ # Close consumer
1348
+ c .close ()
1349
+
1350
+
1236
1351
def generate_group_id ():
1237
1352
return str (uuid .uuid1 ())
1238
1353
@@ -1333,6 +1448,10 @@ def resolve_envs(_conf):
1333
1448
print ('=' * 30 , 'Verifying AVRO with HTTPS' , '=' * 30 )
1334
1449
verify_avro_https ()
1335
1450
1451
+ if 'avro-basic-auth' in modes :
1452
+ print ("=" * 30 , 'Verifying AVRO with Basic Auth' , '=' * 30 )
1453
+ verify_avro_basic_auth (testconf .get ('avro-basic-auth' , None ))
1454
+
1336
1455
if 'admin' in modes :
1337
1456
print ('=' * 30 , 'Verifying Admin API' , '=' * 30 )
1338
1457
verify_admin ()
0 commit comments