@@ -7,17 +7,14 @@ SPDX-License-Identifier: Apache-2.0
7
7
package e2e
8
8
9
9
import (
10
- "fmt"
11
10
"io/ioutil"
12
11
"os"
13
12
"path/filepath"
14
- "syscall"
15
- "time"
16
13
17
- docker "github.com/fsouza/go-dockerclient"
18
14
"github.com/gogo/protobuf/proto"
19
15
"github.com/hyperledger/fabric/common/tools/configtxlator/update"
20
16
"github.com/hyperledger/fabric/core/aclmgmt/resources"
17
+ "github.com/hyperledger/fabric/integration/runner"
21
18
"github.com/hyperledger/fabric/integration/world"
22
19
"github.com/hyperledger/fabric/protos/common"
23
20
pb "github.com/hyperledger/fabric/protos/peer"
@@ -29,18 +26,12 @@ import (
29
26
30
27
var _ = Describe ("EndToEndACL" , func () {
31
28
var (
32
- client * docker.Client
33
- w world.World
29
+ w * world.World
34
30
deployment world.Deployment
31
+ org1Peer0 * runner.Peer
35
32
)
36
33
37
34
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
44
35
w = world .GenerateBasicConfig ("solo" , 2 , 2 , testDir , components )
45
36
46
37
// sets up the world for all tests
@@ -60,152 +51,92 @@ var _ = Describe("EndToEndACL", func() {
60
51
copyFile (filepath .Join ("testdata" , "orderer.yaml" ), filepath .Join (testDir , "orderer.yaml" ))
61
52
copyPeerConfigs (w .PeerOrgs , w .Rootpath )
62
53
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" })
64
55
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" )
65
60
})
66
61
67
62
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 )
107
64
})
108
65
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" ))
201
132
})
202
133
})
203
134
204
135
// SetACLPolicy sets the ACL policy for the world on a running network. It resets all
205
136
// previously defined ACL policies. It performs the generation of the config update,
206
137
// signs the configuration with Org2's signer, and then submits the config update
207
138
// 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 ) {
209
140
outputFile := filepath .Join (testDir , "updated_config.pb" )
210
141
GenerateACLConfigUpdate (w , deployment , policyName , policy , outputFile )
211
142
@@ -218,7 +149,7 @@ func SetACLPolicy(w *world.World, deployment *world.Deployment, policyName, poli
218
149
SendConfigUpdate (deployment , outputFile , sendConfigDir , sendMSPConfigPath )
219
150
}
220
151
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 ) {
222
153
// fetch the config block
223
154
fetchRun := components .Peer ()
224
155
fetchRun .ConfigDir = filepath .Join (testDir , "peer0.org1.example.com" )
@@ -300,7 +231,7 @@ func SignConfigUpdate(w *world.World, outputFile, configDir, mspConfigPath strin
300
231
Expect (err ).To (BeNil ())
301
232
}
302
233
303
- func SendConfigUpdate (deployment * world.Deployment , outputFile , configDir , mspConfigPath string ) {
234
+ func SendConfigUpdate (deployment world.Deployment , outputFile , configDir , mspConfigPath string ) {
304
235
updateRun := components .Peer ()
305
236
updateRun .ConfigDir = configDir
306
237
updateRun .MSPConfigPath = mspConfigPath
0 commit comments