@@ -13,6 +13,8 @@ import (
13
13
"time"
14
14
15
15
"github.com/golang/protobuf/proto"
16
+ "github.com/hyperledger/fabric/common/config"
17
+ "github.com/hyperledger/fabric/common/configtx"
16
18
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
17
19
"github.com/hyperledger/fabric/common/crypto/tlsgen"
18
20
"github.com/hyperledger/fabric/common/genesis"
@@ -22,6 +24,7 @@ import (
22
24
"github.com/hyperledger/fabric/common/tools/configtxgen/configtxgentest"
23
25
"github.com/hyperledger/fabric/common/tools/configtxgen/encoder"
24
26
genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig"
27
+ "github.com/hyperledger/fabric/core/aclmgmt"
25
28
aclmocks "github.com/hyperledger/fabric/core/aclmgmt/mocks"
26
29
"github.com/hyperledger/fabric/core/aclmgmt/resources"
27
30
"github.com/hyperledger/fabric/core/chaincode"
@@ -37,6 +40,7 @@ import (
37
40
"github.com/hyperledger/fabric/core/peer"
38
41
"github.com/hyperledger/fabric/core/policy"
39
42
policymocks "github.com/hyperledger/fabric/core/policy/mocks"
43
+ "github.com/hyperledger/fabric/core/scc/cscc/mock"
40
44
"github.com/hyperledger/fabric/gossip/api"
41
45
"github.com/hyperledger/fabric/gossip/service"
42
46
"github.com/hyperledger/fabric/msp/mgmt"
@@ -51,6 +55,21 @@ import (
51
55
"github.com/stretchr/testify/assert"
52
56
)
53
57
58
+ //go:generate counterfeiter -o mock/config_manager.go --fake-name ConfigManager . configManager
59
+ type configManager interface {
60
+ config.Manager
61
+ }
62
+
63
+ //go:generate counterfeiter -o mock/acl_provider.go --fake-name ACLProvider . aclProvider
64
+ type aclProvider interface {
65
+ aclmgmt.ACLProvider
66
+ }
67
+
68
+ //go:generate counterfeiter -o mock/configtx_validator.go --fake-name ConfigtxValidator . configtxValidator
69
+ type configtxValidator interface {
70
+ configtx.Validator
71
+ }
72
+
54
73
type mockDeliveryClient struct {
55
74
}
56
75
@@ -329,6 +348,61 @@ func TestConfigerInvokeJoinChainCorrectParams(t *testing.T) {
329
348
}
330
349
}
331
350
351
+ func TestGetConfigTree (t * testing.T ) {
352
+ aclProvider := & mock.ACLProvider {}
353
+ configMgr := & mock.ConfigManager {}
354
+ pc := & PeerConfiger {
355
+ aclProvider : aclProvider ,
356
+ configMgr : configMgr ,
357
+ }
358
+
359
+ args := [][]byte {[]byte ("GetConfigTree" ), []byte ("testchan" )}
360
+
361
+ t .Run ("Success" , func (t * testing.T ) {
362
+ ctxv := & mock.ConfigtxValidator {}
363
+ configMgr .GetChannelConfigReturns (ctxv )
364
+ testConfig := & cb.Config {
365
+ ChannelGroup : & cb.ConfigGroup {
366
+ Values : map [string ]* cb.ConfigValue {
367
+ "foo" : {
368
+ Value : []byte ("bar" ),
369
+ },
370
+ },
371
+ },
372
+ }
373
+ ctxv .ConfigProtoReturns (testConfig )
374
+ res := pc .InvokeNoShim (args , nil )
375
+ assert .Equal (t , int32 (shim .OK ), res .Status )
376
+ checkConfig := & pb.ConfigTree {}
377
+ err := proto .Unmarshal (res .Payload , checkConfig )
378
+ assert .NoError (t , err )
379
+ assert .True (t , proto .Equal (testConfig , checkConfig .ChannelConfig ))
380
+ })
381
+
382
+ t .Run ("MissingConfig" , func (t * testing.T ) {
383
+ ctxv := & mock.ConfigtxValidator {}
384
+ configMgr .GetChannelConfigReturns (ctxv )
385
+ res := pc .InvokeNoShim (args , nil )
386
+ assert .NotEqual (t , int32 (shim .OK ), res .Status )
387
+ assert .Equal (t , "Unknown chain ID, testchan" , res .Message )
388
+ })
389
+
390
+ t .Run ("NilChannel" , func (t * testing.T ) {
391
+ ctxv := & mock.ConfigtxValidator {}
392
+ configMgr .GetChannelConfigReturns (ctxv )
393
+ res := pc .InvokeNoShim ([][]byte {[]byte ("GetConfigTree" ), nil }, nil )
394
+ assert .NotEqual (t , int32 (shim .OK ), res .Status )
395
+ assert .Equal (t , "Chain ID must not be nil" , res .Message )
396
+ })
397
+
398
+ t .Run ("BadACL" , func (t * testing.T ) {
399
+ aclProvider .CheckACLReturns (fmt .Errorf ("fake-error" ))
400
+ res := pc .InvokeNoShim (args , nil )
401
+ assert .NotEqual (t , int32 (shim .OK ), res .Status )
402
+ assert .Equal (t , "\" GetConfigTree\" request failed authorization check for channel [testchan]: [fake-error]" , res .Message )
403
+ })
404
+ }
405
+
332
406
func TestPeerConfiger_SubmittingOrdererGenesis (t * testing.T ) {
333
407
viper .Set ("peer.fileSystemPath" , "/tmp/hyperledgertest/" )
334
408
os .Mkdir ("/tmp/hyperledgertest" , 0755 )
0 commit comments