github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/initializer/ca/config/intermediate_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 config_test
    20  
    21  import (
    22  	"os"
    23  	"path/filepath"
    24  
    25  	v1 "github.com/IBM-Blockchain/fabric-operator/pkg/apis/ca/v1"
    26  	"github.com/IBM-Blockchain/fabric-operator/pkg/initializer/ca/config"
    27  	"github.com/IBM-Blockchain/fabric-operator/pkg/util/pointer"
    28  	. "github.com/onsi/ginkgo/v2"
    29  	. "github.com/onsi/gomega"
    30  )
    31  
    32  var _ = Describe("Intermediate config", func() {
    33  	var (
    34  		cfg     *config.Config
    35  		homeDir = "interconfigtest"
    36  	)
    37  
    38  	BeforeEach(func() {
    39  		os.Mkdir(homeDir, 0777)
    40  	})
    41  
    42  	AfterEach(func() {
    43  		err := os.RemoveAll(homeDir)
    44  		Expect(err).NotTo(HaveOccurred())
    45  	})
    46  
    47  	Context("parses intermediate configuration", func() {
    48  		BeforeEach(func() {
    49  			cfg = &config.Config{
    50  				ServerConfig: &v1.ServerConfig{
    51  					CAConfig: v1.CAConfig{
    52  						Intermediate: v1.IntermediateCA{
    53  							TLS: v1.ClientTLSConfig{
    54  								Enabled:   pointer.True(),
    55  								CertFiles: []string{certFile},
    56  								Client: v1.KeyCertFiles{
    57  									CertFile: certFile,
    58  									KeyFile:  keyFile,
    59  								},
    60  							},
    61  						},
    62  					},
    63  				},
    64  				HomeDir: homeDir,
    65  			}
    66  		})
    67  
    68  		It("parses config and returns a map containing all crypto and updated paths to crypto material", func() {
    69  			crypto, err := cfg.ParseIntermediateBlock()
    70  			Expect(err).NotTo(HaveOccurred())
    71  
    72  			certData, certKeyExists := crypto["parent-cert.pem"]
    73  			Expect(certKeyExists).To(Equal(true))
    74  			Expect(certData).NotTo(BeNil())
    75  			Expect(cfg.ServerConfig.CAConfig.Intermediate.TLS.Client.CertFile).To(Equal(filepath.Join(cfg.HomeDir, "parent-cert.pem")))
    76  
    77  			keyData, keyKeyExists := crypto["parent-key.pem"]
    78  			Expect(keyKeyExists).To(Equal(true))
    79  			Expect(keyData).NotTo(BeNil())
    80  			Expect(cfg.ServerConfig.CAConfig.Intermediate.TLS.Client.KeyFile).To(Equal(filepath.Join(cfg.HomeDir, "parent-key.pem")))
    81  
    82  			chainData, chainKeyExists := crypto["parent-certfile0.pem"]
    83  			Expect(chainKeyExists).To(Equal(true))
    84  			Expect(chainData).NotTo(BeNil())
    85  			Expect(cfg.ServerConfig.CAConfig.Intermediate.TLS.CertFiles[0]).To(Equal(filepath.Join(cfg.HomeDir, "parent-certfile0.pem")))
    86  		})
    87  	})
    88  })