github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/initializer/peer/config/v1/config_test.go (about) 1 /* 2 * Copyright contributors to the Hyperledger Fabric Operator project 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package v1_test 20 21 import ( 22 "github.com/IBM-Blockchain/fabric-operator/pkg/apis/common" 23 v1 "github.com/IBM-Blockchain/fabric-operator/pkg/apis/peer/v1" 24 config "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/peer/config/v1" 25 "github.com/IBM-Blockchain/fabric-operator/pkg/util/pointer" 26 . "github.com/onsi/ginkgo/v2" 27 . "github.com/onsi/gomega" 28 ) 29 30 const ( 31 certB64 = "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFb2dJQkFBS0NBUUVBdFJBUDlMemUyZEc1cm1rbmcvdVVtREFZU0VwUElqRFdUUDhqUjMxcUJ5Yjc3YWUrCnk3UTRvRnZod1lDVUhsUWVTWjFKeTdUUHpEcitoUk5hdDJYNGdGYUpGYmVFbC9DSHJ3Rk1mNzNzQStWV1pHdnkKdXhtbjB2bEdYMW5zSEo5aUdIUS9qR2FvV1FJYzlVbnpHWi8yWStlZkpxOWd3cDBNemFzWWZkdXordXVBNlp4VAp5TTdDOWFlWmxYL2ZMYmVkSXVXTzVzaXhPSlZQeUVpcWpkd0RiY1AxYy9mRCtSMm1DbmM3VGovSnVLK1poTGxPCnhGcVlFRmtROHBmSi9LY1pabVF1QURZVFh6RGp6OENxcTRTRU5ySzI0b2hQQkN2SGgyanplWjhGdGR4MmpSSFQKaXdCZWZEYWlSWVBSOUM4enk4K1Z2Wmt6S0hQV3N5aENiNUMrN1FJREFRQUJBb0lCQUZROGhzL2IxdW9Mc3BFOApCdEJXaVVsTWh0K0xBc25yWXFncnd5UU5hdmlzNEdRdXVJdFk2MGRmdCtZb2hjQ2ViZ0RkbG1tWlUxdTJ6cGJtCjdEdUt5MVFaN21rV0dpLytEWUlUM3AxSHBMZ2pTRkFzRUorUFRnN1BQamc2UTZrRlZjUCt3Vm4yb0xmWVRkU28KZE5zbEdxSmNMaVQzVHRMNzhlcjFnTTE5RzN6T3J1ZndrSGJSYU1BRmtvZ1ExUlZLSWpnVGUvbmpIMHFHNW9JagoxNEJLeFFKTUZFTG1pQk50NUx5OVMxWWdxTDRjbmNtUDN5L1QyNEdodVhNckx0eTVOeVhnS0dFZ1pUTDMzZzZvCnYreDFFMFRURWRjMVQvWVBGWkdBSXhHdWRKNWZZZ2JtWU9LZ09mUHZFOE9TbEV6OW56aHNnckVZYjdQVThpZDUKTHFycVJRRUNnWUVBNjIyT3RIUmMxaVY1ZXQxdHQydTVTTTlTS2h2b0lPT3d2Q3NnTEI5dDJzNEhRUlRYN0RXcAo0VDNpUC9leEl5OXI3bTIxNFo5MEgzZlpVNElSUkdHSUxKUVMrYzRQNVA4cHJFTDcyd1dIWlpQTTM3QlZTQ1U3CkxOTXl4TkRjeVdjSUJIVFh4NUY2eXhLNVFXWTg5MVB0eDlDamJFSEcrNVJVdDA4UVlMWDlUQTBDZ1lFQXhPSmYKcXFjeThMOVZyYUFVZG9lbGdIU0NGSkJRR3hMRFNSQlJSTkRIOUJhaWlZOCtwZzd2TExTRXFMRFpsbkZPbFkrQQpiRENEQ0RtdHhwRXViY0x6b3FnOXhlQTZ0eXZZWkNWalY5dXVzNVh1Wmk1VDBBUHhCdm56OHNNa3dRY3RQWkRQCk8zQTN4WllkZzJBRmFrV1BmT1FFbjVaK3F4TU13SG9VZ1ZwQkptRUNnWUJ2Q2FjcTJVOEgrWGpJU0ROOU5TT1kKZ1ovaEdIUnRQcmFXcVVodFJ3MkxDMjFFZHM0NExEOUphdVNSQXdQYThuelhZWXROTk9XU0NmYkllaW9tdEZHRApwUHNtTXRnd1MyQ2VUS0Y0OWF5Y2JnOU0yVi8vdlAraDdxS2RUVjAwNkpGUmVNSms3K3FZYU9aVFFDTTFDN0swCmNXVUNwQ3R6Y014Y0FNQmF2THNRNlFLQmdHbXJMYmxEdjUxaXM3TmFKV0Z3Y0MwL1dzbDZvdVBFOERiNG9RV1UKSUowcXdOV2ZvZm95TGNBS3F1QjIrbkU2SXZrMmFiQ25ZTXc3V0w4b0VJa3NodUtYOVgrTVZ6Y1VPekdVdDNyaQpGeU9mcHJJRXowcm5zcWNSNUJJNUZqTGJqVFpyMEMyUWp2NW5FVFAvaHlpQWFRQ1l5THAyWlVtZ0Vjb0VPNWtwClBhcEJBb0dBZVV0WjE0SVp2cVorQnAxR1VqSG9PR0pQVnlJdzhSRUFETjRhZXRJTUlQRWFVaDdjZUtWdVN6VXMKci9WczA1Zjg0cFBVaStuUTUzaGo2ZFhhYTd1UE1aMFBnNFY4cS9UdzJMZ3BWWndVd0ltZUQrcXNsbldha3VWMQpMSnp3SkhOa3pOWE1OMmJWREFZTndSamNRSmhtbzF0V2xHYlpRQjNoSkEwR2thWGZPa2c9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==" 32 ) 33 34 var _ = Describe("Peer configuration", func() { 35 Context("reading and writing peer configuration file", func() { 36 BeforeEach(func() { 37 coreConfig := &config.Core{ 38 Core: v1.Core{ 39 Peer: v1.Peer{ 40 ID: "test", 41 }, 42 }, 43 } 44 45 err := coreConfig.WriteToFile("/tmp/core.yaml") 46 Expect(err).NotTo(HaveOccurred()) 47 }) 48 49 It("creates core.yaml", func() { 50 Expect("/tmp/core.yaml").Should(BeAnExistingFile()) 51 }) 52 53 It("read core.yaml", func() { 54 core, err := config.ReadCoreFile("/tmp/core.yaml") 55 Expect(err).NotTo(HaveOccurred()) 56 Expect(core.Peer.ID).To(Equal("test")) 57 }) 58 }) 59 60 It("merges current configuration with overrides values", func() { 61 core, err := config.ReadCoreFile("../../../../../testdata/init/peer/core.yaml") 62 Expect(err).NotTo(HaveOccurred()) 63 Expect(core.Peer.ID).To(Equal("jdoe")) 64 65 newConfig := &config.Core{ 66 Core: v1.Core{ 67 Peer: v1.Peer{ 68 ID: "test", 69 BCCSP: &common.BCCSP{ 70 ProviderName: "PKCS11", 71 PKCS11: &common.PKCS11Opts{ 72 Library: "library2", 73 Label: "label2", 74 Pin: "2222", 75 HashFamily: "SHA3", 76 SecLevel: 512, 77 FileKeyStore: &common.FileKeyStoreOpts{ 78 KeyStorePath: "keystore3", 79 }, 80 }, 81 }, 82 Discovery: v1.Discovery{ 83 Enabled: pointer.False(), 84 }, 85 Keepalive: v1.KeepAlive{ 86 MinInterval: common.MustParseDuration("13s"), 87 }, 88 DeliveryClient: v1.DeliveryClient{ 89 AddressOverrides: []v1.AddressOverride{ 90 v1.AddressOverride{ 91 From: "old", 92 To: "new", 93 CACertsFile: certB64, 94 }, 95 }, 96 }, 97 }, 98 }, 99 } 100 101 Expect(core.Peer.Keepalive.MinInterval).To(Equal(common.MustParseDuration("60s"))) 102 103 err = core.MergeWith(newConfig, true) 104 Expect(err).NotTo(HaveOccurred()) 105 Expect(core.Peer.ID).To(Equal("test")) 106 Expect(core.Peer.BCCSP.PKCS11.Library).To(Equal("/usr/local/lib/libpkcs11-proxy.so")) 107 Expect(core.Peer.BCCSP.PKCS11.Label).To(Equal("label2")) 108 Expect(core.Peer.BCCSP.PKCS11.Pin).To(Equal("2222")) 109 Expect(core.Peer.BCCSP.PKCS11.HashFamily).To(Equal("SHA3")) 110 Expect(core.Peer.BCCSP.PKCS11.SecLevel).To(Equal(512)) 111 Expect(core.Peer.BCCSP.PKCS11.FileKeyStore.KeyStorePath).To(Equal("keystore3")) 112 113 Expect(core.Peer.Keepalive.MinInterval).To(Equal(common.MustParseDuration("13s"))) 114 115 Expect(core.Peer.DeliveryClient.AddressOverrides[0].From).To(Equal("old")) 116 Expect(core.Peer.DeliveryClient.AddressOverrides[0].To).To(Equal("new")) 117 Expect(core.Peer.DeliveryClient.AddressOverrides[0].CACertsFile).To(Equal("/orderer/certs/cert0.pem")) 118 119 Expect(*core.Peer.Discovery.Enabled).To(Equal(false)) 120 }) 121 122 It("merges with default values", func() { 123 core, err := config.ReadCoreFile("../../../../../testdata/init/peer/core.yaml") 124 Expect(err).NotTo(HaveOccurred()) 125 Expect(core.Peer.ID).To(Equal("jdoe")) 126 127 newConfig := &config.Core{ 128 Core: v1.Core{ 129 Peer: v1.Peer{ 130 ID: "test", 131 BCCSP: &common.BCCSP{ 132 ProviderName: "PKCS11", 133 PKCS11: &common.PKCS11Opts{ 134 Label: "label2", 135 Pin: "2222", 136 }, 137 }, 138 Discovery: v1.Discovery{ 139 Enabled: pointer.False(), 140 }, 141 }, 142 }, 143 } 144 145 err = core.MergeWith(newConfig, true) 146 Expect(err).NotTo(HaveOccurred()) 147 Expect(core.Peer.ID).To(Equal("test")) 148 Expect(core.Peer.BCCSP.PKCS11.Library).To(Equal("/usr/local/lib/libpkcs11-proxy.so")) 149 Expect(core.Peer.BCCSP.PKCS11.Label).To(Equal("label2")) 150 Expect(core.Peer.BCCSP.PKCS11.Pin).To(Equal("2222")) 151 Expect(core.Peer.BCCSP.PKCS11.HashFamily).To(Equal("SHA2")) 152 Expect(core.Peer.BCCSP.PKCS11.SecLevel).To(Equal(256)) 153 Expect(core.Peer.BCCSP.PKCS11.FileKeyStore.KeyStorePath).To(Equal("keystore2")) 154 }) 155 156 It("reads in core.yaml and unmarshal it to peer config", func() { 157 core, err := config.ReadCoreFile("../../../../../testdata/init/peer/core.yaml") 158 Expect(err).NotTo(HaveOccurred()) 159 160 peerConfig := core.Peer 161 By("setting ID", func() { 162 Expect(peerConfig.ID).To(Equal("jdoe")) 163 }) 164 165 By("setting NetworkID", func() { 166 Expect(peerConfig.NetworkID).To(Equal("dev")) 167 }) 168 169 By("setting ListenAddress", func() { 170 Expect(peerConfig.ListenAddress).To(Equal("0.0.0.0:7051")) 171 }) 172 173 By("setting ChaincodeListenAddress", func() { 174 Expect(peerConfig.ChaincodeListenAddress).To(Equal("0.0.0.0:7052")) 175 }) 176 177 By("setting ChaincodeAddress", func() { 178 Expect(peerConfig.ChaincodeAddress).To(Equal("0.0.0.0:7053")) 179 }) 180 181 By("setting Address", func() { 182 Expect(peerConfig.Address).To(Equal("0.0.0.0:7054")) 183 }) 184 185 By("setting AddressAutoDetect", func() { 186 Expect(*peerConfig.AddressAutoDetect).To(Equal(true)) 187 }) 188 189 By("setting FileSystemPath", func() { 190 Expect(peerConfig.FileSystemPath).To(Equal("/var/hyperledger/production")) 191 }) 192 193 By("setting MspConfigPath", func() { 194 Expect(peerConfig.MspConfigPath).To(Equal("msp")) 195 }) 196 197 By("setting LocalMspId", func() { 198 Expect(peerConfig.LocalMspId).To(Equal("SampleOrg")) 199 }) 200 201 By("setting LocalMspType", func() { 202 Expect(peerConfig.LocalMspType).To(Equal("bccsp")) 203 }) 204 205 By("setting ValidatorPoolSize", func() { 206 Expect(peerConfig.ValidatorPoolSize).To(Equal(5)) 207 }) 208 // KeepAlive 209 210 By("setting Keepalive.MinInterval", func() { 211 d, err := common.ParseDuration("60s") 212 Expect(err).NotTo(HaveOccurred()) 213 Expect(peerConfig.Keepalive.MinInterval).To(Equal(d)) 214 }) 215 216 By("setting Keepalive.Client.Interval", func() { 217 d, err := common.ParseDuration("60s") 218 Expect(err).NotTo(HaveOccurred()) 219 Expect(peerConfig.Keepalive.Client.Interval).To(Equal(d)) 220 }) 221 222 By("setting Keepalive.Client.Timeout", func() { 223 d, err := common.ParseDuration("20s") 224 Expect(err).NotTo(HaveOccurred()) 225 Expect(peerConfig.Keepalive.Client.Timeout).To(Equal(d)) 226 }) 227 228 By("setting Keepalive.DeliveryClient.Interval", func() { 229 d, err := common.ParseDuration("60s") 230 Expect(err).NotTo(HaveOccurred()) 231 Expect(peerConfig.Keepalive.DeliveryClient.Interval).To(Equal(d)) 232 }) 233 234 By("setting Keepalive.DeliveryClient.Timeout", func() { 235 d, err := common.ParseDuration("20s") 236 Expect(err).NotTo(HaveOccurred()) 237 Expect(peerConfig.Keepalive.DeliveryClient.Timeout).To(Equal(d)) 238 }) 239 240 // Gossip 241 By("setting Gossip.Bootstrap", func() { 242 Expect(peerConfig.Gossip.Bootstrap).To(Equal([]string{"127.0.0.1:7051", "127.0.0.1:7052"})) 243 }) 244 245 By("setting Gossip.UseLeaderElection", func() { 246 Expect(*peerConfig.Gossip.UseLeaderElection).To(Equal(true)) 247 }) 248 249 By("setting Gossip.OrgLeader", func() { 250 Expect(*peerConfig.Gossip.OrgLeader).To(Equal(true)) 251 }) 252 253 By("setting Gossip.MembershipTrackerInterval", func() { 254 d, err := common.ParseDuration("5s") 255 Expect(err).NotTo(HaveOccurred()) 256 Expect(peerConfig.Gossip.MembershipTrackerInterval).To(Equal(d)) 257 }) 258 259 By("setting Gossip.Endpoint", func() { 260 Expect(peerConfig.Gossip.Endpoint).To(Equal("endpoint1")) 261 }) 262 263 By("setting Gossip.MaxBlockCountToStore", func() { 264 Expect(peerConfig.Gossip.MaxBlockCountToStore).To(Equal(10)) 265 }) 266 267 By("setting Gossip.MaxPropogationBurstLatency", func() { 268 d, err := common.ParseDuration("10ms") 269 Expect(err).NotTo(HaveOccurred()) 270 Expect(peerConfig.Gossip.MaxPropagationBurstLatency).To(Equal(d)) 271 }) 272 273 By("setting Gossip.MaxPropogationBurstSize", func() { 274 Expect(peerConfig.Gossip.MaxPropagationBurstSize).To(Equal(10)) 275 }) 276 277 By("setting Gossip.PropagateIterations", func() { 278 Expect(peerConfig.Gossip.PropagateIterations).To(Equal(1)) 279 }) 280 281 By("setting Gossip.PropagatePeerNum", func() { 282 Expect(peerConfig.Gossip.PropagatePeerNum).To(Equal(3)) 283 }) 284 285 By("setting Gossip.PullInterval", func() { 286 d, err := common.ParseDuration("4s") 287 Expect(err).NotTo(HaveOccurred()) 288 Expect(peerConfig.Gossip.PullInterval).To(Equal(d)) 289 }) 290 291 By("setting Gossip.PullPeerNum", func() { 292 Expect(peerConfig.Gossip.PullPeerNum).To(Equal(3)) 293 }) 294 295 By("setting Gossip.RequestStateInfoInterval", func() { 296 d, err := common.ParseDuration("4s") 297 Expect(err).NotTo(HaveOccurred()) 298 Expect(peerConfig.Gossip.RequestStateInfoInterval).To(Equal(d)) 299 }) 300 301 By("setting Gossip.PublishStateInfoInterval", func() { 302 d, err := common.ParseDuration("4s") 303 Expect(err).NotTo(HaveOccurred()) 304 Expect(peerConfig.Gossip.PublishStateInfoInterval).To(Equal(d)) 305 }) 306 307 By("setting Gossip.StateInfoRetentionInterval", func() { 308 d, err := common.ParseDuration("2s") 309 Expect(err).NotTo(HaveOccurred()) 310 Expect(peerConfig.Gossip.StateInfoRetentionInterval).To(Equal(d)) 311 }) 312 313 By("setting Gossip.PublishCertPeriod", func() { 314 d, err := common.ParseDuration("10s") 315 Expect(err).NotTo(HaveOccurred()) 316 Expect(peerConfig.Gossip.PublishCertPeriod).To(Equal(d)) 317 }) 318 319 By("setting Gossip.SkipBlockVerification", func() { 320 Expect(*peerConfig.Gossip.SkipBlockVerification).To(Equal(true)) 321 }) 322 323 By("setting Gossip.DialTimeout", func() { 324 d, err := common.ParseDuration("3s") 325 Expect(err).NotTo(HaveOccurred()) 326 Expect(peerConfig.Gossip.DialTimeout).To(Equal(d)) 327 }) 328 329 By("setting Gossip.ConnTimeout", func() { 330 d, err := common.ParseDuration("2s") 331 Expect(err).NotTo(HaveOccurred()) 332 Expect(peerConfig.Gossip.ConnTimeout).To(Equal(d)) 333 }) 334 335 By("setting Gossip.RecvBuffSize", func() { 336 Expect(peerConfig.Gossip.RecvBuffSize).To(Equal(20)) 337 }) 338 339 By("setting Gossip.SendBuffSize", func() { 340 Expect(peerConfig.Gossip.SendBuffSize).To(Equal(200)) 341 }) 342 343 By("setting Gossip.DigestWaitTime", func() { 344 d, err := common.ParseDuration("1s") 345 Expect(err).NotTo(HaveOccurred()) 346 Expect(peerConfig.Gossip.DigestWaitTime).To(Equal(d)) 347 }) 348 349 By("setting Gossip.RequestWaitTime", func() { 350 d, err := common.ParseDuration("1500ms") 351 Expect(err).NotTo(HaveOccurred()) 352 Expect(peerConfig.Gossip.RequestWaitTime).To(Equal(d)) 353 }) 354 355 By("setting Gossip.ResponseWaitTime", func() { 356 d, err := common.ParseDuration("2s") 357 Expect(err).NotTo(HaveOccurred()) 358 Expect(peerConfig.Gossip.ResponseWaitTime).To(Equal(d)) 359 }) 360 361 By("setting Gossip.AliveTimeInterval", func() { 362 d, err := common.ParseDuration("5s") 363 Expect(err).NotTo(HaveOccurred()) 364 Expect(peerConfig.Gossip.AliveTimeInterval).To(Equal(d)) 365 }) 366 367 By("setting Gossip.AliveExpirationTimeout", func() { 368 d, err := common.ParseDuration("25s") 369 Expect(err).NotTo(HaveOccurred()) 370 Expect(peerConfig.Gossip.AliveExpirationTimeout).To(Equal(d)) 371 }) 372 373 By("setting Gossip.ReconnectInterval", func() { 374 d, err := common.ParseDuration("25s") 375 Expect(err).NotTo(HaveOccurred()) 376 Expect(peerConfig.Gossip.ReconnectInterval).To(Equal(d)) 377 }) 378 379 By("setting Gossip.ExternalEndpoint", func() { 380 Expect(peerConfig.Gossip.ExternalEndpoint).To(Equal("externalEndpoint1")) 381 }) 382 383 // BCCSP 384 By("setting BCCSP.ProviderName", func() { 385 Expect(peerConfig.BCCSP.ProviderName).To(Equal("SW")) 386 }) 387 388 By("setting BCCSP.SW.HashFamily", func() { 389 Expect(peerConfig.BCCSP.SW.HashFamily).To(Equal("SHA2")) 390 }) 391 392 By("setting BCCSP.SW.SecLevel", func() { 393 Expect(peerConfig.BCCSP.SW.SecLevel).To(Equal(256)) 394 }) 395 396 By("setting BCCSP.SW.FileKeystore.KeystorePath", func() { 397 Expect(peerConfig.BCCSP.SW.FileKeyStore.KeyStorePath).To(Equal("keystore1")) 398 }) 399 400 By("setting BCCSP.PKCS11.Library", func() { 401 Expect(peerConfig.BCCSP.PKCS11.Library).To(Equal("library1")) 402 }) 403 404 By("setting BCCSP.PKCS11.Label", func() { 405 Expect(peerConfig.BCCSP.PKCS11.Label).To(Equal("label1")) 406 }) 407 408 By("setting BCCSP.PKCS11.Pin", func() { 409 Expect(peerConfig.BCCSP.PKCS11.Pin).To(Equal("1234")) 410 }) 411 412 By("setting BCCSP.PKCS11.HashFamily", func() { 413 Expect(peerConfig.BCCSP.PKCS11.HashFamily).To(Equal("SHA2")) 414 }) 415 416 By("setting BCCSP.PKCS11.Security", func() { 417 Expect(peerConfig.BCCSP.PKCS11.SecLevel).To(Equal(256)) 418 }) 419 420 By("setting BCCSP.PKCS11.FileKeystore.KeystorePath", func() { 421 Expect(peerConfig.BCCSP.PKCS11.FileKeyStore.KeyStorePath).To(Equal("keystore2")) 422 }) 423 424 // Discovery 425 By("setting Discovery.Enabled", func() { 426 Expect(*peerConfig.Discovery.Enabled).To(Equal(true)) 427 }) 428 429 By("setting Discovery.AuthCacheEnabled", func() { 430 Expect(*peerConfig.Discovery.AuthCacheEnabled).To(Equal(true)) 431 }) 432 433 By("setting Discovery.AuthCacheMaxSize", func() { 434 Expect(peerConfig.Discovery.AuthCacheMaxSize).To(Equal(1000)) 435 }) 436 437 By("setting Discovery.AuthCachePurgeRetentionRatio", func() { 438 Expect(peerConfig.Discovery.AuthCachePurgeRetentionRatio).To(Equal(0.75)) 439 }) 440 441 By("setting Discovery.OrgMembersAllowedAccess", func() { 442 Expect(*peerConfig.Discovery.OrgMembersAllowedAccess).To(Equal(true)) 443 }) 444 445 By("setting Limits.Concurrency.Qscc", func() { 446 Expect(peerConfig.Limits.Concurrency.Qscc).To(Equal(5000)) 447 }) 448 449 // Handlers 450 By("setting Handlers.AuthFilters", func() { 451 Expect(peerConfig.Handlers.AuthFilters).To(Equal([]v1.HandlerConfig{ 452 v1.HandlerConfig{ 453 Name: "DefaultAuth", 454 }, 455 v1.HandlerConfig{ 456 Name: "ExpirationCheck", 457 }, 458 })) 459 }) 460 461 By("setting Handlers.Decorators", func() { 462 Expect(peerConfig.Handlers.Decorators).To(Equal([]v1.HandlerConfig{ 463 v1.HandlerConfig{ 464 Name: "DefaultDecorator", 465 }, 466 })) 467 }) 468 469 By("setting Handlers.Endorsers", func() { 470 Expect(peerConfig.Handlers.Endorsers).To(Equal(v1.PluginMapping{ 471 "escc": v1.HandlerConfig{ 472 Name: "DefaultEndorsement", 473 }, 474 })) 475 }) 476 477 By("setting Handlers.Validators", func() { 478 Expect(peerConfig.Handlers.Validators).To(Equal(v1.PluginMapping{ 479 "vscc": v1.HandlerConfig{ 480 Name: "DefaultValidation", 481 }, 482 })) 483 }) 484 }) 485 486 Context("chaincode configuration", func() { 487 It("reads in core.yaml and unmarshal it to chaincode config", func() { 488 core, err := config.ReadCoreFile("../../../../../testdata/init/peer/core.yaml") 489 Expect(err).NotTo(HaveOccurred()) 490 491 chaincode := core.Chaincode 492 By("setting Chaincode.StartupTimeout", func() { 493 d, err := common.ParseDuration("300s") 494 Expect(err).NotTo(HaveOccurred()) 495 Expect(chaincode.StartupTimeout).To(Equal(d)) 496 }) 497 498 By("setting Chaincode.ExecuteTimeout", func() { 499 d, err := common.ParseDuration("30s") 500 Expect(err).NotTo(HaveOccurred()) 501 Expect(chaincode.ExecuteTimeout).To(Equal(d)) 502 }) 503 }) 504 505 It("merges current configuration with overrides values", func() { 506 core, err := config.ReadCoreFile("../../../../../testdata/init/peer/core.yaml") 507 Expect(err).NotTo(HaveOccurred()) 508 Expect(core.Peer.ID).To(Equal("jdoe")) 509 510 startupTimeout, err := common.ParseDuration("200s") 511 Expect(err).NotTo(HaveOccurred()) 512 executeTimeout, err := common.ParseDuration("20s") 513 Expect(err).NotTo(HaveOccurred()) 514 515 newConfig := &config.Core{ 516 Core: v1.Core{ 517 Chaincode: v1.Chaincode{ 518 StartupTimeout: startupTimeout, 519 ExecuteTimeout: executeTimeout, 520 }, 521 }, 522 } 523 524 err = core.MergeWith(newConfig, false) 525 Expect(err).NotTo(HaveOccurred()) 526 Expect(core.Chaincode.StartupTimeout).To(Equal(startupTimeout)) 527 Expect(core.Chaincode.ExecuteTimeout).To(Equal(executeTimeout)) 528 }) 529 }) 530 531 Context("DeliveryClient.AddressOverrides", func() { 532 It("merges current configuration with overrides values", func() { 533 core, err := config.ReadCoreFile("../../../../../testdata/init/peer/core.yaml") 534 Expect(err).NotTo(HaveOccurred()) 535 Expect(core.Peer.ID).To(Equal("jdoe")) 536 537 addressOverrides := []v1.AddressOverride{ 538 v1.AddressOverride{ 539 From: "address_old", 540 To: "address_new", 541 CACertsFile: certB64, 542 }, 543 } 544 545 newConfig := &config.Core{ 546 Core: v1.Core{ 547 Peer: v1.Peer{ 548 DeliveryClient: v1.DeliveryClient{ 549 AddressOverrides: addressOverrides, 550 }, 551 }, 552 }, 553 } 554 555 err = core.MergeWith(newConfig, false) 556 Expect(err).NotTo(HaveOccurred()) 557 558 Expect(core.Peer.DeliveryClient.AddressOverrides[0].From).To(Equal(addressOverrides[0].From)) 559 Expect(core.Peer.DeliveryClient.AddressOverrides[0].To).To(Equal(addressOverrides[0].To)) 560 Expect(core.Peer.DeliveryClient.AddressOverrides[0].CACertsFile).To(Equal("/orderer/certs/cert0.pem")) 561 Expect(len(core.GetAddressOverrides()[0].GetCertBytes())).NotTo(Equal(0)) 562 }) 563 }) 564 565 Context("operations configuration", func() { 566 It("merges current configuration with overrides values", func() { 567 core, err := config.ReadCoreFile("../../../../../testdata/init/peer/core.yaml") 568 Expect(err).NotTo(HaveOccurred()) 569 570 Expect(core.Operations.ListenAddress).To(Equal("127.0.0.1:9443")) 571 Expect(*core.Operations.TLS.Enabled).To(Equal(false)) 572 Expect(core.Operations.TLS.Certificate.File).To(Equal("cert.pem")) 573 Expect(core.Operations.TLS.PrivateKey.File).To(Equal("key.pem")) 574 Expect(*core.Operations.TLS.ClientAuthRequired).To(Equal(false)) 575 Expect(core.Operations.TLS.ClientRootCAs.Files).To(Equal([]string{"rootcert.pem"})) 576 577 newConfig := &config.Core{ 578 Core: v1.Core{ 579 Operations: v1.Operations{ 580 ListenAddress: "localhost:8080", 581 TLS: v1.OperationsTLS{ 582 Enabled: pointer.True(), 583 Certificate: v1.File{ 584 File: "newcert.pem", 585 }, 586 PrivateKey: v1.File{ 587 File: "newkey.pem", 588 }, 589 ClientAuthRequired: pointer.True(), 590 ClientRootCAs: v1.Files{ 591 Files: []string{"newrootcert.pem", "newrootcert2.pem"}, 592 }, 593 }, 594 }, 595 }, 596 } 597 598 err = core.MergeWith(newConfig, false) 599 Expect(err).NotTo(HaveOccurred()) 600 Expect(core.Operations.ListenAddress).To(Equal("localhost:8080")) 601 Expect(*core.Operations.TLS.Enabled).To(Equal(true)) 602 Expect(core.Operations.TLS.Certificate.File).To(Equal("newcert.pem")) 603 Expect(core.Operations.TLS.PrivateKey.File).To(Equal("newkey.pem")) 604 Expect(*core.Operations.TLS.ClientAuthRequired).To(Equal(true)) 605 Expect(core.Operations.TLS.ClientRootCAs.Files).To(Equal([]string{"newrootcert.pem", "newrootcert2.pem"})) 606 }) 607 }) 608 609 Context("metrics configuration", func() { 610 It("merges current configuration with overrides values", func() { 611 core, err := config.ReadCoreFile("../../../../../testdata/init/peer/core.yaml") 612 Expect(err).NotTo(HaveOccurred()) 613 614 Expect(core.Metrics.Provider).To(Equal("prometheus")) 615 Expect(core.Metrics.Statsd.Network).To(Equal("udp")) 616 Expect(core.Metrics.Statsd.Address).To(Equal("127.0.0.1:8125")) 617 Expect(core.Metrics.Statsd.Prefix).To(Equal("")) 618 619 writeInterval, err := common.ParseDuration("10s") 620 Expect(err).NotTo(HaveOccurred()) 621 Expect(core.Metrics.Statsd.WriteInterval).To(Equal(writeInterval)) 622 623 newWriteInterval, err := common.ParseDuration("15s") 624 Expect(err).NotTo(HaveOccurred()) 625 newConfig := &config.Core{ 626 Core: v1.Core{ 627 Metrics: v1.Metrics{ 628 Provider: "statsd", 629 Statsd: v1.Statsd{ 630 Network: "tcp", 631 Address: "localhost:8080", 632 WriteInterval: newWriteInterval, 633 Prefix: "prefix", 634 }, 635 }, 636 }, 637 } 638 639 err = core.MergeWith(newConfig, false) 640 Expect(err).NotTo(HaveOccurred()) 641 642 Expect(core.Metrics.Provider).To(Equal("statsd")) 643 Expect(core.Metrics.Statsd.Network).To(Equal("tcp")) 644 Expect(core.Metrics.Statsd.Address).To(Equal("localhost:8080")) 645 Expect(core.Metrics.Statsd.Prefix).To(Equal("prefix")) 646 Expect(core.Metrics.Statsd.WriteInterval).To(Equal(newWriteInterval)) 647 }) 648 }) 649 650 Context("updating peer.gossip.bootstrap if needed", func() { 651 It("reads core and converts peer.gossip.bootstrap", func() { 652 core, err := config.ReadCoreFile("../../../../../testdata/init/peer/core_bootstrap_test.yaml") 653 Expect(err).NotTo(HaveOccurred()) 654 Expect(core.Peer.Gossip.Bootstrap).To(Equal([]string{"127.0.0.1:7051"})) 655 }) 656 657 It("returns error if invalid core (besides peer.gossip.boostrap field)", func() { 658 _, err := config.ReadCoreFile("../../../../../testdata/init/peer/core_invalid.yaml") 659 Expect(err).NotTo(HaveOccurred()) 660 }) 661 }) 662 })