Search in sources :

Example 61 with UserVO

use of com.cloud.user.UserVO in project cloudstack by apache.

the class UserVmManagerTest method testRestoreVMF3.

// Test restoreVM when VM is in running state
@Test
public void testRestoreVMF3() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    doReturn(VirtualMachine.State.Running).when(_vmMock).getState();
    when(_vmDao.findById(anyLong())).thenReturn(_vmMock);
    when(_volsDao.findByInstanceAndType(314L, Volume.Type.ROOT)).thenReturn(_rootVols);
    doReturn(false).when(_rootVols).isEmpty();
    when(_rootVols.get(eq(0))).thenReturn(_volumeMock);
    doReturn(3L).when(_volumeMock).getTemplateId();
    when(_templateDao.findById(anyLong())).thenReturn(_templateMock);
    when(_storageMgr.allocateDuplicateVolume(_volumeMock, null)).thenReturn(_volumeMock);
    doNothing().when(_volsDao).attachVolume(anyLong(), anyLong(), anyLong());
    when(_volumeMock.getId()).thenReturn(3L);
    doNothing().when(_volsDao).detachVolume(anyLong());
    when(_templateMock.getUuid()).thenReturn("e0552266-7060-11e2-bbaa-d55f5db67735");
    Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    StoragePoolVO storagePool = new StoragePoolVO();
    storagePool.setManaged(false);
    when(_storagePoolDao.findById(anyLong())).thenReturn(storagePool);
    CallContext.register(user, account);
    try {
        _userVmMgr.restoreVMInternal(_account, _vmMock, null);
    } finally {
        CallContext.unregister();
    }
}
Also used : Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 62 with UserVO

use of com.cloud.user.UserVO in project cloudstack by apache.

the class UserVmManagerTest method testScaleVMF2.

// Test scaleVm on equal service offerings.
@Test(expected = InvalidParameterValueException.class)
public void testScaleVMF2() throws Exception {
    ScaleVMCmd cmd = new ScaleVMCmd();
    Class<?> _class = cmd.getClass();
    Field idField = _class.getDeclaredField("id");
    idField.setAccessible(true);
    idField.set(cmd, 1L);
    Field serviceOfferingIdField = _class.getDeclaredField("serviceOfferingId");
    serviceOfferingIdField.setAccessible(true);
    serviceOfferingIdField.set(cmd, 1L);
    when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance);
    doReturn(Hypervisor.HypervisorType.XenServer).when(_vmInstance).getHypervisorType();
    doReturn(VirtualMachine.State.Running).when(_vmInstance).getState();
    doNothing().when(_accountMgr).checkAccess(_account, null, true, _templateMock);
    doNothing().when(_itMgr).checkIfCanUpgrade(_vmMock, _offeringVo);
    ServiceOffering so1 = getSvcoffering(512);
    ServiceOffering so2 = getSvcoffering(256);
    when(_offeringDao.findById(anyLong())).thenReturn((ServiceOfferingVO) so1);
    when(_offeringDao.findByIdIncludingRemoved(anyLong(), anyLong())).thenReturn((ServiceOfferingVO) so1);
    Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, UUID.randomUUID().toString());
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, account);
    try {
        _userVmMgr.upgradeVirtualMachine(cmd);
    } finally {
        CallContext.unregister();
    }
}
Also used : Field(java.lang.reflect.Field) Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) ServiceOffering(com.cloud.offering.ServiceOffering) ScaleVMCmd(org.apache.cloudstack.api.command.user.vm.ScaleVMCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 63 with UserVO

use of com.cloud.user.UserVO in project cloudstack by apache.

the class SAML2UserAuthenticatorTest method authenticate.

@Test
public void authenticate() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    SAML2UserAuthenticator authenticator = new SAML2UserAuthenticator();
    Field daoField = SAML2UserAuthenticator.class.getDeclaredField("_userAccountDao");
    daoField.setAccessible(true);
    daoField.set(authenticator, userAccountDao);
    Field userDaoField = SAML2UserAuthenticator.class.getDeclaredField("_userDao");
    userDaoField.setAccessible(true);
    userDaoField.set(authenticator, userDao);
    UserAccountVO account = new UserAccountVO();
    account.setPassword("5f4dcc3b5aa765d61d8327deb882cf99");
    account.setId(1L);
    UserVO user = new UserVO();
    Mockito.when(userAccountDao.getUserAccount(Mockito.anyString(), Mockito.anyLong())).thenReturn(account);
    Mockito.when(userDao.getUser(Mockito.anyLong())).thenReturn(user);
    Pair<Boolean, ActionOnFailedAuthentication> pair;
    Map<String, Object[]> params = new HashMap<String, Object[]>();
    // When there is no SAMLRequest in params
    pair = authenticator.authenticate("someUID", "random", 1l, params);
    Assert.assertFalse(pair.first());
    // When there is SAMLRequest in params and user is same as the mocked one
    params.put(SAMLPluginConstants.SAML_RESPONSE, new String[] { "RandomString" });
    pair = authenticator.authenticate("someUID", "random", 1l, params);
    Assert.assertFalse(pair.first());
    // When there is SAMLRequest in params but username is null
    pair = authenticator.authenticate(null, "random", 1l, params);
    Assert.assertFalse(pair.first());
    // When there is SAMLRequest in params but username is empty
    pair = authenticator.authenticate("", "random", 1l, params);
    Assert.assertFalse(pair.first());
    // When there is SAMLRequest in params but username is not valid
    pair = authenticator.authenticate("someOtherUID", "random", 1l, params);
    Assert.assertFalse(pair.first());
}
Also used : SAML2UserAuthenticator(org.apache.cloudstack.saml.SAML2UserAuthenticator) Field(java.lang.reflect.Field) UserAccountVO(com.cloud.user.UserAccountVO) UserVO(com.cloud.user.UserVO) HashMap(java.util.HashMap) ActionOnFailedAuthentication(com.cloud.server.auth.UserAuthenticator.ActionOnFailedAuthentication) Test(org.junit.Test)

Example 64 with UserVO

use of com.cloud.user.UserVO in project cloudstack by apache.

the class SAML2AuthManagerImplTest method testAuthorizeUser.

@Test
public void testAuthorizeUser() {
    // Test invalid user
    Mockito.when(userDao.getUser(Mockito.anyLong())).thenReturn(null);
    assertFalse(saml2AuthManager.authorizeUser(1L, "someID", true));
    // Test valid user
    UserVO user = new UserVO(200L);
    user.setUsername("someuser");
    Mockito.when(userDao.getUser(Mockito.anyLong())).thenReturn(user);
    assertTrue(saml2AuthManager.authorizeUser(1L, "someID", true));
    Mockito.verify(userDao, Mockito.atLeastOnce()).update(Mockito.anyLong(), Mockito.any(user.getClass()));
}
Also used : UserVO(com.cloud.user.UserVO) Test(org.junit.Test)

Example 65 with UserVO

use of com.cloud.user.UserVO in project cloudstack by apache.

the class ImplicitPlannerTest method setUp.

@Before
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    acct.setType(Account.ACCOUNT_TYPE_NORMAL);
    acct.setAccountName("user1");
    acct.setDomainId(domainId);
    acct.setId(accountId);
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, acct);
}
Also used : UserVO(com.cloud.user.UserVO) Before(org.junit.Before)

Aggregations

UserVO (com.cloud.user.UserVO)72 AccountVO (com.cloud.user.AccountVO)44 Account (com.cloud.user.Account)42 Test (org.junit.Test)23 Before (org.junit.Before)21 ArrayList (java.util.ArrayList)19 Field (java.lang.reflect.Field)15 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)11 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 HashMap (java.util.HashMap)11 DomainVO (com.cloud.domain.DomainVO)10 VMTemplateVO (com.cloud.storage.VMTemplateVO)8 DomainRouterVO (com.cloud.vm.DomainRouterVO)8 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)7 Service (com.cloud.network.Network.Service)7 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)6 DataCenterVO (com.cloud.dc.DataCenterVO)5 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)5 LinkedHashMap (java.util.LinkedHashMap)5 NetworkOrchestrationService (org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService)5