Test case fix and logs added

Related to https://gitlab.com/entgra/product-iots/-/issues/1541
license
inoshperera 2 years ago
parent c0ac653ca6
commit 0fc27682df

@ -48,6 +48,8 @@ import org.jscep.message.*;
import org.jscep.transaction.FailInfo; import org.jscep.transaction.FailInfo;
import org.jscep.transaction.Nonce; import org.jscep.transaction.Nonce;
import org.jscep.transaction.TransactionId; import org.jscep.transaction.TransactionId;
import org.wso2.carbon.certificate.mgt.core.cache.CertificateCacheManager;
import org.wso2.carbon.certificate.mgt.core.cache.impl.CertificateCacheManagerImpl;
import org.wso2.carbon.certificate.mgt.core.dao.CertificateDAO; import org.wso2.carbon.certificate.mgt.core.dao.CertificateDAO;
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOException; import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOException;
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOFactory; import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOFactory;
@ -209,27 +211,35 @@ public class CertificateGenerator {
return certificate; return certificate;
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
String errorMsg = "No such algorithm found when generating certificate"; String errorMsg = "No such algorithm found when generating certificate";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (NoSuchProviderException e) { } catch (NoSuchProviderException e) {
String errorMsg = "No such provider found when generating certificate"; String errorMsg = "No such provider found when generating certificate";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (OperatorCreationException e) { } catch (OperatorCreationException e) {
String errorMsg = "Issue in operator creation when generating certificate"; String errorMsg = "Issue in operator creation when generating certificate";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (CertificateExpiredException e) { } catch (CertificateExpiredException e) {
String errorMsg = "Certificate expired after generating certificate"; String errorMsg = "Certificate expired after generating certificate";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (CertificateNotYetValidException e) { } catch (CertificateNotYetValidException e) {
String errorMsg = "Certificate not yet valid when generating certificate"; String errorMsg = "Certificate not yet valid when generating certificate";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (CertificateException e) { } catch (CertificateException e) {
String errorMsg = "Certificate issue occurred when generating certificate"; String errorMsg = "Certificate issue occurred when generating certificate";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (InvalidKeyException e) { } catch (InvalidKeyException e) {
String errorMsg = "Invalid key used when generating certificate"; String errorMsg = "Invalid key used when generating certificate";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (SignatureException e) { } catch (SignatureException e) {
String errorMsg = "Signature related issue occurred when generating certificate"; String errorMsg = "Signature related issue occurred when generating certificate";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} }
} }
@ -285,18 +295,23 @@ public class CertificateGenerator {
} catch (CertificateException e) { } catch (CertificateException e) {
String errorMsg = "Certificate issue occurred when generating getPKIMessage"; String errorMsg = "Certificate issue occurred when generating getPKIMessage";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (MessageEncodingException e) { } catch (MessageEncodingException e) {
String errorMsg = "Message encoding issue occurred when generating getPKIMessage"; String errorMsg = "Message encoding issue occurred when generating getPKIMessage";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (IOException e) { } catch (IOException e) {
String errorMsg = "Input output issue occurred when generating getPKIMessage"; String errorMsg = "Input output issue occurred when generating getPKIMessage";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (MessageDecodingException e) { } catch (MessageDecodingException e) {
String errorMsg = "Message decoding issue occurred when generating getPKIMessage"; String errorMsg = "Message decoding issue occurred when generating getPKIMessage";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (CMSException e) { } catch (CMSException e) {
String errorMsg = "CMS issue occurred when generating getPKIMessage"; String errorMsg = "CMS issue occurred when generating getPKIMessage";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} }
} }
@ -511,12 +526,15 @@ public class CertificateGenerator {
saveCertInKeyStore(certificates); saveCertInKeyStore(certificates);
} catch (CertIOException e) { } catch (CertIOException e) {
String errorMsg = "Certificate Input output issue occurred when generating generateCertificateFromCSR"; String errorMsg = "Certificate Input output issue occurred when generating generateCertificateFromCSR";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (OperatorCreationException e) { } catch (OperatorCreationException e) {
String errorMsg = "Operator creation issue occurred when generating generateCertificateFromCSR"; String errorMsg = "Operator creation issue occurred when generating generateCertificateFromCSR";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (CertificateException e) { } catch (CertificateException e) {
String errorMsg = "Certificate issue occurred when generating generateCertificateFromCSR"; String errorMsg = "Certificate issue occurred when generating generateCertificateFromCSR";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} }
@ -547,9 +565,11 @@ public class CertificateGenerator {
return generator.generate(new CMSAbsentContent()); return generator.generate(new CMSAbsentContent());
} catch (CertificateEncodingException e) { } catch (CertificateEncodingException e) {
String errorMsg = "Certificate encoding issue occurred when generating getMessageData"; String errorMsg = "Certificate encoding issue occurred when generating getMessageData";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (CMSException e) { } catch (CMSException e) {
String errorMsg = "Message decoding issue occurred when generating getMessageData"; String errorMsg = "Message decoding issue occurred when generating getMessageData";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} }
} }
@ -641,12 +661,15 @@ public class CertificateGenerator {
return scepResponse; return scepResponse;
} catch (CertificateEncodingException e) { } catch (CertificateEncodingException e) {
String errorMsg = "Certificate encoding issue occurred in getCACert"; String errorMsg = "Certificate encoding issue occurred in getCACert";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (CMSException e) { } catch (CMSException e) {
String errorMsg = "CMS issue occurred in getCACert"; String errorMsg = "CMS issue occurred in getCACert";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (IOException e) { } catch (IOException e) {
String errorMsg = "Input output issue occurred in getCACert"; String errorMsg = "Input output issue occurred in getCACert";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} }
} }
@ -665,10 +688,12 @@ public class CertificateGenerator {
CertificateManagementDAOFactory.commitTransaction(); CertificateManagementDAOFactory.commitTransaction();
} catch (CertificateManagementDAOException e) { } catch (CertificateManagementDAOException e) {
String errorMsg = "Error occurred when saving the generated certificate"; String errorMsg = "Error occurred when saving the generated certificate";
log.error(errorMsg);
CertificateManagementDAOFactory.rollbackTransaction(); CertificateManagementDAOFactory.rollbackTransaction();
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
String errorMsg = "Error occurred when saving the generated certificate"; String errorMsg = "Error occurred when saving the generated certificate";
log.error(errorMsg);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} }
} }

@ -312,8 +312,9 @@ public class CertificateManagementServiceImplTests extends BaseDeviceManagementC
} }
@Test(description = "This test case tests extracting Certificate from the header Signature") @Test(description = "This test case tests extracting Certificate from the header Signature")
public void testExtractCertificateFromSignature() throws KeystoreException, CertificateEncodingException, CMSException, IOException { public void testExtractCertificateFromSignature() throws KeystoreException, CertificateEncodingException, CMSException, IOException, DeviceManagementException {
BASE64Encoder encoder = new BASE64Encoder(); BASE64Encoder encoder = new BASE64Encoder();
DeviceConfigurationManager.getInstance().initConfig();
//generate and save a certificate in the keystore //generate and save a certificate in the keystore
X509Certificate x509Certificate = managementService.generateX509Certificate(); X509Certificate x509Certificate = managementService.generateX509Certificate();
//Generate CMSdata //Generate CMSdata

Loading…
Cancel
Save