def _process_non_approved_profile_request(self, order_meta, plugin_meta, profile_id, inputs=None): if inputs is None: inputs = { 'cert_request_type': 'pkcs10', 'cert_request': base64.b64decode( order_meta.get('request_data')) } # mock CertRequestInfo enrollment_result = dogtag_cert.CertRequestInfo() enrollment_result.request_id = self.request_id_mock enrollment_result.request_status = ( dogtag_cert.CertRequestStatus.PENDING) # mock CertRequestInfoCollection enrollment_results = dogtag_cert.CertRequestInfoCollection() enrollment_results.cert_request_info_list = ( [enrollment_result]) self.certclient_mock.create_enrollment_request.return_value = ( enrollment_result) self.certclient_mock.submit_enrollment_request.return_value = ( enrollment_results) result_dto = self.plugin.issue_certificate_request( self.order_id, order_meta, plugin_meta, self.barbican_meta_dto) self.certclient_mock.create_enrollment_request.assert_called_once_with( profile_id, inputs) self.certclient_mock.submit_enrollment_request.assert_called_once_with( enrollment_result) self.assertEqual(cm.CertificateStatus.WAITING_FOR_CA, result_dto.status, "result_dto status incorrect") self.assertEqual( self.request_id_mock, plugin_meta.get(dogtag_import.DogtagCAPlugin.REQUEST_ID) )
def setUp(self): super(WhenTestingDogtagCAPlugin, self).setUp() self.certclient_mock = mock.MagicMock(name="CertClient mock") self.patcher = mock.patch('pki.crypto.NSSCryptoProvider') self.patcher2 = mock.patch('pki.client.PKIConnection') self.patcher.start() self.patcher2.start() # create nss db for test only self.nss_dir = tempfile.mkdtemp() # create expiration file for test fh, self.expiration_data_path = tempfile.mkstemp() exp_time = datetime.datetime.utcnow() + datetime.timedelta(days=2) os.write(fh, exp_time.strftime( "%Y-%m-%d %H:%M:%S.%f")) os.close(fh) # create host CA file for test fh, self.host_ca_path = tempfile.mkstemp() os.write(fh, "host_ca_aid") os.close(fh) self.approved_profile_id = "caServerCert" CONF = dogtag_import.CONF CONF.dogtag_plugin.nss_db_path = self.nss_dir CONF.dogtag_plugin.ca_expiration_data_path = self.expiration_data_path CONF.dogtag_plugin.ca_host_aid_path = self.host_ca_path CONF.dogtag_plugin.auto_approved_profiles = [self.approved_profile_id] CONF.dogtag_plugin.dogtag_host = "localhost" CONF.dogtag_plugin.dogtag_port = 8443 CONF.dogtag_plugin.simple_cmc_profile = "caOtherCert" self.cfg = CONF self.plugin = dogtag_import.DogtagCAPlugin(CONF) self.plugin.certclient = self.certclient_mock self.order_id = mock.MagicMock() self.profile_id = mock.MagicMock() # request generated self.request_id_mock = mock.MagicMock() self.request = dogtag_cert.CertRequestInfo() self.request.request_id = self.request_id_mock self.request.request_status = dogtag_cert.CertRequestStatus.COMPLETE self.cert_id_mock = mock.MagicMock() self.request.cert_id = self.cert_id_mock # cert generated self.cert = mock.MagicMock() self.cert.encoded = keys.get_certificate_pem() self.cert.pkcs7_cert_chain = keys.get_certificate_der() # for cancel/modify self.review_response = mock.MagicMock() # modified request self.modified_request = mock.MagicMock() self.modified_request_id_mock = mock.MagicMock() self.modified_request.request_id = self.modified_request_id_mock self.modified_request.request_status = ( dogtag_cert.CertRequestStatus.COMPLETE) self.modified_request.cert_id = self.cert_id_mock self.barbican_meta_dto = cm.BarbicanMetaDTO()