mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	CLOUDSTACK-8868: use same method to generate passwords for system/guest vms
generateRandomPassword() is supposed to create root user passwords. Right now it is only used on the guest VMs. The format of the passwords it creates are of the form "random 3-character string with a lowercase character, uppercase character, and a digit" + random n-character string with only lowercase characters". For whatever reason it was that we use generateRandomPassword() for guest VM root user passwords(maybe more secure?) we should use the same function for system VM root user passwords.
This commit is contained in:
		
							parent
							
								
									004242ccc6
								
							
						
					
					
						commit
						97a5d6bd20
					
				| @ -155,6 +155,8 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio | ||||
|     protected ConfigDepot _configDepot; | ||||
|     @Inject | ||||
|     protected ConfigurationManager _configMgr; | ||||
|     @Inject | ||||
|     protected ManagementService _mgrService; | ||||
| 
 | ||||
| 
 | ||||
|     public ConfigurationServerImpl() { | ||||
| @ -668,7 +670,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio | ||||
|         if (already == null) { | ||||
|             TransactionLegacy txn = TransactionLegacy.currentTxn(); | ||||
|             try { | ||||
|                 String rpassword = PasswordGenerator.generatePresharedKey(8); | ||||
|                 String rpassword = _mgrService.generateRandomPassword(); | ||||
|                 String wSql = "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " | ||||
|                 + "VALUES ('Secure','DEFAULT', 'management-server','system.vm.password', ?,'randmon password generated each management server starts for system vm')"; | ||||
|                 PreparedStatement stmt = txn.prepareAutoCloseStatement(wSql); | ||||
|  | ||||
| @ -19,14 +19,74 @@ package com.cloud.server; | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| 
 | ||||
| import com.cloud.configuration.ConfigurationManager; | ||||
| import com.cloud.configuration.dao.ResourceCountDao; | ||||
| import com.cloud.dc.dao.DataCenterDao; | ||||
| import com.cloud.dc.dao.HostPodDao; | ||||
| import com.cloud.dc.dao.VlanDao; | ||||
| import com.cloud.domain.dao.DomainDao; | ||||
| import com.cloud.network.dao.NetworkDao; | ||||
| import com.cloud.offerings.dao.NetworkOfferingDao; | ||||
| import com.cloud.offerings.dao.NetworkOfferingServiceMapDao; | ||||
| import com.cloud.service.dao.ServiceOfferingDao; | ||||
| import com.cloud.storage.dao.DiskOfferingDao; | ||||
| import com.cloud.user.dao.AccountDao; | ||||
| import com.cloud.utils.db.TransactionLegacy; | ||||
| import org.apache.cloudstack.framework.config.ConfigDepot; | ||||
| import org.apache.cloudstack.framework.config.ConfigDepotAdmin; | ||||
| import org.apache.cloudstack.framework.config.dao.ConfigurationDao; | ||||
| import org.apache.commons.codec.binary.Base64; | ||||
| import org.apache.commons.io.FileUtils; | ||||
| import org.junit.Assert; | ||||
| import org.junit.Test; | ||||
| import org.junit.runner.RunWith; | ||||
| import org.mockito.InjectMocks; | ||||
| import org.mockito.Mock; | ||||
| import org.mockito.Mockito; | ||||
| import org.mockito.Spy; | ||||
| import org.mockito.runners.MockitoJUnitRunner; | ||||
| 
 | ||||
| @RunWith(MockitoJUnitRunner.class) | ||||
| public class ConfigurationServerImplTest { | ||||
| 
 | ||||
|     @Mock | ||||
|     private ConfigurationDao _configDao; | ||||
|     @Mock | ||||
|     private DataCenterDao _zoneDao; | ||||
|     @Mock | ||||
|     private HostPodDao _podDao; | ||||
|     @Mock | ||||
|     private DiskOfferingDao _diskOfferingDao; | ||||
|     @Mock | ||||
|     private ServiceOfferingDao _serviceOfferingDao; | ||||
|     @Mock | ||||
|     private NetworkOfferingDao _networkOfferingDao; | ||||
|     @Mock | ||||
|     private DataCenterDao _dataCenterDao; | ||||
|     @Mock | ||||
|     private NetworkDao _networkDao; | ||||
|     @Mock | ||||
|     private VlanDao _vlanDao; | ||||
|     @Mock | ||||
|     private DomainDao _domainDao; | ||||
|     @Mock | ||||
|     private AccountDao _accountDao; | ||||
|     @Mock | ||||
|     private ResourceCountDao _resourceCountDao; | ||||
|     @Mock | ||||
|     private NetworkOfferingServiceMapDao _ntwkOfferingServiceMapDao; | ||||
|     @Mock | ||||
|     private ConfigDepotAdmin _configDepotAdmin; | ||||
|     @Mock | ||||
|     private ConfigDepot _configDepot; | ||||
|     @Mock | ||||
|     private ConfigurationManager _configMgr; | ||||
|     @Mock | ||||
|     private ManagementService _mgrService; | ||||
| 
 | ||||
|     @InjectMocks | ||||
|     private ConfigurationServerImpl configurationServer; | ||||
| 
 | ||||
|     @Spy | ||||
|     ConfigurationServerImpl windowsImpl = new ConfigurationServerImpl() { | ||||
|       protected boolean isOnWindows() { | ||||
| @ -84,4 +144,22 @@ public class ConfigurationServerImplTest { | ||||
|       Assert.assertFalse(linuxImpl.isOnWindows()); | ||||
|       Assert.assertEquals("scripts/vm/systemvm/injectkeys.sh", linuxImpl.getInjectScript()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void testUpdateSystemvmPassword() { | ||||
|         //setup | ||||
|         String realusername = System.getProperty("user.name"); | ||||
|         System.setProperty("user.name", "cloud"); | ||||
|         Mockito.when(_configDao.getValue("system.vm.random.password")).thenReturn(String.valueOf(true)); | ||||
|         TransactionLegacy.open("cloud"); | ||||
|         Mockito.when(_mgrService.generateRandomPassword()).thenReturn("randomPassword"); | ||||
| 
 | ||||
|         //call the method to test | ||||
|         configurationServer.updateSystemvmPassword(); | ||||
| 
 | ||||
|         //verify that generateRandomPassword() is called | ||||
|         Mockito.verify(_mgrService, Mockito.times(1)).generateRandomPassword(); | ||||
|         //teardown | ||||
|         System.setProperty("user.name", realusername); | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user