@@ -509,11 +509,11 @@ func TestDeployAndUpgrade(t *testing.T) {
509
509
chaincode .GetChain ().Stop (ctxt , cccid2 , & pb.ChaincodeDeploymentSpec {ChaincodeSpec : & pb.ChaincodeSpec {ChaincodeId : chaincodeID2 }})
510
510
}
511
511
512
- // TestACLFail deploys a chaincode and then tries to invoke it;
512
+ // TestWritersACLFail deploys a chaincode and then tries to invoke it;
513
513
// however we inject a special policy for writers to simulate
514
514
// the scenario in which the creator of this proposal is not among
515
515
// the writers for the chain
516
- func TestACLFail (t * testing.T ) {
516
+ func TestWritersACLFail (t * testing.T ) {
517
517
chainID := util .GetTestChainID ()
518
518
var ctxt = context .Background ()
519
519
@@ -567,8 +567,51 @@ func TestACLFail(t *testing.T) {
567
567
return
568
568
}
569
569
570
- fmt .Println ("TestACLFail passed" )
571
- t .Logf ("TestACLFail passed" )
570
+ fmt .Println ("TestWritersACLFail passed" )
571
+ t .Logf ("TestWritersACLFail passed" )
572
+
573
+ chaincode .GetChain ().Stop (ctxt , cccid , & pb.ChaincodeDeploymentSpec {ChaincodeSpec : & pb.ChaincodeSpec {ChaincodeId : chaincodeID }})
574
+ }
575
+
576
+ // TestAdminACLFail deploys tried to deploy a chaincode;
577
+ // however we inject a special policy for admins to simulate
578
+ // the scenario in which the creator of this proposal is not among
579
+ // the admins for the chain
580
+ func TestAdminACLFail (t * testing.T ) {
581
+ chainID := util .GetTestChainID ()
582
+
583
+ // here we inject a reject policy for admins
584
+ // to simulate the scenario in which the invoker
585
+ // is not authorized to issue this proposal
586
+ rejectpolicy := & mockpolicies.Policy {
587
+ Err : errors .New ("The creator of this proposal does not fulfil the writers policy of this chain" ),
588
+ }
589
+ pm := peer .GetPolicyManager (chainID )
590
+ pm .(* mockpolicies.Manager ).PolicyMap = map [string ]* mockpolicies.Policy {policies .ChannelApplicationAdmins : rejectpolicy }
591
+
592
+ var ctxt = context .Background ()
593
+
594
+ url := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example01"
595
+ chaincodeID := & pb.ChaincodeID {Path : url , Name : "ex01-fail1" , Version : "0" }
596
+
597
+ defer deleteChaincodeOnDisk ("ex01-fail1.0" )
598
+
599
+ f := "init"
600
+ argsDeploy := util .ToChaincodeArgs (f , "a" , "100" , "b" , "200" )
601
+ spec := & pb.ChaincodeSpec {Type : 1 , ChaincodeId : chaincodeID , Input : & pb.ChaincodeInput {Args : argsDeploy }}
602
+
603
+ cccid := ccprovider .NewCCContext (chainID , "ex01-fail1" , "0" , "" , false , nil , nil )
604
+
605
+ _ , _ , err := deploy (endorserServer , chainID , spec , nil )
606
+ if err == nil {
607
+ t .Fail ()
608
+ t .Logf ("Deploying chaincode should have failed!" )
609
+ chaincode .GetChain ().Stop (ctxt , cccid , & pb.ChaincodeDeploymentSpec {ChaincodeSpec : & pb.ChaincodeSpec {ChaincodeId : chaincodeID }})
610
+ return
611
+ }
612
+
613
+ fmt .Println ("TestAdminACLFail passed" )
614
+ t .Logf ("TestATestAdminACLFailCLFail passed" )
572
615
573
616
chaincode .GetChain ().Stop (ctxt , cccid , & pb.ChaincodeDeploymentSpec {ChaincodeSpec : & pb.ChaincodeSpec {ChaincodeId : chaincodeID }})
574
617
}
0 commit comments