Replace '\r\n' with '\n' in cert pem before looks for existing ones
Since the NSX fix the certificate pem when creating it, we should do the same when comparing a new one to existing ones. Change-Id: I7da39447869c7ec2a99820676b6fb75b0a098acf
This commit is contained in:
parent
0d263ec65e
commit
f54812edf9
@ -41,3 +41,26 @@ class TestNsxLibTrustManagement(nsxlib_testcase.NsxClientTestCase):
|
|||||||
create.assert_called_with(
|
create.assert_called_with(
|
||||||
'trust-management/certificates?action=import',
|
'trust-management/certificates?action=import',
|
||||||
body)
|
body)
|
||||||
|
|
||||||
|
def test_find_cert_with_pem_empty(self):
|
||||||
|
pem = 'abc'
|
||||||
|
with mock.patch.object(self.nsxlib.client, 'get',
|
||||||
|
return_value={'results': []}):
|
||||||
|
results = self.nsxlib.trust_management.find_cert_with_pem(pem)
|
||||||
|
self.assertEqual(0, len(results))
|
||||||
|
|
||||||
|
def test_find_cert_with_pem_found(self):
|
||||||
|
pem = consts.FAKE_CERT_PEM
|
||||||
|
with mock.patch.object(
|
||||||
|
self.nsxlib.client, 'get',
|
||||||
|
return_value={'results': consts.FAKE_CERT_LIST}):
|
||||||
|
results = self.nsxlib.trust_management.find_cert_with_pem(pem)
|
||||||
|
self.assertEqual(1, len(results))
|
||||||
|
|
||||||
|
def test_find_cert_with_pem_rn_found(self):
|
||||||
|
pem = consts.FAKE_CERT_PEM.replace('\n', '\r\n')
|
||||||
|
with mock.patch.object(
|
||||||
|
self.nsxlib.client, 'get',
|
||||||
|
return_value={'results': consts.FAKE_CERT_LIST}):
|
||||||
|
results = self.nsxlib.trust_management.find_cert_with_pem(pem)
|
||||||
|
self.assertEqual(1, len(results))
|
||||||
|
@ -4587,10 +4587,12 @@ class NsxPolicyCertApi(NsxPolicyResourceBase):
|
|||||||
|
|
||||||
def find_cert_with_pem(self, cert_pem,
|
def find_cert_with_pem(self, cert_pem,
|
||||||
tenant=constants.POLICY_INFRA_TENANT):
|
tenant=constants.POLICY_INFRA_TENANT):
|
||||||
# Find certificate with cert_pem
|
"""Find NSX certificates with specific pem and return their IDs"""
|
||||||
|
# First fix Dos to unix possible issues, as the NSX backed also does
|
||||||
|
nsx_style_pem = cert_pem.replace('\r\n', '\n')
|
||||||
certs = self.list(tenant=tenant)
|
certs = self.list(tenant=tenant)
|
||||||
cert_ids = [cert['id'] for cert in certs
|
cert_ids = [cert['id'] for cert in certs
|
||||||
if cert['pem_encoded'] == cert_pem]
|
if cert['pem_encoded'] == nsx_style_pem]
|
||||||
return cert_ids
|
return cert_ids
|
||||||
|
|
||||||
def update(self, certificate_id, name=IGNORE,
|
def update(self, certificate_id, name=IGNORE,
|
||||||
|
@ -66,10 +66,12 @@ class NsxLibTrustManagement(utils.NsxLibApiBase):
|
|||||||
self._delete_by_path_with_retry(resource)
|
self._delete_by_path_with_retry(resource)
|
||||||
|
|
||||||
def find_cert_with_pem(self, cert_pem):
|
def find_cert_with_pem(self, cert_pem):
|
||||||
# Find certificate with cert_pem
|
"""Find NSX certificates with specific pem and return their IDs"""
|
||||||
|
# First fix Dos to unix possible issues, as the NSX backed also does
|
||||||
|
nsx_style_pem = cert_pem.replace('\r\n', '\n')
|
||||||
certs = self.get_certs()
|
certs = self.get_certs()
|
||||||
cert_ids = [cert['id'] for cert in certs
|
cert_ids = [cert['id'] for cert in certs
|
||||||
if cert['pem_encoded'] == cert_pem]
|
if cert['pem_encoded'] == nsx_style_pem]
|
||||||
return cert_ids
|
return cert_ids
|
||||||
|
|
||||||
def create_identity(self, name, cert_id,
|
def create_identity(self, name, cert_id,
|
||||||
|
Loading…
Reference in New Issue
Block a user