...

Source file src/k8s.io/kubernetes/cmd/kubeadm/app/phases/certs/renewal/filerenewer_test.go

Documentation: k8s.io/kubernetes/cmd/kubeadm/app/phases/certs/renewal

     1  /*
     2  Copyright 2018 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package renewal
    18  
    19  import (
    20  	"crypto/x509"
    21  	"testing"
    22  
    23  	certutil "k8s.io/client-go/util/cert"
    24  
    25  	"k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil"
    26  )
    27  
    28  func TestFileRenewer(t *testing.T) {
    29  	// creates a File renewer using a test Certificate authority
    30  	fr := NewFileRenewer(testCACert, testCAKey)
    31  
    32  	// renews a certificate
    33  	certCfg := &pkiutil.CertConfig{
    34  		Config: certutil.Config{
    35  			CommonName: "test-certs",
    36  			AltNames: certutil.AltNames{
    37  				DNSNames: []string{"test-domain.space"},
    38  			},
    39  			Usages: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth},
    40  		},
    41  	}
    42  
    43  	cert, _, err := fr.Renew(certCfg)
    44  	if err != nil {
    45  		t.Fatalf("unexpected error renewing cert: %v", err)
    46  	}
    47  
    48  	// verify the renewed certificate
    49  	pool := x509.NewCertPool()
    50  	pool.AddCert(testCACert)
    51  
    52  	_, err = cert.Verify(x509.VerifyOptions{
    53  		DNSName:   "test-domain.space",
    54  		Roots:     pool,
    55  		KeyUsages: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth},
    56  	})
    57  	if err != nil {
    58  		t.Errorf("couldn't verify new cert: %v", err)
    59  	}
    60  
    61  }
    62  

View as plain text