@@ -105,7 +105,7 @@ func TestStandardDialerDialer(t *testing.T) {
105
105
t .Parallel ()
106
106
emptyCertificate := []byte ("-----BEGIN CERTIFICATE-----\n -----END CERTIFICATE-----" )
107
107
dialer := cluster .NewTLSPinningDialer (comm.ClientConfig {SecOpts : & comm.SecureOptions {UseTLS : true , ServerRootCAs : [][]byte {emptyCertificate }}})
108
- standardDialer := & cluster.StandardDialerDialer {Dialer : dialer }
108
+ standardDialer := & cluster.StandardDialer {Dialer : dialer }
109
109
_ , err := standardDialer .Dial ("127.0.0.1:8080" )
110
110
assert .EqualError (t , err , "error adding root certificate: asn1: syntax error: sequence truncated" )
111
111
}
@@ -332,48 +332,49 @@ func createBlockChain(start, end uint64) []*common.Block {
332
332
return blockchain
333
333
}
334
334
335
- func TestTLSCACertsFromConfigBlockGreenPath (t * testing.T ) {
335
+ func TestEndpointconfigFromConfigBlockGreenPath (t * testing.T ) {
336
336
blockBytes , err := ioutil .ReadFile ("testdata/mychannel.block" )
337
337
assert .NoError (t , err )
338
338
339
339
block := & common.Block {}
340
340
assert .NoError (t , proto .Unmarshal (blockBytes , block ))
341
341
342
- certs , err := cluster .TLSCACertsFromConfigBlock (block )
342
+ endpointConfig , err := cluster .EndpointconfigFromConfigBlock (block )
343
343
assert .NoError (t , err )
344
- assert .Len (t , certs , 1 )
344
+ assert .Len (t , endpointConfig .TLSRootCAs , 1 )
345
+ assert .Equal (t , []string {"orderer.example.com:7050" }, endpointConfig .Endpoints )
345
346
346
- bl , _ := pem .Decode (certs [0 ])
347
+ bl , _ := pem .Decode (endpointConfig . TLSRootCAs [0 ])
347
348
cert , err := x509 .ParseCertificate (bl .Bytes )
348
349
assert .NoError (t , err )
349
350
350
351
assert .True (t , cert .IsCA )
351
352
assert .Equal (t , "tlsca.example.com" , cert .Subject .CommonName )
352
353
}
353
354
354
- func TestTLSCACertsFromConfigBlockFailures (t * testing.T ) {
355
+ func TestEndpointconfigFromConfigBlockFailures (t * testing.T ) {
355
356
t .Run ("nil block" , func (t * testing.T ) {
356
- certs , err := cluster .TLSCACertsFromConfigBlock (nil )
357
+ certs , err := cluster .EndpointconfigFromConfigBlock (nil )
357
358
assert .Nil (t , certs )
358
359
assert .EqualError (t , err , "nil block" )
359
360
})
360
361
361
362
t .Run ("nil block data" , func (t * testing.T ) {
362
- certs , err := cluster .TLSCACertsFromConfigBlock (& common.Block {})
363
+ certs , err := cluster .EndpointconfigFromConfigBlock (& common.Block {})
363
364
assert .Nil (t , certs )
364
365
assert .EqualError (t , err , "block data is nil" )
365
366
})
366
367
367
368
t .Run ("no envelope" , func (t * testing.T ) {
368
- certs , err := cluster .TLSCACertsFromConfigBlock (& common.Block {
369
+ certs , err := cluster .EndpointconfigFromConfigBlock (& common.Block {
369
370
Data : & common.BlockData {},
370
371
})
371
372
assert .Nil (t , certs )
372
373
assert .EqualError (t , err , "envelope index out of bounds" )
373
374
})
374
375
375
376
t .Run ("bad envelope" , func (t * testing.T ) {
376
- certs , err := cluster .TLSCACertsFromConfigBlock (& common.Block {
377
+ certs , err := cluster .EndpointconfigFromConfigBlock (& common.Block {
377
378
Data : & common.BlockData {
378
379
Data : [][]byte {{}},
379
380
},
@@ -382,3 +383,39 @@ func TestTLSCACertsFromConfigBlockFailures(t *testing.T) {
382
383
assert .EqualError (t , err , "failed extracting bundle from envelope: envelope header cannot be nil" )
383
384
})
384
385
}
386
+
387
+ func TestClientConfig (t * testing.T ) {
388
+ t .Run ("Uninitialized dialer" , func (t * testing.T ) {
389
+ dialer := & cluster.PredicateDialer {}
390
+ _ , err := dialer .ClientConfig ()
391
+ assert .EqualError (t , err , "client config not initialized" )
392
+ })
393
+
394
+ t .Run ("Wrong type stored" , func (t * testing.T ) {
395
+ dialer := & cluster.PredicateDialer {}
396
+ dialer .Config .Store ("foo" )
397
+ _ , err := dialer .ClientConfig ()
398
+ assert .EqualError (t , err , "value stored is string, not comm.ClientConfig" )
399
+ })
400
+
401
+ t .Run ("Nil secure options" , func (t * testing.T ) {
402
+ dialer := & cluster.PredicateDialer {}
403
+ dialer .Config .Store (comm.ClientConfig {
404
+ SecOpts : nil ,
405
+ })
406
+ _ , err := dialer .ClientConfig ()
407
+ assert .EqualError (t , err , "SecOpts is nil" )
408
+ })
409
+
410
+ t .Run ("Valid config" , func (t * testing.T ) {
411
+ dialer := & cluster.PredicateDialer {}
412
+ dialer .Config .Store (comm.ClientConfig {
413
+ SecOpts : & comm.SecureOptions {
414
+ Key : []byte {1 , 2 , 3 },
415
+ },
416
+ })
417
+ cc , err := dialer .ClientConfig ()
418
+ assert .NoError (t , err )
419
+ assert .Equal (t , []byte {1 , 2 , 3 }, cc .SecOpts .Key )
420
+ })
421
+ }
0 commit comments