github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/integration/e2e/acl_test.go (about) 1 /* 2 Copyright hechain All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package e2e 8 9 import ( 10 "encoding/json" 11 "fmt" 12 "io/ioutil" 13 "os" 14 "path/filepath" 15 "syscall" 16 17 docker "github.com/fsouza/go-dockerclient" 18 "github.com/golang/protobuf/proto" 19 "github.com/hechain20/hechain/core/aclmgmt/resources" 20 "github.com/hechain20/hechain/integration/nwo" 21 "github.com/hechain20/hechain/integration/nwo/commands" 22 "github.com/hechain20/hechain/protoutil" 23 "github.com/hyperledger/fabric-protos-go/common" 24 pb "github.com/hyperledger/fabric-protos-go/peer" 25 . "github.com/onsi/ginkgo" 26 . "github.com/onsi/gomega" 27 "github.com/onsi/gomega/gbytes" 28 "github.com/onsi/gomega/gexec" 29 "github.com/tedsuo/ifrit" 30 ) 31 32 var _ = Describe("EndToEndACL", func() { 33 var ( 34 testDir string 35 client *docker.Client 36 network *nwo.Network 37 chaincode nwo.Chaincode 38 process ifrit.Process 39 40 orderer *nwo.Orderer 41 org1Peer0 *nwo.Peer 42 org2Peer0 *nwo.Peer 43 ) 44 45 BeforeEach(func() { 46 var err error 47 testDir, err = ioutil.TempDir("", "acl-e2e") 48 Expect(err).NotTo(HaveOccurred()) 49 50 client, err = docker.NewClientFromEnv() 51 Expect(err).NotTo(HaveOccurred()) 52 53 // Speed up test by reducing the number of peers we 54 // bring up and install chaincode to. 55 soloConfig := nwo.BasicSolo() 56 soloConfig.RemovePeer("Org1", "peer1") 57 soloConfig.RemovePeer("Org2", "peer1") 58 Expect(soloConfig.Peers).To(HaveLen(2)) 59 60 network = nwo.New(soloConfig, testDir, client, StartPort(), components) 61 network.GenerateConfigTree() 62 network.Bootstrap() 63 64 networkRunner := network.NetworkGroupRunner() 65 process = ifrit.Invoke(networkRunner) 66 Eventually(process.Ready(), network.EventuallyTimeout).Should(BeClosed()) 67 68 orderer = network.Orderer("orderer") 69 org1Peer0 = network.Peer("Org1", "peer0") 70 org2Peer0 = network.Peer("Org2", "peer0") 71 72 chaincode = nwo.Chaincode{ 73 Name: "mycc", 74 Version: "0.0", 75 Path: "github.com/hechain20/hechain/integration/chaincode/simple/cmd", 76 Ctor: `{"Args":["init","a","100","b","200"]}`, 77 Policy: `OR ('Org1MSP.member','Org2MSP.member')`, 78 } 79 network.CreateAndJoinChannel(orderer, "testchannel") 80 nwo.DeployChaincodeLegacy(network, "testchannel", orderer, chaincode) 81 }) 82 83 AfterEach(func() { 84 process.Signal(syscall.SIGTERM) 85 Eventually(process.Wait(), network.EventuallyTimeout).Should(Receive()) 86 network.Cleanup() 87 os.RemoveAll(testDir) 88 }) 89 90 It("enforces access control list policies", func() { 91 invokeChaincode := commands.ChaincodeInvoke{ 92 ChannelID: "testchannel", 93 Orderer: network.OrdererAddress(orderer, nwo.ListenPort), 94 Name: chaincode.Name, 95 Ctor: `{"Args":["invoke","a","b","10"]}`, 96 WaitForEvent: true, 97 } 98 99 outputBlock := filepath.Join(testDir, "newest_block.pb") 100 fetchNewest := commands.ChannelFetch{ 101 ChannelID: "testchannel", 102 Block: "newest", 103 OutputFile: outputBlock, 104 } 105 106 // 107 // when the ACL policy for DeliverFiltered is satisfied 108 // 109 By("setting the filtered block event ACL policy to Org1/Admins") 110 policyName := resources.Event_FilteredBlock 111 policy := "/Channel/Application/Org1/Admins" 112 SetACLPolicy(network, "testchannel", policyName, policy, "orderer") 113 114 By("invoking chaincode as a permitted Org1 Admin identity") 115 sess, err := network.PeerAdminSession(org1Peer0, invokeChaincode) 116 Expect(err).NotTo(HaveOccurred()) 117 Eventually(sess.Err, network.EventuallyTimeout).Should(gbytes.Say("Chaincode invoke successful. result: status:200")) 118 119 // 120 // when the ACL policy for DeliverFiltered is not satisfied 121 // 122 By("setting the filtered block event ACL policy to org2/Admins") 123 policyName = resources.Event_FilteredBlock 124 policy = "/Channel/Application/org2/Admins" 125 SetACLPolicy(network, "testchannel", policyName, policy, "orderer") 126 127 By("invoking chaincode as a forbidden Org1 Admin identity") 128 sess, err = network.PeerAdminSession(org1Peer0, invokeChaincode) 129 Expect(err).NotTo(HaveOccurred()) 130 Eventually(sess.Err, network.EventuallyTimeout).Should(gbytes.Say(`\Qdeliver completed with status (FORBIDDEN)\E`)) 131 132 // 133 // when the ACL policy for Deliver is satisfied 134 // 135 By("setting the block event ACL policy to Org1/Admins") 136 policyName = resources.Event_Block 137 policy = "/Channel/Application/Org1/Admins" 138 SetACLPolicy(network, "testchannel", policyName, policy, "orderer") 139 140 By("fetching the latest block from the peer as a permitted Org1 Admin identity") 141 sess, err = network.PeerAdminSession(org1Peer0, fetchNewest) 142 Expect(err).NotTo(HaveOccurred()) 143 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0)) 144 Expect(sess.Err).To(gbytes.Say("Received block: ")) 145 146 // 147 // when the ACL policy for Deliver is not satisfied 148 // 149 By("fetching the latest block from the peer as a forbidden org2 Admin identity") 150 sess, err = network.PeerAdminSession(org2Peer0, fetchNewest) 151 Expect(err).NotTo(HaveOccurred()) 152 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) 153 Expect(sess.Err).To(gbytes.Say("can't read the block: &{FORBIDDEN}")) 154 155 // 156 // when the ACL policy for lscc/GetInstantiatedChaincodes is satisfied 157 // 158 By("setting the lscc/GetInstantiatedChaincodes ACL policy to Org1/Admins") 159 policyName = resources.Lscc_GetInstantiatedChaincodes 160 policy = "/Channel/Application/Org1/Admins" 161 SetACLPolicy(network, "testchannel", policyName, policy, "orderer") 162 163 By("listing the instantiated chaincodes as a permitted Org1 Admin identity") 164 sess, err = network.PeerAdminSession(org1Peer0, commands.ChaincodeListInstantiatedLegacy{ 165 ChannelID: "testchannel", 166 }) 167 Expect(err).NotTo(HaveOccurred()) 168 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0)) 169 Expect(sess).To(gbytes.Say("Name: mycc, Version: 0.0, Path: .*, Escc: escc, Vscc: vscc")) 170 171 // 172 // when the ACL policy for lscc/GetInstantiatedChaincodes is not satisfied 173 // 174 By("listing the instantiated chaincodes as a forbidden org2 Admin identity") 175 sess, err = network.PeerAdminSession(org2Peer0, commands.ChaincodeListInstantiatedLegacy{ 176 ChannelID: "testchannel", 177 }) 178 Expect(err).NotTo(HaveOccurred()) 179 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) 180 Expect(sess).NotTo(gbytes.Say("Name: mycc, Version: 0.0, Path: .*, Escc: escc, Vscc: vscc")) 181 Expect(sess.Err).To(gbytes.Say(`access denied for \[getchaincodes\]\[testchannel\](.*)signature set did not satisfy policy`)) 182 183 // 184 // when a system chaincode ACL policy is set and a query is performed 185 // 186 187 // getting a transaction id from a block in the ledger 188 sess, err = network.PeerAdminSession(org1Peer0, fetchNewest) 189 Expect(err).NotTo(HaveOccurred()) 190 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0)) 191 Expect(sess.Err).To(gbytes.Say("Received block: ")) 192 txID := GetTxIDFromBlockFile(outputBlock) 193 194 ItEnforcesPolicy := func(scc, operation string, args ...string) { 195 policyName := fmt.Sprintf("%s/%s", scc, operation) 196 policy := "/Channel/Application/Org1/Admins" 197 By("setting " + policyName + " to Org1 Admins") 198 SetACLPolicy(network, "testchannel", policyName, policy, "orderer") 199 200 args = append([]string{operation}, args...) 201 chaincodeQuery := commands.ChaincodeQuery{ 202 ChannelID: "testchannel", 203 Name: scc, 204 Ctor: ToCLIChaincodeArgs(args...), 205 } 206 207 By("evaluating " + policyName + " for a permitted subject") 208 sess, err := network.PeerAdminSession(org1Peer0, chaincodeQuery) 209 Expect(err).NotTo(HaveOccurred()) 210 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit(0)) 211 212 By("evaluating " + policyName + " for a forbidden subject") 213 sess, err = network.PeerAdminSession(org2Peer0, chaincodeQuery) 214 Expect(err).NotTo(HaveOccurred()) 215 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) 216 Expect(sess.Err).To(gbytes.Say(fmt.Sprintf(`access denied for \[%s\]\[%s\](.*)signature set did not satisfy policy`, operation, "testchannel"))) 217 } 218 219 // 220 // qscc 221 // 222 ItEnforcesPolicy("qscc", "GetChainInfo", "testchannel") 223 ItEnforcesPolicy("qscc", "GetBlockByNumber", "testchannel", "0") 224 ItEnforcesPolicy("qscc", "GetBlockByTxID", "testchannel", txID) 225 ItEnforcesPolicy("qscc", "GetTransactionByID", "testchannel", txID) 226 227 // 228 // lscc 229 // 230 ItEnforcesPolicy("lscc", "GetChaincodeData", "testchannel", "mycc") 231 ItEnforcesPolicy("lscc", "ChaincodeExists", "testchannel", "mycc") 232 233 // 234 // cscc 235 // 236 ItEnforcesPolicy("cscc", "GetConfigBlock", "testchannel") 237 ItEnforcesPolicy("cscc", "GetChannelConfig", "testchannel") 238 239 // 240 // _lifecycle ACL policies 241 // 242 243 chaincode = nwo.Chaincode{ 244 Name: "mycc", 245 Version: "0.0", 246 Path: components.Build("github.com/hechain20/hechain/integration/chaincode/simple/cmd"), 247 Lang: "binary", 248 PackageFile: filepath.Join(testDir, "simplecc.tar.gz"), 249 Ctor: `{"Args":["init","a","100","b","200"]}`, 250 ChannelConfigPolicy: "/Channel/Application/Endorsement", 251 Sequence: "1", 252 InitRequired: true, 253 Label: "my_prebuilt_chaincode", 254 } 255 256 nwo.PackageChaincodeBinary(chaincode) 257 258 // 259 // when the ACL policy for _lifecycle/InstallChaincode is not satisfied 260 // 261 By("installing the chaincode to an org1 peer as an org2 admin") 262 sess, err = network.PeerAdminSession(org2Peer0, commands.ChaincodeInstall{ 263 PackageFile: chaincode.PackageFile, 264 PeerAddresses: []string{network.PeerAddress(org1Peer0, nwo.ListenPort)}, 265 }) 266 Expect(err).NotTo(HaveOccurred()) 267 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) 268 Expect(sess.Err).To(gbytes.Say(`access denied: channel \[\] creator org unknown, creator is malformed`)) 269 270 By("installing the chaincode to an org1 peer as a non-admin org1 identity") 271 sess, err = network.PeerUserSession(org1Peer0, "User1", commands.ChaincodeInstall{ 272 PackageFile: chaincode.PackageFile, 273 }) 274 Expect(err).NotTo(HaveOccurred()) 275 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) 276 Expect(sess.Err).To(gbytes.Say(`Error: chaincode install failed with status: 500 - Failed to authorize invocation due to failed ACL check: Failed verifying that proposal's creator satisfies local MSP principal during channelless check policy with policy \Q[Admins]\E: \Q[The identity is not an admin under this MSP [Org1MSP]: The identity does not contain OU [ADMIN], MSP: [Org1MSP]]\E`)) 277 278 // 279 // when the ACL policy for _lifecycle/InstallChaincode is satisfied 280 // 281 nwo.InstallChaincode(network, chaincode, org1Peer0, org2Peer0) 282 283 // 284 // when the V2_0 application capabilities flag has not yet been enabled 285 // 286 By("approving a chaincode definition on a channel without V2_0 capabilities enabled") 287 sess, err = network.PeerAdminSession(org1Peer0, commands.ChaincodeApproveForMyOrg{ 288 ChannelID: "testchannel", 289 Orderer: network.OrdererAddress(orderer, nwo.ListenPort), 290 Name: chaincode.Name, 291 Version: chaincode.Version, 292 Sequence: chaincode.Sequence, 293 EndorsementPlugin: chaincode.EndorsementPlugin, 294 ValidationPlugin: chaincode.ValidationPlugin, 295 SignaturePolicy: chaincode.SignaturePolicy, 296 ChannelConfigPolicy: chaincode.ChannelConfigPolicy, 297 InitRequired: chaincode.InitRequired, 298 CollectionsConfig: chaincode.CollectionsConfig, 299 }) 300 Expect(err).NotTo(HaveOccurred()) 301 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) 302 Expect(sess.Err).To(gbytes.Say("Error: proposal failed with status: 500 - cannot use new lifecycle for channel 'testchannel' as it does not have the required capabilities enabled")) 303 304 By("committing a chaincode definition on a channel without V2_0 capabilities enabled") 305 sess, err = network.PeerAdminSession(org1Peer0, commands.ChaincodeCommit{ 306 ChannelID: "testchannel", 307 Orderer: network.OrdererAddress(orderer, nwo.ListenPort), 308 Name: chaincode.Name, 309 Version: chaincode.Version, 310 Sequence: chaincode.Sequence, 311 EndorsementPlugin: chaincode.EndorsementPlugin, 312 ValidationPlugin: chaincode.ValidationPlugin, 313 SignaturePolicy: chaincode.SignaturePolicy, 314 ChannelConfigPolicy: chaincode.ChannelConfigPolicy, 315 InitRequired: chaincode.InitRequired, 316 CollectionsConfig: chaincode.CollectionsConfig, 317 }) 318 Expect(err).NotTo(HaveOccurred()) 319 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) 320 Expect(sess.Err).To(gbytes.Say("Error: proposal failed with status: 500 - cannot use new lifecycle for channel 'testchannel' as it does not have the required capabilities enabled")) 321 322 // enable V2_0 application capabilities on the channel 323 By("enabling V2_0 application capabilities on the channel") 324 nwo.EnableCapabilities(network, "testchannel", "Application", "V2_0", orderer, org1Peer0, org2Peer0) 325 326 // 327 // when the ACL policy for _lifecycle/ApproveChaincodeDefinitionForOrg is not satisfied 328 // 329 By("approving a chaincode definition for org1 as an org2 admin") 330 sess, err = network.PeerAdminSession(org2Peer0, commands.ChaincodeApproveForMyOrg{ 331 ChannelID: "testchannel", 332 Orderer: network.OrdererAddress(orderer, nwo.ListenPort), 333 Name: chaincode.Name, 334 Version: chaincode.Version, 335 Sequence: chaincode.Sequence, 336 EndorsementPlugin: chaincode.EndorsementPlugin, 337 ValidationPlugin: chaincode.ValidationPlugin, 338 SignaturePolicy: chaincode.SignaturePolicy, 339 ChannelConfigPolicy: chaincode.ChannelConfigPolicy, 340 InitRequired: chaincode.InitRequired, 341 CollectionsConfig: chaincode.CollectionsConfig, 342 PeerAddresses: []string{network.PeerAddress(org1Peer0, nwo.ListenPort)}, 343 }) 344 Expect(err).NotTo(HaveOccurred()) 345 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) 346 Expect(sess.Err).To(gbytes.Say(`Error: proposal failed with status: 500 - Failed to authorize invocation due to failed ACL check: Failed deserializing proposal creator during channelless check policy with policy \[Admins\]: \[expected MSP ID Org1MSP, received Org2MSP\]`)) 347 348 // 349 // when the ACL policy for _lifecycle/ApproveChaincodeDefinitionForOrg is satisfied 350 // 351 By("approving a chaincode definition for org1 and org2") 352 nwo.ApproveChaincodeForMyOrg(network, "testchannel", orderer, chaincode, org1Peer0, org2Peer0) 353 354 // 355 // when the ACL policy for _lifecycle/QueryApprovedChaincodeDefinition is not satisfied 356 // 357 By("querying the approved chaincode definition for org1 as an org2 admin") 358 sess, err = network.PeerAdminSession(org2Peer0, commands.ChaincodeQueryApproved{ 359 ChannelID: "testchannel", 360 Name: chaincode.Name, 361 Sequence: chaincode.Sequence, 362 PeerAddresses: []string{network.PeerAddress(org1Peer0, nwo.ListenPort)}, 363 }) 364 Expect(err).NotTo(HaveOccurred()) 365 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) 366 Expect(sess.Err).To(gbytes.Say(`\QError: query failed with status: 500 - Failed to authorize invocation due to failed ACL check: Failed deserializing proposal creator during channelless check policy with policy [Admins]: [expected MSP ID Org1MSP, received Org2MSP]\E`)) 367 368 // 369 // when the ACL policy for _lifecycle/QueryApprovedChaincodeDefinition is satisfied 370 // 371 By("querying the approved chaincode definition for org1 as an org1 admin") 372 nwo.EnsureChaincodeApproved(network, org1Peer0, "testchannel", chaincode.Name, chaincode.Sequence) 373 374 // 375 // when the ACL policy for CheckCommitReadiness is not satisfied 376 // 377 By("setting the simulate commit chaincode definition ACL policy to Org1/Admins") 378 policyName = resources.Lifecycle_CheckCommitReadiness 379 policy = "/Channel/Application/Org1/Admins" 380 SetACLPolicy(network, "testchannel", policyName, policy, "orderer") 381 382 By("simulating the commit of a chaincode dwefinition as a forbidden Org2 Admin identity") 383 sess, err = network.PeerAdminSession(org2Peer0, commands.ChaincodeCheckCommitReadiness{ 384 ChannelID: "testchannel", 385 Name: chaincode.Name, 386 Version: chaincode.Version, 387 Sequence: chaincode.Sequence, 388 EndorsementPlugin: chaincode.EndorsementPlugin, 389 ValidationPlugin: chaincode.ValidationPlugin, 390 SignaturePolicy: chaincode.SignaturePolicy, 391 ChannelConfigPolicy: chaincode.ChannelConfigPolicy, 392 InitRequired: chaincode.InitRequired, 393 CollectionsConfig: chaincode.CollectionsConfig, 394 }) 395 Expect(err).NotTo(HaveOccurred()) 396 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) 397 Expect(sess.Err).To(gbytes.Say(`\QError: query failed with status: 500 - Failed to authorize invocation due to failed ACL check: failed evaluating policy on signed data during check policy [/Channel/Application/Org1/Admins]: [signature set did not satisfy policy]\E`)) 398 399 // 400 // when the ACL policy for CheckCommitReadiness is satisfied 401 // 402 nwo.CheckCommitReadinessUntilReady(network, "testchannel", chaincode, network.PeerOrgs(), org1Peer0) 403 404 // 405 // when the ACL policy for CommitChaincodeDefinition is not satisfied 406 // 407 By("setting the commit chaincode definition ACL policy to Org1/Admins") 408 policyName = resources.Lifecycle_CommitChaincodeDefinition 409 policy = "/Channel/Application/Org1/Admins" 410 SetACLPolicy(network, "testchannel", policyName, policy, "orderer") 411 412 By("committing the chaincode definition as a forbidden Org2 Admin identity") 413 peerAddresses := []string{ 414 network.PeerAddress(org1Peer0, nwo.ListenPort), 415 network.PeerAddress(org2Peer0, nwo.ListenPort), 416 } 417 sess, err = network.PeerAdminSession(org2Peer0, commands.ChaincodeCommit{ 418 ChannelID: "testchannel", 419 Orderer: network.OrdererAddress(orderer, nwo.ListenPort), 420 Name: chaincode.Name, 421 Version: chaincode.Version, 422 Sequence: chaincode.Sequence, 423 EndorsementPlugin: chaincode.EndorsementPlugin, 424 ValidationPlugin: chaincode.ValidationPlugin, 425 SignaturePolicy: chaincode.SignaturePolicy, 426 ChannelConfigPolicy: chaincode.ChannelConfigPolicy, 427 InitRequired: chaincode.InitRequired, 428 CollectionsConfig: chaincode.CollectionsConfig, 429 PeerAddresses: peerAddresses, 430 }) 431 Expect(err).NotTo(HaveOccurred()) 432 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) 433 Expect(sess.Err).To(gbytes.Say(`\QError: proposal failed with status: 500 - Failed to authorize invocation due to failed ACL check: failed evaluating policy on signed data during check policy [/Channel/Application/Org1/Admins]: [signature set did not satisfy policy]\E`)) 434 435 // 436 // when the ACL policy for CommitChaincodeDefinition is satisfied 437 // 438 nwo.CommitChaincode(network, "testchannel", orderer, chaincode, org1Peer0, org1Peer0, org2Peer0) 439 440 // 441 // when the ACL policy for QueryChaincodeDefinition is satisfied 442 // 443 By("setting the query chaincode definition ACL policy to Org1/Admins") 444 policyName = resources.Lifecycle_QueryChaincodeDefinition 445 policy = "/Channel/Application/Org1/Admins" 446 SetACLPolicy(network, "testchannel", policyName, policy, "orderer") 447 448 By("querying the chaincode definition as a permitted Org1 Admin identity") 449 nwo.EnsureChaincodeCommitted(network, "testchannel", "mycc", "0.0", "1", []*nwo.Organization{network.Organization("Org1"), network.Organization("Org2")}, org1Peer0) 450 451 By("querying the chaincode definition as a forbidden Org2 Admin identity") 452 sess, err = network.PeerAdminSession(org2Peer0, commands.ChaincodeListCommitted{ 453 ChannelID: "testchannel", 454 Name: "mycc", 455 }) 456 Expect(err).NotTo(HaveOccurred()) 457 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) 458 Expect(sess.Err).To(gbytes.Say(`\QError: query failed with status: 500 - Failed to authorize invocation due to failed ACL check: failed evaluating policy on signed data during check policy [/Channel/Application/Org1/Admins]: [signature set did not satisfy policy]\E`)) 459 460 // 461 // when the ACL policy for snapshot related commands is not satisfied (e.g., non-admin user or admin in another org) 462 // 463 By("calling snapshot submitrequest as a non-permitted identity") 464 expectedMsgNonAdmin := `\Qfailed verifying that the signed data identity satisfies local MSP principal during channelless check policy with policy [Admins]: [The identity is not an admin under this MSP [Org1MSP]: The identity does not contain OU [ADMIN], MSP: [Org1MSP]]\E` 465 expectedMsgAdminWrongOrg := `\Qfailed deserializing signed data identity during channelless check policy with policy [Admins]: [expected MSP ID Org1MSP, received Org2MSP]\E` 466 submitrequestCmd := &commands.SnapshotSubmitRequest{ 467 ChannelID: "testchannel", 468 BlockNumber: "100", 469 ClientAuth: network.ClientAuthRequired, 470 PeerAddress: network.PeerAddress(org1Peer0, nwo.ListenPort), 471 } 472 verifyCommandErr(network, org1Peer0, "User1", submitrequestCmd, expectedMsgNonAdmin) 473 verifyCommandErr(network, org2Peer0, "Admin", submitrequestCmd, expectedMsgAdminWrongOrg) 474 475 By("calling snapshot cancelrequest as a non-permitted identity") 476 cancelrequestCmd := &commands.SnapshotCancelRequest{ 477 ChannelID: "testchannel", 478 BlockNumber: "100", 479 ClientAuth: network.ClientAuthRequired, 480 PeerAddress: network.PeerAddress(org1Peer0, nwo.ListenPort), 481 } 482 verifyCommandErr(network, org1Peer0, "User1", cancelrequestCmd, expectedMsgNonAdmin) 483 verifyCommandErr(network, org2Peer0, "Admin", cancelrequestCmd, expectedMsgAdminWrongOrg) 484 485 By("calling snapshot listpending as a non-permitted identity") 486 listpendingCmd := &commands.SnapshotListPending{ 487 ChannelID: "testchannel", 488 ClientAuth: network.ClientAuthRequired, 489 PeerAddress: network.PeerAddress(org1Peer0, nwo.ListenPort), 490 } 491 verifyCommandErr(network, org1Peer0, "User1", listpendingCmd, expectedMsgNonAdmin) 492 verifyCommandErr(network, org2Peer0, "Admin", listpendingCmd, expectedMsgAdminWrongOrg) 493 494 By("calling joinbysnapshot as a non-permitted identity") 495 expectedMsgNonAdmin = `\QFailed verifying that proposal's creator satisfies local MSP principal during channelless check policy with policy [Admins]: [The identity is not an admin under this MSP [Org1MSP]: The identity does not contain OU [ADMIN], MSP: [Org1MSP]]\E` 496 joinbysnapshotCmd := commands.ChannelJoinBySnapshot{ 497 SnapshotPath: "/tmp/dummy_dir", 498 ClientAuth: network.ClientAuthRequired, 499 } 500 verifyCommandErr(network, org1Peer0, "User1", joinbysnapshotCmd, expectedMsgNonAdmin) 501 502 By("calling joinbysnapshotstatus as a non-permitted identity") 503 joinbysnapshotstatusCmd := commands.ChannelJoinBySnapshotStatus{ 504 ClientAuth: network.ClientAuthRequired, 505 } 506 verifyCommandErr(network, org1Peer0, "User1", joinbysnapshotstatusCmd, expectedMsgNonAdmin) 507 }) 508 }) 509 510 // SetACLPolicy sets the ACL policy for a running network. It resets all 511 // previously defined ACL policies, generates the config update, signs the 512 // configuration with Org2's signer, and then submits the config update using 513 // Org1. 514 func SetACLPolicy(network *nwo.Network, channel, policyName, policy string, ordererName string) { 515 orderer := network.Orderer(ordererName) 516 submitter := network.Peer("Org1", "peer0") 517 signer := network.Peer("Org2", "peer0") 518 519 config := nwo.GetConfig(network, submitter, orderer, channel) 520 updatedConfig := proto.Clone(config).(*common.Config) 521 522 // set the policy 523 updatedConfig.ChannelGroup.Groups["Application"].Values["ACLs"] = &common.ConfigValue{ 524 ModPolicy: "Admins", 525 Value: protoutil.MarshalOrPanic(&pb.ACLs{ 526 Acls: map[string]*pb.APIResource{ 527 policyName: {PolicyRef: policy}, 528 }, 529 }), 530 } 531 532 nwo.UpdateConfig(network, orderer, channel, config, updatedConfig, true, submitter, signer) 533 } 534 535 // GetTxIDFromBlock gets a transaction id from a block that has been 536 // marshaled and stored on the filesystem 537 func GetTxIDFromBlockFile(blockFile string) string { 538 block := nwo.UnmarshalBlockFromFile(blockFile) 539 540 txID, err := protoutil.GetOrComputeTxIDFromEnvelope(block.Data.Data[0]) 541 Expect(err).NotTo(HaveOccurred()) 542 543 return txID 544 } 545 546 // ToCLIChaincodeArgs converts string args to args for use with chaincode calls 547 // from the CLI. 548 func ToCLIChaincodeArgs(args ...string) string { 549 type cliArgs struct { 550 Args []string 551 } 552 cArgs := &cliArgs{Args: args} 553 cArgsJSON, err := json.Marshal(cArgs) 554 Expect(err).NotTo(HaveOccurred()) 555 return string(cArgsJSON) 556 } 557 558 func verifyCommandErr(network *nwo.Network, peer *nwo.Peer, user string, cmd nwo.Command, expectedMsg string) { 559 sess, err := network.PeerUserSession(peer, user, cmd) 560 Expect(err).NotTo(HaveOccurred()) 561 Eventually(sess, network.EventuallyTimeout).Should(gexec.Exit()) 562 Expect(sess.Err).To(gbytes.Say(expectedMsg)) 563 }