2 * ============LICENSE_START=======================================================
3 * oom-certservice-k8s-external-provider
4 * ================================================================================
5 * Copyright (C) 2021 Nokia. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
27 cmapi "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1"
28 "github.com/stretchr/testify/assert"
29 "sigs.k8s.io/controller-runtime/pkg/client/fake"
31 "onap.org/oom-certservice/k8s-external-provider/src/testdata"
35 revisionAnnotation = "cert-manager.io/certificate-revision"
36 certificateConfigurationAnnotation = "kubectl.kubernetes.io/last-applied-configuration"
37 testPrivateKeyData = "test-private-key"
38 testCertificateData = "test-certificate"
41 func Test_shouldCreateCertificateModelWithCorrectParameters(t *testing.T) {
42 request := new(cmapi.CertificateRequest)
43 request.ObjectMeta.Annotations = map[string]string{
44 revisionAnnotation: "2",
45 certificateConfigurationAnnotation: testdata.OldCertificateConfig,
47 request.Spec.Request = testdata.CsrBytes
48 fakeClient := fake.NewFakeClientWithScheme(testdata.GetScheme(), testdata.GetValidCertificateSecret())
50 signCertModel, err := CreateSignCertificateModel(fakeClient, request, *new(context.Context), testdata.PkBytes)
53 assert.NotNil(t, signCertModel)
54 assert.NotNil(t, signCertModel.FilteredCsr)
55 assert.Equal(t, testdata.PkBytes, signCertModel.PrivateKeyBytes)
56 assert.Equal(t, request, signCertModel.CertificateRequest)
57 assert.Equal(t, []byte(testCertificateData), signCertModel.OldCertificateBytes)
58 assert.Equal(t, []byte(testPrivateKeyData), signCertModel.OldPrivateKeyBytes)