Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ public String getValue() {
}
}

/**
* Returns the value as stored in the database, without decrypting it.
*/
public String getRawValue() {
return value;
}

public void setValue(String value) {
if(isEncrypted()) {
this.value = DBEncryptionUtil.encrypt(value);
Expand Down
5 changes: 4 additions & 1 deletion server/src/main/java/com/cloud/api/ApiResponseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
import org.apache.cloudstack.framework.jobs.AsyncJob;
import org.apache.cloudstack.framework.jobs.AsyncJobManager;
import org.apache.cloudstack.management.ManagementServerHost;
Expand Down Expand Up @@ -639,7 +640,9 @@ public ConfigurationResponse createConfigurationResponse(Configuration cfg) {
cfgResponse.setSubGroup(configGroupAndSubGroup.second());
cfgResponse.setDescription(cfg.getDescription());
cfgResponse.setName(cfg.getName());
if (cfg.isEncrypted()) {
if (cfg instanceof ConfigurationVO && cfg.isEncrypted()) {
cfgResponse.setValue(((ConfigurationVO) cfg).getRawValue());
} else if (cfg.isEncrypted()) {
cfgResponse.setValue(DBEncryptionUtil.encrypt(cfg.getValue()));
} else {
cfgResponse.setValue(cfg.getValue());
Expand Down
19 changes: 19 additions & 0 deletions server/src/test/java/com/cloud/api/ApiResponseHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.cloud.api;

import com.cloud.capacity.Capacity;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.Resource;
import com.cloud.domain.DomainVO;
import com.cloud.network.PublicIpQuarantine;
Expand All @@ -39,17 +40,20 @@
import com.cloud.user.UserDataVO;
import com.cloud.user.UserVO;
import com.cloud.user.dao.UserDataDao;
import com.cloud.utils.Pair;
import com.cloud.utils.net.Ip;
import com.cloud.vm.NicSecondaryIp;
import org.apache.cloudstack.annotation.dao.AnnotationDao;
import org.apache.cloudstack.api.response.AutoScaleVmGroupResponse;
import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse;
import org.apache.cloudstack.api.response.ConfigurationResponse;
import org.apache.cloudstack.api.response.DirectDownloadCertificateResponse;
import org.apache.cloudstack.api.response.IpQuarantineResponse;
import org.apache.cloudstack.api.response.NicSecondaryIpResponse;
import org.apache.cloudstack.api.response.UnmanagedInstanceResponse;
import org.apache.cloudstack.api.response.UsageRecordResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
import org.apache.cloudstack.usage.UsageService;
import org.apache.cloudstack.vm.UnmanagedInstanceTO;
import org.junit.After;
Expand All @@ -63,6 +67,7 @@
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;

import java.lang.reflect.Field;
import java.text.ParseException;
Expand Down Expand Up @@ -105,6 +110,9 @@ public class ApiResponseHelperTest {
@Mock
IPAddressDao ipAddressDaoMock;

@Mock
ConfigurationManager configurationManagerMock;

@Spy
@InjectMocks
ApiResponseHelper apiResponseHelper = new ApiResponseHelper();
Expand Down Expand Up @@ -481,4 +489,15 @@ public void testCapacityListingForSingleNonGpuType() {
Assert.assertTrue(apiResponseHelper.capacityListingForSingleNonGpuType(List.of(c1, c2)));
Assert.assertFalse(apiResponseHelper.capacityListingForSingleNonGpuType(List.of(c1, c2, c3)));
}

@Test
public void testCreateConfigurationResponseSecureValueIsReturnedAsStored() {
ConfigurationVO cfg = new ConfigurationVO("Secure", "DEFAULT", "test", "test.secure.setting", null, "test");
ReflectionTestUtils.setField(cfg, "value", "storedEncryptedValue");
Mockito.when(configurationManagerMock.getConfigurationGroupAndSubGroup(cfg.getName())).thenReturn(new Pair<>("Miscellaneous", "Others"));

ConfigurationResponse response = apiResponseHelper.createConfigurationResponse(cfg);

assertEquals("storedEncryptedValue", response.getValue());
}
}
Loading