You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[FAB-9446] Peer CLI multi-endorse via string arrays
This CR add supports to the peer CLI for obtaining
multiple endorsements for an "invoke" call. The peers
and the paths to the TLS root cert files for the peers
are supplied via the --peerAddresses and --tlsRootCertFiles
string array pflags.
Change-Id: I087abc34b877b386defec012e70bb8391610d227
Signed-off-by: Will Lahti <wtlahti@us.ibm.com>
fmt.Sprint("If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag"))
// failure - more than one peer and TLS root cert - not invoke
225
+
resetFlags()
226
+
peerAddresses= []string{"peer0", "peer1"}
227
+
tlsRootCertFiles= []string{"cert0", "cert1"}
228
+
err:=validatePeerConnectionParameters("query")
229
+
assert.Error(err)
230
+
assert.Contains(err.Error(), "command can only be executed against one peer")
231
+
232
+
// success - peer provided and no TLS root certs
233
+
// TLS disabled
234
+
resetFlags()
235
+
peerAddresses= []string{"peer0"}
236
+
err=validatePeerConnectionParameters("query")
237
+
assert.NoError(err)
238
+
assert.Nil(tlsRootCertFiles)
239
+
240
+
// success - more TLS root certs than peers
241
+
// TLS disabled
242
+
resetFlags()
243
+
peerAddresses= []string{"peer0"}
244
+
tlsRootCertFiles= []string{"cert0", "cert1"}
245
+
err=validatePeerConnectionParameters("invoke")
246
+
assert.NoError(err)
247
+
assert.Nil(tlsRootCertFiles)
248
+
249
+
// success - multiple peers and no TLS root certs - invoke
250
+
// TLS disabled
251
+
resetFlags()
252
+
peerAddresses= []string{"peer0", "peer1"}
253
+
err=validatePeerConnectionParameters("invoke")
254
+
assert.NoError(err)
255
+
assert.Nil(tlsRootCertFiles)
256
+
257
+
// TLS enabled
258
+
viper.Set("peer.tls.enabled", true)
259
+
260
+
// failure - uneven number of peers and TLS root certs - invoke
261
+
// TLS enabled
262
+
resetFlags()
263
+
peerAddresses= []string{"peer0", "peer1"}
264
+
tlsRootCertFiles= []string{"cert0"}
265
+
err=validatePeerConnectionParameters("invoke")
266
+
assert.Error(err)
267
+
assert.Contains(err.Error(), fmt.Sprintf("number of peer addresses (%d) does not match the number of TLS root cert files (%d)", len(peerAddresses), len(tlsRootCertFiles)))
268
+
269
+
// success - more than one peer and TLS root certs - invoke
270
+
// TLS enabled
271
+
resetFlags()
272
+
peerAddresses= []string{"peer0", "peer1"}
273
+
tlsRootCertFiles= []string{"cert0", "cert1"}
274
+
err=validatePeerConnectionParameters("invoke")
275
+
assert.NoError(err)
276
+
277
+
// cleanup pflags and viper
278
+
resetFlags()
279
+
viper.Reset()
280
+
}
281
+
282
+
funcTestInitCmdFactoryFailures(t*testing.T) {
283
+
assert:=assert.New(t)
284
+
285
+
// failure validating peer connection parameters
286
+
resetFlags()
287
+
peerAddresses= []string{"peer0", "peer1"}
288
+
tlsRootCertFiles= []string{"cert0", "cert1"}
289
+
cf, err:=InitCmdFactory("query", true, false)
290
+
assert.Error(err)
291
+
assert.Contains(err.Error(), "error validating peer connection parameters: 'query' command can only be executed against one peer")
292
+
assert.Nil(cf)
293
+
294
+
// failure - no peers supplied and endorser client is needed
295
+
resetFlags()
296
+
peerAddresses= []string{}
297
+
cf, err=InitCmdFactory("query", true, false)
298
+
assert.Error(err)
299
+
assert.Contains(err.Error(), "no endorser clients retrieved")
300
+
assert.Nil(cf)
301
+
302
+
// failure - orderer client is needed, ordering endpoint is empty and no
303
+
// endorser client supplied
304
+
resetFlags()
305
+
peerAddresses=nil
306
+
cf, err=InitCmdFactory("invoke", false, true)
307
+
assert.Error(err)
308
+
assert.Contains(err.Error(), "no ordering endpoint or endorser client supplied")
0 commit comments