Search in sources :

Example 1 with CertificateDaoImpl

use of org.nhindirect.config.store.dao.impl.CertificateDaoImpl in project nhin-d by DirectProject.

the class CertificateDaoImp_saveWithProtectionMgr method testStripP12ProtectionTest_NoP12ProtectionWithManager_assertP12Returned.

@Test
public void testStripP12ProtectionTest_NoP12ProtectionWithManager_assertP12Returned() throws Exception {
    final EntityManager manager = mock(EntityManager.class);
    doAnswer(new Answer<Object>() {

        public Object answer(InvocationOnMock invocation) {
            persistedCert = (Certificate) invocation.getArguments()[0];
            return "";
        }
    }).when(manager).persist(any());
    final BootstrappedKeyStoreProtectionManager mgr = new BootstrappedKeyStoreProtectionManager();
    mgr.setKeyStoreProtectionKey("12345");
    mgr.setPrivateKeyProtectionKey("67890");
    CertificateDaoImpl daoImpl = new CertificateDaoImpl();
    daoImpl.setKeyStoreProtectionManager(mgr);
    daoImpl.setEntityManager(manager);
    daoImpl.save(populateCert("gm2552.der", "gm2552Key.der"));
    assert (persistedCert.getData() != null);
    // make sure we can't access the P12 without a passphrase
    boolean exceptionOccured = false;
    try {
        CertUtils.toCertContainer(persistedCert.getData());
    } catch (CertificateConversionException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : EntityManager(javax.persistence.EntityManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CertificateConversionException(org.nhindirect.config.model.exceptions.CertificateConversionException) CertificateDaoImpl(org.nhindirect.config.store.dao.impl.CertificateDaoImpl) BootstrappedKeyStoreProtectionManager(org.nhindirect.common.crypto.impl.BootstrappedKeyStoreProtectionManager) Test(org.junit.Test)

Aggregations

EntityManager (javax.persistence.EntityManager)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 BootstrappedKeyStoreProtectionManager (org.nhindirect.common.crypto.impl.BootstrappedKeyStoreProtectionManager)1 CertificateConversionException (org.nhindirect.config.model.exceptions.CertificateConversionException)1 CertificateDaoImpl (org.nhindirect.config.store.dao.impl.CertificateDaoImpl)1