Skip to content

Commit 10f1177

Browse files
author
Jason Yellick
committed
FAB-10442 Missing SimulateConfigTreeUpdate tests
As part of the ACL unit test audit, it was discovered that there are no unit tests for CSCC SimulateConfigTreeUpdate. This CR remedies the situation and additionally adds a unit test for the ACL. Change-Id: Ic77c364a6b5fc26d295029e6b6b345db933e2bf3 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 12c609c commit 10f1177

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

core/scc/cscc/configure_test.go

+82
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,88 @@ func TestGetConfigTree(t *testing.T) {
403403
})
404404
}
405405

406+
func TestSimulateConfigTreeUpdate(t *testing.T) {
407+
aclProvider := &mock.ACLProvider{}
408+
configMgr := &mock.ConfigManager{}
409+
pc := &PeerConfiger{
410+
aclProvider: aclProvider,
411+
configMgr: configMgr,
412+
}
413+
414+
testUpdate := &cb.Envelope{
415+
Payload: utils.MarshalOrPanic(&cb.Payload{
416+
Header: &cb.Header{
417+
ChannelHeader: utils.MarshalOrPanic(&cb.ChannelHeader{
418+
Type: int32(cb.HeaderType_CONFIG_UPDATE),
419+
}),
420+
},
421+
}),
422+
}
423+
424+
args := [][]byte{[]byte("SimulateConfigTreeUpdate"), []byte("testchan"), utils.MarshalOrPanic(testUpdate)}
425+
426+
t.Run("Success", func(t *testing.T) {
427+
ctxv := &mock.ConfigtxValidator{}
428+
configMgr.GetChannelConfigReturns(ctxv)
429+
res := pc.InvokeNoShim(args, nil)
430+
assert.Equal(t, int32(shim.OK), res.Status, res.Message)
431+
})
432+
433+
t.Run("BadUpdate", func(t *testing.T) {
434+
ctxv := &mock.ConfigtxValidator{}
435+
configMgr.GetChannelConfigReturns(ctxv)
436+
ctxv.ProposeConfigUpdateReturns(nil, fmt.Errorf("fake-error"))
437+
res := pc.InvokeNoShim(args, nil)
438+
assert.NotEqual(t, int32(shim.OK), res.Status)
439+
assert.Equal(t, "fake-error", res.Message)
440+
})
441+
442+
t.Run("BadType", func(t *testing.T) {
443+
res := pc.InvokeNoShim([][]byte{
444+
args[0],
445+
args[1],
446+
utils.MarshalOrPanic(&cb.Envelope{
447+
Payload: utils.MarshalOrPanic(&cb.Payload{
448+
Header: &cb.Header{
449+
ChannelHeader: utils.MarshalOrPanic(&cb.ChannelHeader{
450+
Type: int32(cb.HeaderType_ENDORSER_TRANSACTION),
451+
}),
452+
},
453+
}),
454+
}),
455+
}, nil)
456+
assert.NotEqual(t, int32(shim.OK), res.Status)
457+
assert.Equal(t, "invalid payload header type: 3", res.Message)
458+
})
459+
460+
t.Run("BadEnvelope", func(t *testing.T) {
461+
res := pc.InvokeNoShim([][]byte{
462+
args[0],
463+
args[1],
464+
[]byte("garbage"),
465+
}, nil)
466+
assert.NotEqual(t, int32(shim.OK), res.Status)
467+
assert.Contains(t, res.Message, "proto:")
468+
})
469+
470+
t.Run("NilChainID", func(t *testing.T) {
471+
res := pc.InvokeNoShim([][]byte{
472+
args[0],
473+
nil,
474+
args[2],
475+
}, nil)
476+
assert.NotEqual(t, int32(shim.OK), res.Status)
477+
assert.Equal(t, "Chain ID must not be nil", res.Message)
478+
})
479+
480+
t.Run("BadACL", func(t *testing.T) {
481+
aclProvider.CheckACLReturns(fmt.Errorf("fake-error"))
482+
res := pc.InvokeNoShim(args, nil)
483+
assert.NotEqual(t, int32(shim.OK), res.Status)
484+
assert.Equal(t, "\"SimulateConfigTreeUpdate\" request failed authorization check for channel [testchan]: [fake-error]", res.Message)
485+
})
486+
}
487+
406488
func TestPeerConfiger_SubmittingOrdererGenesis(t *testing.T) {
407489
viper.Set("peer.fileSystemPath", "/tmp/hyperledgertest/")
408490
os.Mkdir("/tmp/hyperledgertest", 0755)

0 commit comments

Comments
 (0)