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/v1/certificate/"
33 validUrl2 = "https://oom-cert-service:8443/v1/certificate"
34 invalidUrl = "https://oom-cert service:8443/v1/certificate"
36 expectedCertificationUrl = "https://oom-cert-service:8443/v1/certificate/RA"
39 func Test_shouldCreateCertServiceClient(t *testing.T) {
40 shouldCreateCertServiceClientWithExpectedUrl(t, expectedCertificationUrl, validUrl)
41 shouldCreateCertServiceClientWithExpectedUrl(t, expectedCertificationUrl, validUrl2)
44 func shouldCreateCertServiceClientWithExpectedUrl(t *testing.T, expectedCertificationUrl string, baseUrl string) {
45 client, err := CreateCertServiceClient(baseUrl, caName, testdata.KeyBytes, testdata.CertBytes, testdata.CacertBytes)
47 assert.NotNil(t, client)
49 assert.Equal(t, expectedCertificationUrl, client.certificationUrl)
52 func Test_shouldReturnError_whenUrlInvalid(t *testing.T) {
53 client, err := CreateCertServiceClient(invalidUrl, caName, testdata.KeyBytes, testdata.CertBytes, testdata.CacertBytes)
59 func Test_shouldReturnError_whenCanameEmpty(t *testing.T) {
60 client, err := CreateCertServiceClient(validUrl, "", testdata.KeyBytes, testdata.CertBytes, testdata.CacertBytes)
66 func Test_shouldReturnError_whenKeyNotMatchingCert(t *testing.T) {
67 client, err := CreateCertServiceClient(validUrl, caName, testdata.NotMatchingKeyBytes, testdata.CertBytes, testdata.CacertBytes)
73 func Test_shouldReturnError_whenKeyInvalid(t *testing.T) {
75 client, err := CreateCertServiceClient(validUrl, caName, testdata.CertBytes, testdata.CertBytes, testdata.CacertBytes)
81 func Test_shouldReturnError_whenCertInvalid(t *testing.T) {
83 client, err := CreateCertServiceClient(validUrl, caName, testdata.KeyBytes, testdata.CacertBytes, testdata.CacertBytes)
89 func Test_shouldReturnError_whenCacertInvalid(t *testing.T) {
91 client, err := CreateCertServiceClient(validUrl, caName, testdata.KeyBytes, testdata.CertBytes, testdata.KeyBytes)