Skip to content

Commit fe34feb

Browse files
committed
[FAB-10475] DRY up e2e suite and fix minor issues
- pulled repeated docker cleanup into world.Close - collapsed n peer runners into one for acl test - removed Contexts embedded inside of ginkgo specs as the behavior is non-deterministic - extract query/invoke/query used by solo and kafka into a function Change-Id: I89d4808521892b58662129d8b4467c8b71ab4e2b Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent 8f79ea1 commit fe34feb

File tree

5 files changed

+225
-405
lines changed

5 files changed

+225
-405
lines changed

integration/e2e/acl_test.go

+78-147
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@ SPDX-License-Identifier: Apache-2.0
77
package e2e
88

99
import (
10-
"fmt"
1110
"io/ioutil"
1211
"os"
1312
"path/filepath"
14-
"syscall"
15-
"time"
1613

17-
docker "github.com/fsouza/go-dockerclient"
1814
"github.com/gogo/protobuf/proto"
1915
"github.com/hyperledger/fabric/common/tools/configtxlator/update"
2016
"github.com/hyperledger/fabric/core/aclmgmt/resources"
17+
"github.com/hyperledger/fabric/integration/runner"
2118
"github.com/hyperledger/fabric/integration/world"
2219
"github.com/hyperledger/fabric/protos/common"
2320
pb "github.com/hyperledger/fabric/protos/peer"
@@ -29,18 +26,12 @@ import (
2926

3027
var _ = Describe("EndToEndACL", func() {
3128
var (
32-
client *docker.Client
33-
w world.World
29+
w *world.World
3430
deployment world.Deployment
31+
org1Peer0 *runner.Peer
3532
)
3633

3734
BeforeEach(func() {
38-
var err error
39-
40-
client, err = docker.NewClientFromEnv()
41-
Expect(err).NotTo(HaveOccurred())
42-
43-
// generating files to bootstrap the network
4435
w = world.GenerateBasicConfig("solo", 2, 2, testDir, components)
4536

4637
// sets up the world for all tests
@@ -60,152 +51,92 @@ var _ = Describe("EndToEndACL", func() {
6051
copyFile(filepath.Join("testdata", "orderer.yaml"), filepath.Join(testDir, "orderer.yaml"))
6152
copyPeerConfigs(w.PeerOrgs, w.Rootpath)
6253
w.BuildNetwork()
63-
err = w.SetupChannel(deployment, []string{"peer0.org1.example.com", "peer0.org2.example.com"})
54+
err := w.SetupChannel(deployment, []string{"peer0.org1.example.com", "peer0.org2.example.com"})
6455
Expect(err).NotTo(HaveOccurred())
56+
57+
org1Peer0 = components.Peer()
58+
org1Peer0.ConfigDir = filepath.Join(w.Rootpath, "peer0.org1.example.com")
59+
org1Peer0.MSPConfigPath = filepath.Join(w.Rootpath, "crypto", "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
6560
})
6661

6762
AfterEach(func() {
68-
// Stop the running chaincode containers
69-
filters := map[string][]string{}
70-
filters["name"] = []string{fmt.Sprintf("%s-%s", deployment.Chaincode.Name, deployment.Chaincode.Version)}
71-
allContainers, _ := client.ListContainers(docker.ListContainersOptions{
72-
Filters: filters,
73-
})
74-
if len(allContainers) > 0 {
75-
for _, container := range allContainers {
76-
client.RemoveContainer(docker.RemoveContainerOptions{
77-
ID: container.ID,
78-
Force: true,
79-
})
80-
}
81-
}
82-
83-
// Remove chaincode image
84-
filters = map[string][]string{}
85-
filters["label"] = []string{fmt.Sprintf("org.hyperledger.fabric.chaincode.id.name=%s", deployment.Chaincode.Name)}
86-
images, _ := client.ListImages(docker.ListImagesOptions{
87-
Filters: filters,
88-
})
89-
if len(images) > 0 {
90-
for _, image := range images {
91-
client.RemoveImage(image.ID)
92-
}
93-
}
94-
95-
// Stop the orderers and peers
96-
for _, localProc := range w.LocalProcess {
97-
localProc.Signal(syscall.SIGTERM)
98-
Eventually(localProc.Wait(), 5*time.Second).Should(Receive())
99-
localProc.Signal(syscall.SIGKILL)
100-
Eventually(localProc.Wait(), 5*time.Second).Should(Receive())
101-
}
102-
103-
// Remove any started networks
104-
if w.Network != nil {
105-
client.RemoveNetwork(w.Network.Name)
106-
}
63+
w.Close(deployment)
10764
})
10865

109-
It("tests ACL policies", func() {
110-
Context("when the ACL policy for DeliverFiltered is satisified", func() {
111-
By("setting the filtered block event ACL policy to Org1/Admins")
112-
policyName := resources.Event_FilteredBlock
113-
policy := "/Channel/Application/Org1/Admins"
114-
SetACLPolicy(&w, &deployment, policyName, policy)
115-
116-
By("waiting for the transaction to commit to the ledger using an Org1 Admin identity")
117-
adminPeer := components.Peer()
118-
adminPeer.ConfigDir = filepath.Join(testDir, "peer0.org1.example.com")
119-
adminPeer.MSPConfigPath = filepath.Join(testDir, "crypto", "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
120-
121-
adminRunner := adminPeer.InvokeChaincode(deployment.Chaincode.Name, deployment.Channel, `{"Args":["invoke","a","b","10"]}`, deployment.Orderer, "--waitForEvent")
122-
execute(adminRunner)
123-
Eventually(adminRunner.Err()).Should(gbytes.Say("Chaincode invoke successful. result: status:200"))
124-
})
125-
126-
Context("when the ACL policy for DeliverFiltered is not satisifed", func() {
127-
By("setting the filtered block event ACL policy to Org2/Admins")
128-
policyName := resources.Event_FilteredBlock
129-
policy := "/Channel/Application/Org2/Admins"
130-
SetACLPolicy(&w, &deployment, policyName, policy)
131-
132-
By("waiting for the transaction to commit to the ledger using an Org1 Admin identity")
133-
adminPeer := components.Peer()
134-
adminPeer.ConfigDir = filepath.Join(testDir, "peer0.org1.example.com")
135-
adminPeer.MSPConfigPath = filepath.Join(testDir, "crypto", "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
136-
137-
adminRunner := adminPeer.InvokeChaincode(deployment.Chaincode.Name, deployment.Channel, `{"Args":["invoke","a","b","10"]}`, deployment.Orderer, "--waitForEvent")
138-
execute(adminRunner)
139-
Eventually(adminRunner.Err()).Should(gbytes.Say(`\Qdeliver completed with status (FORBIDDEN)\E`))
140-
})
141-
142-
Context("when the ACL policy for Deliver is satisfied", func() {
143-
By("setting the block event ACL policy to Org1/Admins")
144-
policyName := resources.Event_Block
145-
policy := "/Channel/Application/Org1/Admins"
146-
SetACLPolicy(&w, &deployment, policyName, policy)
147-
148-
By("setting the log level for deliver to debug")
149-
logRun := w.Components.Peer()
150-
logRun.ConfigDir = filepath.Join(w.Rootpath, "peer0.org1.example.com")
151-
logRun.MSPConfigPath = filepath.Join(w.Rootpath, "crypto", "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
152-
lRunner := logRun.SetLogLevel("common/deliver", "debug")
153-
execute(lRunner)
154-
Expect(lRunner.Err()).To(gbytes.Say("Log level set for peer modules matching regular expression 'common/deliver': DEBUG"))
155-
156-
By("fetching the latest block from the peer")
157-
fetchRun := w.Components.Peer()
158-
fetchRun.ConfigDir = filepath.Join(w.Rootpath, "peer0.org1.example.com")
159-
fetchRun.MSPConfigPath = filepath.Join(w.Rootpath, "crypto", "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
160-
fRunner := fetchRun.FetchChannel(deployment.Channel, filepath.Join(testDir, "newest_block.pb"), "newest", "")
161-
execute(fRunner)
162-
Expect(fRunner.Err()).To(gbytes.Say("Received block: "))
163-
// TODO - enable this once the peer's logs are available here
164-
// Expect(peerRunner.Err()).To(gbytes.Say(`\Q[channel: testchannel] Done delivering \E`))
165-
166-
By("setting the log level for deliver to back to info")
167-
lRunner = logRun.SetLogLevel("common/deliver", "info")
168-
execute(lRunner)
169-
Expect(lRunner.Err()).To(gbytes.Say("Log level set for peer modules matching regular expression 'common/deliver': INFO"))
170-
})
171-
172-
Context("tests when the ACL policy for Deliver is not satisifed", func() {
173-
By("setting the block event ACL policy to Org2/Admins")
174-
policyName := resources.Event_Block
175-
policy := "/Channel/Application/Org2/Admins"
176-
SetACLPolicy(&w, &deployment, policyName, policy)
177-
178-
By("setting the log level for deliver to debug")
179-
logRun := w.Components.Peer()
180-
logRun.ConfigDir = filepath.Join(w.Rootpath, "peer0.org1.example.com")
181-
logRun.MSPConfigPath = filepath.Join(w.Rootpath, "crypto", "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
182-
lRunner := logRun.SetLogLevel("common/deliver", "debug")
183-
execute(lRunner)
184-
Expect(lRunner.Err()).To(gbytes.Say("Log level set for peer modules matching regular expression 'common/deliver': DEBUG"))
185-
186-
By("fetching the latest block from the peer")
187-
fetchRun := w.Components.Peer()
188-
fetchRun.ConfigDir = filepath.Join(w.Rootpath, "peer0.org1.example.com")
189-
fetchRun.MSPConfigPath = filepath.Join(w.Rootpath, "crypto", "peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp")
190-
fRunner := fetchRun.FetchChannel(deployment.Channel, filepath.Join(testDir, "newest_block.pb"), "newest", "")
191-
execute(fRunner)
192-
Expect(fRunner.Err()).To(gbytes.Say("can't read the block: &{FORBIDDEN}"))
193-
// TODO - enable this once the peer's logs are available here
194-
// Expect(peerRunner.Err()).To(gbytes.Say(`\Q[channel: testchannel] Done delivering \Q`))
195-
196-
By("setting the log level for deliver to back to info")
197-
lRunner = logRun.SetLogLevel("common/deliver", "info")
198-
execute(lRunner)
199-
Expect(lRunner.Err()).To(gbytes.Say("Log level set for peer modules matching regular expression 'common/deliver': INFO"))
200-
})
66+
It("enforces access control list policies", func() {
67+
//
68+
// when the ACL policy for DeliverFiltered is satisified
69+
//
70+
By("setting the filtered block event ACL policy to Org1/Admins")
71+
policyName := resources.Event_FilteredBlock
72+
policy := "/Channel/Application/Org1/Admins"
73+
SetACLPolicy(w, deployment, policyName, policy)
74+
75+
By("invoking chaincode as a permitted Org1 Admin identity")
76+
adminRunner := org1Peer0.InvokeChaincode(deployment.Chaincode.Name, deployment.Channel, `{"Args":["invoke","a","b","10"]}`, deployment.Orderer, "--waitForEvent")
77+
execute(adminRunner)
78+
Eventually(adminRunner.Err()).Should(gbytes.Say("Chaincode invoke successful. result: status:200"))
79+
80+
//
81+
// when the ACL policy for DeliverFiltered is not satisifed
82+
//
83+
By("setting the filtered block event ACL policy to Org2/Admins")
84+
policyName = resources.Event_FilteredBlock
85+
policy = "/Channel/Application/Org2/Admins"
86+
SetACLPolicy(w, deployment, policyName, policy)
87+
88+
By("invoking chaincode as a forbidden Org1 Admin identity")
89+
adminRunner = org1Peer0.InvokeChaincode(deployment.Chaincode.Name, deployment.Channel, `{"Args":["invoke","a","b","10"]}`, deployment.Orderer, "--waitForEvent")
90+
execute(adminRunner)
91+
Eventually(adminRunner.Err()).Should(gbytes.Say(`\Qdeliver completed with status (FORBIDDEN)\E`))
92+
93+
//
94+
// when the ACL policy for Deliver is satisfied
95+
//
96+
By("setting the block event ACL policy to Org1/Admins")
97+
policyName = resources.Event_Block
98+
policy = "/Channel/Application/Org1/Admins"
99+
SetACLPolicy(w, deployment, policyName, policy)
100+
101+
By("setting the log level for deliver to debug")
102+
lRunner := org1Peer0.SetLogLevel("common/deliver", "debug")
103+
execute(lRunner)
104+
Expect(lRunner.Err()).To(gbytes.Say("Log level set for peer modules matching regular expression 'common/deliver': DEBUG"))
105+
106+
By("fetching the latest block from the peer as a permitted Org1 Admin identity")
107+
fRunner := org1Peer0.FetchChannel(deployment.Channel, filepath.Join(testDir, "newest_block.pb"), "newest", "")
108+
execute(fRunner)
109+
Expect(fRunner.Err()).To(gbytes.Say("Received block: "))
110+
// TODO - enable this once the peer's logs are available here
111+
// Expect(peerRunner.Err()).To(gbytes.Say(`\Q[channel: testchannel] Done delivering \E`))
112+
113+
//
114+
// when the ACL policy for Deliver is not satisifed
115+
//
116+
By("setting the block event ACL policy to Org2/Admins")
117+
policyName = resources.Event_Block
118+
policy = "/Channel/Application/Org2/Admins"
119+
SetACLPolicy(w, deployment, policyName, policy)
120+
121+
By("fetching the latest block from the peer as a forbidden Org1 Admin identity")
122+
fRunner = org1Peer0.FetchChannel(deployment.Channel, filepath.Join(testDir, "newest_block.pb"), "newest", "")
123+
execute(fRunner)
124+
Expect(fRunner.Err()).To(gbytes.Say("can't read the block: &{FORBIDDEN}"))
125+
// TODO - enable this once the peer's logs are available here
126+
// Expect(peerRunner.Err()).To(gbytes.Say(`\Q[channel: testchannel] Done delivering \Q`))
127+
128+
By("setting the log level for deliver to back to info")
129+
lRunner = org1Peer0.SetLogLevel("common/deliver", "info")
130+
execute(lRunner)
131+
Expect(lRunner.Err()).To(gbytes.Say("Log level set for peer modules matching regular expression 'common/deliver': INFO"))
201132
})
202133
})
203134

204135
// SetACLPolicy sets the ACL policy for the world on a running network. It resets all
205136
// previously defined ACL policies. It performs the generation of the config update,
206137
// signs the configuration with Org2's signer, and then submits the config update
207138
// using Org1
208-
func SetACLPolicy(w *world.World, deployment *world.Deployment, policyName, policy string) {
139+
func SetACLPolicy(w *world.World, deployment world.Deployment, policyName, policy string) {
209140
outputFile := filepath.Join(testDir, "updated_config.pb")
210141
GenerateACLConfigUpdate(w, deployment, policyName, policy, outputFile)
211142

@@ -218,7 +149,7 @@ func SetACLPolicy(w *world.World, deployment *world.Deployment, policyName, poli
218149
SendConfigUpdate(deployment, outputFile, sendConfigDir, sendMSPConfigPath)
219150
}
220151

221-
func GenerateACLConfigUpdate(w *world.World, deployment *world.Deployment, policyName, policy, outputFile string) {
152+
func GenerateACLConfigUpdate(w *world.World, deployment world.Deployment, policyName, policy, outputFile string) {
222153
// fetch the config block
223154
fetchRun := components.Peer()
224155
fetchRun.ConfigDir = filepath.Join(testDir, "peer0.org1.example.com")
@@ -300,7 +231,7 @@ func SignConfigUpdate(w *world.World, outputFile, configDir, mspConfigPath strin
300231
Expect(err).To(BeNil())
301232
}
302233

303-
func SendConfigUpdate(deployment *world.Deployment, outputFile, configDir, mspConfigPath string) {
234+
func SendConfigUpdate(deployment world.Deployment, outputFile, configDir, mspConfigPath string) {
304235
updateRun := components.Peer()
305236
updateRun.ConfigDir = configDir
306237
updateRun.MSPConfigPath = mspConfigPath

0 commit comments

Comments
 (0)