2 * ============LICENSE_START=======================================================
3 * oom-certservice-k8s-external-provider
4 * ================================================================================
5 * Copyright (C) 2020-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=========================================================
21 package certserviceclient
26 "github.com/stretchr/testify/assert"
28 "onap.org/oom-certservice/k8s-external-provider/src/testdata"
32 validUrl = "https://oom-cert-service:8443/"
33 validUrl2 = "https://oom-cert-service:8443"
34 invalidUrl = "https://oom-cert service:8443/"
35 healthEndpoint = "actuator/health"
36 healthEndpointInvalid = ":/actuator/health"
37 certEndpoint = "v1/certificate"
38 updateEndpoint = "v1/certificate-update"
39 certEndpointInvalid = ":/v1/certificate"
40 certUpdateEndpointInvalid = ":/v1/certificate-update"
42 caNameInvalid = ":/RA"
43 expectedCertificationUrl = "https://oom-cert-service:8443/v1/certificate/RA"
44 expectedHealthCheckUrl = "https://oom-cert-service:8443/actuator/health"
47 func Test_shouldCreateCertServiceClient(t *testing.T) {
48 shouldCreateCertServiceClientWithExpectedUrl(t, validUrl)
49 shouldCreateCertServiceClientWithExpectedUrl(t, validUrl2)
52 func shouldCreateCertServiceClientWithExpectedUrl(t *testing.T, baseUrl string) {
53 client, err := CreateCertServiceClient(baseUrl, healthEndpoint, certEndpoint, updateEndpoint, caName, testdata.KeyBytes, testdata.CertBytes, testdata.CacertBytes)
55 assert.NotNil(t, client)
57 assert.Equal(t, expectedCertificationUrl, client.certificationUrl)
58 assert.Equal(t, expectedHealthCheckUrl, client.healthUrl)
61 func Test_shouldReturnError_whenCaNameInvalid(t *testing.T) {
62 client, err := CreateCertServiceClient(validUrl, healthEndpoint, certEndpoint, updateEndpoint, caNameInvalid, testdata.KeyBytes, testdata.CertBytes, testdata.CacertBytes)
68 func Test_shouldReturnError_whenHealthEndpointInvalid(t *testing.T) {
69 client, err := CreateCertServiceClient(validUrl, healthEndpointInvalid, certEndpoint, updateEndpoint, caName, testdata.KeyBytes, testdata.CertBytes, testdata.CacertBytes)
75 func Test_shouldReturnError_whenCertEndpointInvalid(t *testing.T) {
76 client, err := CreateCertServiceClient(validUrl, healthEndpoint, certEndpointInvalid, updateEndpoint, caName, testdata.KeyBytes, testdata.CertBytes, testdata.CacertBytes)
82 func Test_shouldReturnError_whenUpdateCertificateEndpointInvalid(t *testing.T) {
83 client, err := CreateCertServiceClient(validUrl, healthEndpoint, certEndpoint, certUpdateEndpointInvalid, caName, testdata.KeyBytes, testdata.CertBytes, testdata.KeyBytes)
89 func Test_shouldReturnError_whenUrlInvalid(t *testing.T) {
90 client, err := CreateCertServiceClient(invalidUrl, healthEndpoint, certEndpoint, updateEndpoint, caName, testdata.KeyBytes, testdata.CertBytes, testdata.CacertBytes)
96 func Test_shouldReturnError_whenCanameEmpty(t *testing.T) {
97 client, err := CreateCertServiceClient(validUrl, healthEndpoint, certEndpoint, updateEndpoint, "", testdata.KeyBytes, testdata.CertBytes, testdata.CacertBytes)
103 func Test_shouldReturnError_whenKeyNotMatchingCert(t *testing.T) {
104 client, err := CreateCertServiceClient(validUrl, healthEndpoint, certEndpoint, updateEndpoint, caName, testdata.NotMatchingKeyBytes, testdata.CertBytes, testdata.CacertBytes)
106 assert.Nil(t, client)
110 func Test_shouldReturnError_whenKeyInvalid(t *testing.T) {
112 client, err := CreateCertServiceClient(validUrl, healthEndpoint, certEndpoint, updateEndpoint, caName, testdata.CertBytes, testdata.CertBytes, testdata.CacertBytes)
114 assert.Nil(t, client)
118 func Test_shouldReturnError_whenCertInvalid(t *testing.T) {
119 //Cacert used as cert
120 client, err := CreateCertServiceClient(validUrl, healthEndpoint, certEndpoint, updateEndpoint, caName, testdata.KeyBytes, testdata.CacertBytes, testdata.CacertBytes)
122 assert.Nil(t, client)
126 func Test_shouldReturnError_whenCacertInvalid(t *testing.T) {
128 client, err := CreateCertServiceClient(validUrl, healthEndpoint, certEndpoint, updateEndpoint, caName, testdata.KeyBytes, testdata.CertBytes, testdata.KeyBytes)
130 assert.Nil(t, client)