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();
}
}
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();
}
}
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());
}
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()));
}
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);
}
Aggregations