cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [2/4] git commit: updated refs/heads/master to 17d5bfa
Date Thu, 03 Dec 2015 08:59:24 GMT
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.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/97a5d6bd
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/97a5d6bd
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/97a5d6bd

Branch: refs/heads/master
Commit: 97a5d6bd20da8cd4a03b4ea038c1664134f812cc
Parents: 004242c
Author: Rajani Karuturi <rajani.karuturi@citrix.com>
Authored: Wed Sep 16 12:28:03 2015 +0530
Committer: Rajani Karuturi <rajani.karuturi@citrix.com>
Committed: Tue Nov 17 16:05:46 2015 +0530

----------------------------------------------------------------------
 .../cloud/server/ConfigurationServerImpl.java   |  4 +-
 .../server/ConfigurationServerImplTest.java     | 78 ++++++++++++++++++++
 2 files changed, 81 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/97a5d6bd/server/src/com/cloud/server/ConfigurationServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java
index 926d9a7..16e4ff0 100644
--- a/server/src/com/cloud/server/ConfigurationServerImpl.java
+++ b/server/src/com/cloud/server/ConfigurationServerImpl.java
@@ -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);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/97a5d6bd/server/test/com/cloud/server/ConfigurationServerImplTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/server/ConfigurationServerImplTest.java b/server/test/com/cloud/server/ConfigurationServerImplTest.java
index 38dc1bc..b64f3f7 100644
--- a/server/test/com/cloud/server/ConfigurationServerImplTest.java
+++ b/server/test/com/cloud/server/ConfigurationServerImplTest.java
@@ -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);
+    }
 }


Mime
View raw message