2 * ============LICENSE_START=======================================================
3 * oom-certservice-k8s-external-provider
4 * ================================================================================
5 * Copyright (C) 2020 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 certEndpointInvalid = ":/v1/certificate"
40 caNameInvalid = ":/RA"
41 expectedCertificationUrl = "https://oom-cert-service:8443/v1/certificate/RA"
42 expectedHealthCheckUrl = "https://oom-cert-service:8443/actuator/health"
45 func Test_shouldCreateCertServiceClient(t *testing.T) {
46 shouldCreateCertServiceClientWithExpectedUrl(t, validUrl)
47 shouldCreateCertServiceClientWithExpectedUrl(t, validUrl2)
50 func shouldCreateCertServiceClientWithExpectedUrl(t *testing.T, baseUrl string) {
51 client, err := CreateCertServiceClient(baseUrl, healthEndpoint, certEndpoint, caName, testdata.KeyBytes, testdata.CertBytes, testdata.CacertBytes)
53 assert.NotNil(t, client)
55 assert.Equal(t, expectedCertificationUrl, client.certificationUrl)
56 assert.Equal(t, expectedHealthCheckUrl, client.healthUrl)
59 func Test_shouldReturnError_whenCaNameInvalid(t *testing.T) {
60 client, err := CreateCertServiceClient(validUrl, healthEndpoint, certEndpoint, caNameInvalid, testdata.KeyBytes, testdata.CertBytes, testdata.CacertBytes)
66 func Test_shouldReturnError_whenHealthEndpointInvalid(t *testing.T) {
67 client, err := CreateCertServiceClient(validUrl, healthEndpointInvalid, certEndpoint, caName, testdata.KeyBytes, testdata.CertBytes, testdata.CacertBytes)
73 func Test_shouldReturnError_whenCertEndpointInvalid(t *testing.T) {
74 client, err := CreateCertServiceClient(validUrl, healthEndpoint, certEndpointInvalid, caName, testdata.KeyBytes, testdata.CertBytes, testdata.CacertBytes)
80 func Test_shouldReturnError_whenUrlInvalid(t *testing.T) {
81 client, err := CreateCertServiceClient(invalidUrl, healthEndpoint, certEndpoint, caName, testdata.KeyBytes, testdata.CertBytes, testdata.CacertBytes)
87 func Test_shouldReturnError_whenCanameEmpty(t *testing.T) {
88 client, err := CreateCertServiceClient(validUrl, healthEndpoint, certEndpoint, "", testdata.KeyBytes, testdata.CertBytes, testdata.CacertBytes)
94 func Test_shouldReturnError_whenKeyNotMatchingCert(t *testing.T) {
95 client, err := CreateCertServiceClient(validUrl, healthEndpoint, certEndpoint, caName, testdata.NotMatchingKeyBytes, testdata.CertBytes, testdata.CacertBytes)
101 func Test_shouldReturnError_whenKeyInvalid(t *testing.T) {
103 client, err := CreateCertServiceClient(validUrl, healthEndpoint, certEndpoint, caName, testdata.CertBytes, testdata.CertBytes, testdata.CacertBytes)
105 assert.Nil(t, client)
109 func Test_shouldReturnError_whenCertInvalid(t *testing.T) {
110 //Cacert used as cert
111 client, err := CreateCertServiceClient(validUrl, healthEndpoint, certEndpoint, caName, testdata.KeyBytes, testdata.CacertBytes, testdata.CacertBytes)
113 assert.Nil(t, client)
117 func Test_shouldReturnError_whenCacertInvalid(t *testing.T) {
119 client, err := CreateCertServiceClient(validUrl, healthEndpoint, certEndpoint, caName, testdata.KeyBytes, testdata.CertBytes, testdata.KeyBytes)
121 assert.Nil(t, client)