You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2023/01/20 15:12:02 UTC

[cloudstack] branch 4.17 updated: api: fix new password is applied on host when update host password with update_passwd_on_host=false (#7092)

This is an automated email from the ASF dual-hosted git repository.

dahn pushed a commit to branch 4.17
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.17 by this push:
     new 536a387326 api: fix new password is applied on host when update host password with update_passwd_on_host=false (#7092)
536a387326 is described below

commit 536a387326f3e6ae341b40b180d8ef221d20ceb9
Author: Wei Zhou <we...@apache.org>
AuthorDate: Fri Jan 20 16:11:55 2023 +0100

    api: fix new password is applied on host when update host password with update_passwd_on_host=false (#7092)
---
 .../api/command/admin/host/UpdateHostPasswordCmd.java      |  3 ++-
 .../api/command/test/UpdateHostPasswordCmdTest.java        | 14 +++++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java
index 5a884cf72a..8f191bd432 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java
@@ -23,6 +23,7 @@ import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.response.ClusterResponse;
 import org.apache.cloudstack.api.response.HostResponse;
 import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.commons.lang3.BooleanUtils;
 import org.apache.log4j.Logger;
 
 import com.cloud.user.Account;
@@ -67,7 +68,7 @@ public class UpdateHostPasswordCmd extends BaseCmd {
     }
 
     public Boolean getUpdatePasswdOnHost() {
-        return updatePasswdOnHost == null ? false : true;
+        return BooleanUtils.isTrue(updatePasswdOnHost);
     }
 
     public String getPassword() {
diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/UpdateHostPasswordCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/UpdateHostPasswordCmdTest.java
index 12f9da3a40..9b130b060b 100644
--- a/api/src/test/java/org/apache/cloudstack/api/command/test/UpdateHostPasswordCmdTest.java
+++ b/api/src/test/java/org/apache/cloudstack/api/command/test/UpdateHostPasswordCmdTest.java
@@ -27,6 +27,7 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
+import org.springframework.test.util.ReflectionTestUtils;
 
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.resource.ResourceService;
@@ -94,4 +95,15 @@ public class UpdateHostPasswordCmdTest extends TestCase {
         assertFalse("The attribute updatePasswdOnHost should be false, but it isn't.", updateHostPasswordCmd.getUpdatePasswdOnHost());
         verify(managementServer, times(1)).updateHostPassword(updateHostPasswordCmd);
     }
-}
\ No newline at end of file
+
+    @Test
+    public void testGetUpdatePasswdOnHostValues() {
+        assertFalse(updateHostPasswordCmd.getUpdatePasswdOnHost());
+
+        ReflectionTestUtils.setField(updateHostPasswordCmd, "updatePasswdOnHost", false);
+        assertFalse(updateHostPasswordCmd.getUpdatePasswdOnHost());
+
+        ReflectionTestUtils.setField(updateHostPasswordCmd, "updatePasswdOnHost", true);
+        assertTrue(updateHostPasswordCmd.getUpdatePasswdOnHost());
+    }
+}