Search in sources :

Example 1 with DeleteSslCertCmd

use of com.cloud.api.command.user.loadbalancer.DeleteSslCertCmd in project cosmic by MissionCriticalCloud.

the class CertServiceTest method runDeleteSslCertBoundCert.

@Test
public void runDeleteSslCertBoundCert() throws NoSuchFieldException, IllegalAccessException {
    final TransactionLegacy txn = TransactionLegacy.open("runDeleteSslCertBoundCert");
    final CertServiceImpl certService = new CertServiceImpl();
    // setting mock objects
    final long certId = 1;
    certService._accountMgr = Mockito.mock(AccountManager.class);
    final Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    when(certService._accountMgr.getAccount(anyLong())).thenReturn(account);
    certService._domainDao = Mockito.mock(DomainDao.class);
    final DomainVO domain = new DomainVO("networkdomain", 1L, 1L, "networkdomain");
    when(certService._domainDao.findByIdIncludingRemoved(anyLong())).thenReturn(domain);
    certService._sslCertDao = Mockito.mock(SslCertDao.class);
    when(certService._sslCertDao.remove(anyLong())).thenReturn(true);
    when(certService._sslCertDao.findById(anyLong())).thenReturn(new SslCertVO());
    // rule holding the cert
    certService._lbCertDao = Mockito.mock(LoadBalancerCertMapDao.class);
    final List<LoadBalancerCertMapVO> lbMapList = new ArrayList<>();
    lbMapList.add(new LoadBalancerCertMapVO());
    certService._lbCertDao = Mockito.mock(LoadBalancerCertMapDao.class);
    when(certService._lbCertDao.listByCertId(anyLong())).thenReturn(lbMapList);
    certService._entityMgr = Mockito.mock(EntityManager.class);
    when(certService._entityMgr.findById(eq(LoadBalancerVO.class), anyLong())).thenReturn(new LoadBalancerVO());
    // creating the command
    final DeleteSslCertCmd deleteCmd = new DeleteSslCertCmdExtn();
    final Class<?> _class = deleteCmd.getClass().getSuperclass();
    final Field certField = _class.getDeclaredField("id");
    certField.setAccessible(true);
    certField.set(deleteCmd, certId);
    try {
        certService.deleteSslCert(deleteCmd);
        fail("Delete with a cert id bound to a lb should fail");
    } catch (final Exception e) {
        assertTrue(e.getMessage().contains("Certificate in use by a loadbalancer"));
    }
}
Also used : Account(com.cloud.user.Account) SslCertDao(com.cloud.network.dao.SslCertDao) LoadBalancerCertMapDao(com.cloud.network.dao.LoadBalancerCertMapDao) ArrayList(java.util.ArrayList) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) LoadBalancerCertMapVO(com.cloud.network.dao.LoadBalancerCertMapVO) AccountVO(com.cloud.user.AccountVO) IOException(java.io.IOException) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) DomainVO(com.cloud.domain.DomainVO) Field(java.lang.reflect.Field) EntityManager(com.cloud.dao.EntityManager) SslCertVO(com.cloud.network.dao.SslCertVO) DomainDao(com.cloud.domain.dao.DomainDao) AccountManager(com.cloud.user.AccountManager) DeleteSslCertCmd(com.cloud.api.command.user.loadbalancer.DeleteSslCertCmd) Test(org.junit.Test)

Example 2 with DeleteSslCertCmd

use of com.cloud.api.command.user.loadbalancer.DeleteSslCertCmd in project cosmic by MissionCriticalCloud.

the class CertServiceTest method runDeleteSslCertInvalidId.

@Test
public void runDeleteSslCertInvalidId() throws NoSuchFieldException, IllegalAccessException {
    final TransactionLegacy txn = TransactionLegacy.open("runDeleteSslCertInvalidId");
    final long certId = 1;
    final CertServiceImpl certService = new CertServiceImpl();
    certService._accountMgr = Mockito.mock(AccountManager.class);
    final Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    when(certService._accountMgr.getAccount(anyLong())).thenReturn(account);
    certService._domainDao = Mockito.mock(DomainDao.class);
    final DomainVO domain = new DomainVO("networkdomain", 1L, 1L, "networkdomain");
    when(certService._domainDao.findByIdIncludingRemoved(anyLong())).thenReturn(domain);
    certService._sslCertDao = Mockito.mock(SslCertDao.class);
    when(certService._sslCertDao.remove(anyLong())).thenReturn(true);
    when(certService._sslCertDao.findById(anyLong())).thenReturn(null);
    // no rule holding the cert
    certService._lbCertDao = Mockito.mock(LoadBalancerCertMapDao.class);
    when(certService._lbCertDao.listByCertId(anyLong())).thenReturn(null);
    // creating the command
    final DeleteSslCertCmd deleteCmd = new DeleteSslCertCmdExtn();
    final Class<?> _class = deleteCmd.getClass().getSuperclass();
    final Field certField = _class.getDeclaredField("id");
    certField.setAccessible(true);
    certField.set(deleteCmd, certId);
    try {
        certService.deleteSslCert(deleteCmd);
        fail("Delete with an invalid ID should fail");
    } catch (final Exception e) {
        assertTrue(e.getMessage().contains("Invalid certificate id"));
    }
}
Also used : Account(com.cloud.user.Account) SslCertDao(com.cloud.network.dao.SslCertDao) LoadBalancerCertMapDao(com.cloud.network.dao.LoadBalancerCertMapDao) AccountVO(com.cloud.user.AccountVO) IOException(java.io.IOException) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) DomainVO(com.cloud.domain.DomainVO) Field(java.lang.reflect.Field) DomainDao(com.cloud.domain.dao.DomainDao) AccountManager(com.cloud.user.AccountManager) DeleteSslCertCmd(com.cloud.api.command.user.loadbalancer.DeleteSslCertCmd) Test(org.junit.Test)

Example 3 with DeleteSslCertCmd

use of com.cloud.api.command.user.loadbalancer.DeleteSslCertCmd in project cosmic by MissionCriticalCloud.

the class CertServiceTest method runDeleteSslCertValid.

@Test
public /**
 * Delete with a valid Id should succeed
 */
void runDeleteSslCertValid() throws Exception {
    final TransactionLegacy txn = TransactionLegacy.open("runDeleteSslCertValid");
    final CertServiceImpl certService = new CertServiceImpl();
    final long certId = 1;
    // setting mock objects
    certService._accountMgr = Mockito.mock(AccountManager.class);
    final Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    when(certService._accountMgr.getAccount(anyLong())).thenReturn(account);
    certService._domainDao = Mockito.mock(DomainDao.class);
    final DomainVO domain = new DomainVO("networkdomain", 1L, 1L, "networkdomain");
    when(certService._domainDao.findByIdIncludingRemoved(anyLong())).thenReturn(domain);
    certService._sslCertDao = Mockito.mock(SslCertDao.class);
    when(certService._sslCertDao.remove(anyLong())).thenReturn(true);
    when(certService._sslCertDao.findById(anyLong())).thenReturn(new SslCertVO());
    // a rule holding the cert
    certService._lbCertDao = Mockito.mock(LoadBalancerCertMapDao.class);
    when(certService._lbCertDao.listByCertId(anyLong())).thenReturn(null);
    // creating the command
    final DeleteSslCertCmd deleteCmd = new DeleteSslCertCmdExtn();
    final Class<?> _class = deleteCmd.getClass().getSuperclass();
    final Field certField = _class.getDeclaredField("id");
    certField.setAccessible(true);
    certField.set(deleteCmd, certId);
    certService.deleteSslCert(deleteCmd);
}
Also used : Account(com.cloud.user.Account) SslCertDao(com.cloud.network.dao.SslCertDao) LoadBalancerCertMapDao(com.cloud.network.dao.LoadBalancerCertMapDao) AccountVO(com.cloud.user.AccountVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) DomainVO(com.cloud.domain.DomainVO) Field(java.lang.reflect.Field) SslCertVO(com.cloud.network.dao.SslCertVO) DomainDao(com.cloud.domain.dao.DomainDao) AccountManager(com.cloud.user.AccountManager) DeleteSslCertCmd(com.cloud.api.command.user.loadbalancer.DeleteSslCertCmd) Test(org.junit.Test)

Aggregations

DeleteSslCertCmd (com.cloud.api.command.user.loadbalancer.DeleteSslCertCmd)3 DomainVO (com.cloud.domain.DomainVO)3 DomainDao (com.cloud.domain.dao.DomainDao)3 LoadBalancerCertMapDao (com.cloud.network.dao.LoadBalancerCertMapDao)3 SslCertDao (com.cloud.network.dao.SslCertDao)3 Account (com.cloud.user.Account)3 AccountManager (com.cloud.user.AccountManager)3 AccountVO (com.cloud.user.AccountVO)3 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)3 Field (java.lang.reflect.Field)3 Test (org.junit.Test)3 SslCertVO (com.cloud.network.dao.SslCertVO)2 IOException (java.io.IOException)2 EntityManager (com.cloud.dao.EntityManager)1 LoadBalancerCertMapVO (com.cloud.network.dao.LoadBalancerCertMapVO)1 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)1 ArrayList (java.util.ArrayList)1