github.com/hellobchain/third_party@v0.0.0-20230331131523-deb0478a2e52/hyperledger/fabric-config/configtx/organization_test.go (about) 1 /* 2 Copyright IBM Corp All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package configtx 8 9 import ( 10 "bytes" 11 "fmt" 12 "github.com/hellobchain/third_party/hyperledger/fabric-config/protolator" 13 "github.com/hellobchain/third_party/hyperledger/fabric-config/protolator/protoext/ordererext" 14 "testing" 15 16 . "github.com/onsi/gomega" 17 ) 18 19 func TestOrganization(t *testing.T) { 20 t.Parallel() 21 gt := NewGomegaWithT(t) 22 23 expectedOrg := baseApplicationOrg(t) 24 expectedOrg.AnchorPeers = nil 25 orgGroup, err := newOrgConfigGroup(expectedOrg) 26 gt.Expect(err).NotTo(HaveOccurred()) 27 28 org, err := getOrganization(orgGroup, "Org1") 29 gt.Expect(err).NotTo(HaveOccurred()) 30 gt.Expect(expectedOrg).To(Equal(org)) 31 } 32 33 func TestNewOrgConfigGroup(t *testing.T) { 34 t.Parallel() 35 36 t.Run("success", func(t *testing.T) { 37 t.Parallel() 38 gt := NewGomegaWithT(t) 39 40 baseSystemChannelProfile, _, _ := baseSystemChannelProfile(t) 41 org := baseSystemChannelProfile.Orderer.Organizations[0] 42 configGroup, err := newOrdererOrgConfigGroup(org) 43 gt.Expect(err).NotTo(HaveOccurred()) 44 45 certBase64, crlBase64 := certCRLBase64(t, org.MSP) 46 47 // The organization is from network.BasicSolo Profile 48 // configtxgen -printOrg Org1 49 expectedPrintOrg := fmt.Sprintf(` 50 { 51 "groups": {}, 52 "mod_policy": "Admins", 53 "policies": { 54 "Admins": { 55 "mod_policy": "Admins", 56 "policy": { 57 "type": 3, 58 "value": { 59 "rule": "MAJORITY", 60 "sub_policy": "Admins" 61 } 62 }, 63 "version": "0" 64 }, 65 "Endorsement": { 66 "mod_policy": "Admins", 67 "policy": { 68 "type": 3, 69 "value": { 70 "rule": "MAJORITY", 71 "sub_policy": "Endorsement" 72 } 73 }, 74 "version": "0" 75 }, 76 "Readers": { 77 "mod_policy": "Admins", 78 "policy": { 79 "type": 3, 80 "value": { 81 "rule": "ANY", 82 "sub_policy": "Readers" 83 } 84 }, 85 "version": "0" 86 }, 87 "Writers": { 88 "mod_policy": "Admins", 89 "policy": { 90 "type": 3, 91 "value": { 92 "rule": "ANY", 93 "sub_policy": "Writers" 94 } 95 }, 96 "version": "0" 97 } 98 }, 99 "values": { 100 "Endpoints": { 101 "mod_policy": "Admins", 102 "value": { 103 "addresses": [ 104 "localhost:123" 105 ] 106 }, 107 "version": "0" 108 }, 109 "MSP": { 110 "mod_policy": "Admins", 111 "value": { 112 "config": { 113 "admins": [ 114 "%[1]s" 115 ], 116 "crypto_config": { 117 "identity_identifier_hash_function": "SHA256", 118 "signature_hash_family": "SHA3" 119 }, 120 "fabric_node_ous": { 121 "admin_ou_identifier": { 122 "certificate": "%[1]s", 123 "organizational_unit_identifier": "OUID" 124 }, 125 "client_ou_identifier": { 126 "certificate": "%[1]s", 127 "organizational_unit_identifier": "OUID" 128 }, 129 "enable": false, 130 "orderer_ou_identifier": { 131 "certificate": "%[1]s", 132 "organizational_unit_identifier": "OUID" 133 }, 134 "peer_ou_identifier": { 135 "certificate": "%[1]s", 136 "organizational_unit_identifier": "OUID" 137 } 138 }, 139 "intermediate_certs": [ 140 "%[1]s" 141 ], 142 "name": "MSPID", 143 "organizational_unit_identifiers": [ 144 { 145 "certificate": "%[1]s", 146 "organizational_unit_identifier": "OUID" 147 } 148 ], 149 "revocation_list": [ 150 "%[2]s" 151 ], 152 "root_certs": [ 153 "%[1]s" 154 ], 155 "signing_identity": null, 156 "tls_intermediate_certs": [ 157 "%[1]s" 158 ], 159 "tls_root_certs": [ 160 "%[1]s" 161 ] 162 }, 163 "type": 0 164 }, 165 "version": "0" 166 } 167 }, 168 "version": "0" 169 } 170 `, certBase64, crlBase64) 171 172 buf := bytes.Buffer{} 173 err = protolator.DeepMarshalJSON(&buf, &ordererext.DynamicOrdererOrgGroup{ConfigGroup: configGroup}) 174 gt.Expect(err).NotTo(HaveOccurred()) 175 176 gt.Expect(buf.String()).To(MatchJSON(expectedPrintOrg)) 177 }) 178 } 179 180 func TestNewOrgConfigGroupFailure(t *testing.T) { 181 t.Parallel() 182 183 gt := NewGomegaWithT(t) 184 185 baseSystemChannelProfile, _, _ := baseSystemChannelProfile(t) 186 baseOrg := baseSystemChannelProfile.Orderer.Organizations[0] 187 baseOrg.Policies = nil 188 189 configGroup, err := newOrgConfigGroup(baseOrg) 190 gt.Expect(configGroup).To(BeNil()) 191 gt.Expect(err).To(MatchError("no policies defined")) 192 } 193 194 func baseApplicationOrg(t *testing.T) Organization { 195 msp, _ := baseMSP(t) 196 return Organization{ 197 Name: "Org1", 198 Policies: standardPolicies(), 199 MSP: msp, 200 AnchorPeers: []Address{ 201 {Host: "host3", Port: 123}, 202 }, 203 } 204 }