Skip to content

Commit ddd24b9

Browse files
committed
[FAB-15066] Add additional IT
* Test for ignoring collection config endorsement policy if using legacy chaincode * Test for endorsement failure if semantically wrong but well formed collection config signature policy is used Change-Id: Ic7c64cfa287bd7f58aaf5ce8e7f9b3df683369f6 Signed-off-by: Danny Cao <dcao@us.ibm.com>
1 parent b852a86 commit ddd24b9

File tree

2 files changed

+129
-52
lines changed

2 files changed

+129
-52
lines changed

integration/pvtdata/pvtdata_test.go

Lines changed: 105 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -523,84 +523,137 @@ var _ bool = Describe("PrivateData", func() {
523523
})
524524

525525
Describe("Collection Config Endorsement Policy", func() {
526-
BeforeEach(func() {
527-
testChaincode = chaincode{
528-
Chaincode: newLifecycleChaincode,
529-
isLegacy: false,
530-
}
531-
nwo.EnableCapabilities(network, "testchannel", "Application", "V2_0", orderer, network.Peers...)
532-
})
533-
534-
When("a peer specified in the chaincode endorsement policy but not in the collection config endorsement policy is used to invoke the chaincode", func() {
535-
It("fails validation", func() {
526+
When("using legacy lifecycle chaincode", func() {
527+
It("ignores the collection config endorsement policy and successfully invokes the chaincode", func() {
528+
testChaincode = chaincode{
529+
Chaincode: legacyChaincode,
530+
isLegacy: true,
531+
}
536532
By("setting the collection config endorsement policy to org2 or org3 peers")
537533
testChaincode.CollectionsConfig = collectionConfig("collections_config4.json")
538534

539-
By("deploying new lifecycle chaincode")
540-
// set collection endorsement policy to org2 or org3
535+
By("deploying legacy chaincode")
541536
deployChaincode(network, orderer, testChaincode)
542537

543-
By("adding marble1 with an org1 peer as endorser")
538+
By("adding marble1 with an org 1 peer as endorser")
544539
peer := network.Peer("Org1", "peer0")
545540
marbleDetails := `{"name":"marble1", "color":"blue", "size":35, "owner":"tom", "price":99}`
546-
marbleDetailsBase64 := base64.StdEncoding.EncodeToString([]byte(marbleDetails))
547-
548-
command := commands.ChaincodeInvoke{
549-
ChannelID: channelID,
550-
Orderer: network.OrdererAddress(orderer, nwo.ListenPort),
551-
Name: testChaincode.Name,
552-
Ctor: fmt.Sprintf(`{"Args":["initMarble"]}`),
553-
Transient: fmt.Sprintf(`{"marble":"%s"}`, marbleDetailsBase64),
554-
PeerAddresses: []string{
555-
network.PeerAddress(peer, nwo.ListenPort),
556-
},
557-
WaitForEvent: true,
558-
}
559-
560-
sess, err := network.PeerUserSession(peer, "User1", command)
561-
Expect(err).NotTo(HaveOccurred())
562-
Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit())
563-
Expect(sess.Err).To(gbytes.Say("ENDORSEMENT_POLICY_FAILURE"))
541+
addMarble(network, orderer, testChaincode.Name, marbleDetails, peer)
564542
})
565543
})
566544

567-
When("a peer specified in the collection endorsement policy but not in the chaincode endorsement policy is used to invoke the chaincode", func() {
568-
When("the collection endorsement policy is a signature policy", func() {
569-
It("successfully invokes the chaincode", func() {
570-
// collection config endorsement policy specifies org2 or org3 peers for endorsement
571-
By("setting the collection config endorsement policy to use a signature policy")
572-
testChaincode.CollectionsConfig = collectionConfig("collections_config4.json")
545+
When("using new lifecycle chaincode", func() {
546+
BeforeEach(func() {
547+
testChaincode = chaincode{
548+
Chaincode: newLifecycleChaincode,
549+
isLegacy: false,
550+
}
551+
nwo.EnableCapabilities(network, "testchannel", "Application", "V2_0", orderer, network.Peers...)
552+
})
573553

574-
By("setting the chaincode endorsement policy to org1 or org2 peers")
575-
testChaincode.SignaturePolicy = `OR ('Org1MSP.member','Org2MSP.member')`
554+
When("a peer specified in the chaincode endorsement policy but not in the collection config endorsement policy is used to invoke the chaincode", func() {
555+
It("fails validation", func() {
556+
By("setting the collection config endorsement policy to org2 or org3 peers")
557+
testChaincode.CollectionsConfig = collectionConfig("collections_config4.json")
576558

577559
By("deploying new lifecycle chaincode")
578560
// set collection endorsement policy to org2 or org3
579561
deployChaincode(network, orderer, testChaincode)
580562

581-
By("adding marble1 with an org3 peer as endorser")
582-
peer := network.Peer("Org3", "peer0")
563+
By("adding marble1 with an org1 peer as endorser")
564+
peer := network.Peer("Org1", "peer0")
583565
marbleDetails := `{"name":"marble1", "color":"blue", "size":35, "owner":"tom", "price":99}`
584-
addMarble(network, orderer, testChaincode.Name, marbleDetails, peer)
566+
marbleDetailsBase64 := base64.StdEncoding.EncodeToString([]byte(marbleDetails))
567+
568+
command := commands.ChaincodeInvoke{
569+
ChannelID: channelID,
570+
Orderer: network.OrdererAddress(orderer, nwo.ListenPort),
571+
Name: testChaincode.Name,
572+
Ctor: fmt.Sprintf(`{"Args":["initMarble"]}`),
573+
Transient: fmt.Sprintf(`{"marble":"%s"}`, marbleDetailsBase64),
574+
PeerAddresses: []string{
575+
network.PeerAddress(peer, nwo.ListenPort),
576+
},
577+
WaitForEvent: true,
578+
}
579+
580+
sess, err := network.PeerUserSession(peer, "User1", command)
581+
Expect(err).NotTo(HaveOccurred())
582+
Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit())
583+
Expect(sess.Err).To(gbytes.Say("ENDORSEMENT_POLICY_FAILURE"))
585584
})
586585
})
587586

588-
When("the collection endorsement policy is a channel config policy reference", func() {
589-
It("successfully invokes the chaincode", func() {
590-
// collection config endorsement policy specifies channel config policy reference /Channel/Application/Readers
591-
By("setting the collection config endorsement policy to use a channel config policy reference")
592-
testChaincode.CollectionsConfig = collectionConfig("collections_config5.json")
587+
When("a peer specified in the collection endorsement policy but not in the chaincode endorsement policy is used to invoke the chaincode", func() {
588+
When("the collection endorsement policy is a signature policy", func() {
589+
It("successfully invokes the chaincode", func() {
590+
// collection config endorsement policy specifies org2 or org3 peers for endorsement
591+
By("setting the collection config endorsement policy to use a signature policy")
592+
testChaincode.CollectionsConfig = collectionConfig("collections_config4.json")
593+
594+
By("setting the chaincode endorsement policy to org1 or org2 peers")
595+
testChaincode.SignaturePolicy = `OR ('Org1MSP.member','Org2MSP.member')`
596+
597+
By("deploying new lifecycle chaincode")
598+
// set collection endorsement policy to org2 or org3
599+
deployChaincode(network, orderer, testChaincode)
600+
601+
By("adding marble1 with an org3 peer as endorser")
602+
peer := network.Peer("Org3", "peer0")
603+
marbleDetails := `{"name":"marble1", "color":"blue", "size":35, "owner":"tom", "price":99}`
604+
addMarble(network, orderer, testChaincode.Name, marbleDetails, peer)
605+
})
606+
})
607+
608+
When("the collection endorsement policy is a channel config policy reference", func() {
609+
It("successfully invokes the chaincode", func() {
610+
// collection config endorsement policy specifies channel config policy reference /Channel/Application/Readers
611+
By("setting the collection config endorsement policy to use a channel config policy reference")
612+
testChaincode.CollectionsConfig = collectionConfig("collections_config5.json")
613+
614+
By("setting the channel endorsement policy to org1 or org2 peers")
615+
testChaincode.SignaturePolicy = `OR ('Org1MSP.member','Org2MSP.member')`
616+
617+
By("deploying new lifecycle chaincode")
618+
deployChaincode(network, orderer, testChaincode)
619+
620+
By("adding marble1 with an org3 peer as endorser")
621+
peer := network.Peer("Org3", "peer0")
622+
marbleDetails := `{"name":"marble1", "color":"blue", "size":35, "owner":"tom", "price":99}`
623+
addMarble(network, orderer, testChaincode.Name, marbleDetails, peer)
624+
})
625+
})
626+
})
593627

594-
By("setting the channel endorsement policy to org1 or org2 peers")
595-
testChaincode.SignaturePolicy = `OR ('Org1MSP.member','Org2MSP.member')`
628+
When("the collection config endorsement policy specifies a semantically wrong, but well formed signature policy", func() {
629+
It("fails to invoke the chaincode with an endorsement policy failure", func() {
630+
By("setting the collection config endorsement policy to non existent org4 peers")
631+
testChaincode.CollectionsConfig = collectionConfig("collections_config6.json")
596632

597633
By("deploying new lifecycle chaincode")
598634
deployChaincode(network, orderer, testChaincode)
599635

600-
By("adding marble1 with an org3 peer as endorser")
601-
peer := network.Peer("Org3", "peer0")
636+
By("adding marble1 with an org1 peer as endorser")
637+
peer := network.Peer("Org1", "peer0")
602638
marbleDetails := `{"name":"marble1", "color":"blue", "size":35, "owner":"tom", "price":99}`
603-
addMarble(network, orderer, testChaincode.Name, marbleDetails, peer)
639+
marbleDetailsBase64 := base64.StdEncoding.EncodeToString([]byte(marbleDetails))
640+
641+
command := commands.ChaincodeInvoke{
642+
ChannelID: channelID,
643+
Orderer: network.OrdererAddress(orderer, nwo.ListenPort),
644+
Name: testChaincode.Name,
645+
Ctor: fmt.Sprintf(`{"Args":["initMarble"]}`),
646+
Transient: fmt.Sprintf(`{"marble":"%s"}`, marbleDetailsBase64),
647+
PeerAddresses: []string{
648+
network.PeerAddress(peer, nwo.ListenPort),
649+
},
650+
WaitForEvent: true,
651+
}
652+
653+
sess, err := network.PeerUserSession(peer, "User1", command)
654+
Expect(err).NotTo(HaveOccurred())
655+
Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit())
656+
Expect(sess.Err).To(gbytes.Say("ENDORSEMENT_POLICY_FAILURE"))
604657
})
605658
})
606659
})
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[
2+
{
3+
"name": "collectionMarbles",
4+
"policy": "OR('Org1MSP.member', 'Org2MSP.member', 'Org3MSP.member')",
5+
"requiredPeerCount": 1,
6+
"maxPeerCount": 2,
7+
"blockToLive":1000000,
8+
"memberOnlyRead": false,
9+
"endorsementPolicy": {
10+
"signaturePolicy": "OR('Org4MSP.member')"
11+
}
12+
},
13+
{
14+
"name": "collectionMarblePrivateDetails",
15+
"policy": "OR('Org1MSP.member', 'Org2MSP.member', 'Org3MSP.member')",
16+
"requiredPeerCount": 1,
17+
"maxPeerCount": 2,
18+
"blockToLive":1000000,
19+
"memberOnlyRead": false,
20+
"endorsementPolicy": {
21+
"signaturePolicy": "OR('Org4MSP.member')"
22+
}
23+
}
24+
]

0 commit comments

Comments
 (0)