mirror of https://github.com/apache/cloudstack.git
test_accounts.py failure fix - keep the camelCase parameter "domainId" (#12689)
This commit is contained in:
parent
744c8afcf1
commit
56dc11980f
|
|
@ -48,4 +48,6 @@ public interface ApiServerService {
|
|||
boolean forgotPassword(UserAccount userAccount, Domain domain);
|
||||
|
||||
boolean resetPassword(UserAccount userAccount, String token, String password);
|
||||
|
||||
String getDomainId(Map<String, Object[]> params);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,14 +176,14 @@ public class OauthLoginAPIAuthenticatorCmd extends BaseCmd implements APIAuthent
|
|||
}
|
||||
|
||||
protected Long getDomainIdFromParams(Map<String, Object[]> params, StringBuilder auditTrailSb, String responseType) {
|
||||
String[] domainIdArr = (String[])params.get(ApiConstants.DOMAIN_ID);
|
||||
String domainIdStr = _apiServer.getDomainId(params);
|
||||
Long domainId = null;
|
||||
if (domainIdArr != null && domainIdArr.length > 0) {
|
||||
if (StringUtils.isNotEmpty(domainIdStr)) {
|
||||
try {
|
||||
//check if UUID is passed in for domain
|
||||
domainId = _apiServer.fetchDomainId(domainIdArr[0]);
|
||||
domainId = _apiServer.fetchDomainId(domainIdStr);
|
||||
if (domainId == null) {
|
||||
domainId = Long.parseLong(domainIdArr[0]);
|
||||
domainId = Long.parseLong(domainIdStr);
|
||||
}
|
||||
auditTrailSb.append(" domainid=" + domainId);// building the params for POST call
|
||||
} catch (final NumberFormatException e) {
|
||||
|
|
|
|||
|
|
@ -85,10 +85,29 @@ public class OauthLoginAPIAuthenticatorCmdTest {
|
|||
ApiServer apiServer = mock(ApiServer.class);
|
||||
cmd._apiServer = apiServer;
|
||||
when(apiServer.fetchDomainId("1234")).thenReturn(5678L);
|
||||
when(apiServer.getDomainId(params)).thenCallRealMethod();
|
||||
|
||||
Long domainId = cmd.getDomainIdFromParams(params, auditTrailSb, responseType);
|
||||
|
||||
assertEquals(Long.valueOf(5678), domainId);
|
||||
assertEquals(" domainid=5678", auditTrailSb.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDomainIdFromCamelCaseParam() {
|
||||
StringBuilder auditTrailSb = new StringBuilder();
|
||||
String responseType = "json";
|
||||
Map<String, Object[]> params = new HashMap<>();
|
||||
params.put(ApiConstants.DOMAIN_ID, null);
|
||||
params.put(ApiConstants.DOMAIN__ID, new String[]{"5678"});
|
||||
ApiServer apiServer = mock(ApiServer.class);
|
||||
cmd._apiServer = apiServer;
|
||||
when(apiServer.fetchDomainId("5678")).thenReturn(1234L);
|
||||
when(apiServer.getDomainId(params)).thenCallRealMethod();
|
||||
|
||||
Long domainId = cmd.getDomainIdFromParams(params, auditTrailSb, responseType);
|
||||
|
||||
assertEquals(Long.valueOf(1234), domainId);
|
||||
assertEquals(" domainid=1234", auditTrailSb.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ import org.apache.cloudstack.framework.messagebus.MessageHandler;
|
|||
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
|
||||
import org.apache.cloudstack.user.UserPasswordResetManager;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
import org.apache.http.ConnectionClosedException;
|
||||
import org.apache.http.HttpException;
|
||||
|
|
@ -1354,6 +1355,25 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
|
|||
return userPasswordResetManager.validateAndResetPassword(userAccount, token, password);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDomainId(Map<String, Object[]> params) {
|
||||
if (MapUtils.isEmpty(params)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] domainIdArr = (String[])params.get(ApiConstants.DOMAIN_ID);
|
||||
if (domainIdArr == null) {
|
||||
// Fallback to support clients using the camelCase parameter name "domainId"
|
||||
domainIdArr = (String[])params.get(ApiConstants.DOMAIN__ID);
|
||||
}
|
||||
|
||||
if (domainIdArr == null || domainIdArr.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return domainIdArr[0];
|
||||
}
|
||||
|
||||
private void checkCommandAvailable(final User user, final String commandName, final InetAddress remoteAddress) throws PermissionDeniedException {
|
||||
if (user == null) {
|
||||
throw new PermissionDeniedException("User is null for role based API access check for command" + commandName);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import com.cloud.api.ApiServlet;
|
|||
import com.cloud.domain.Domain;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.user.UserAccount;
|
||||
import com.cloud.utils.StringUtils;
|
||||
import org.apache.cloudstack.api.ApiServerService;
|
||||
import com.cloud.api.response.ApiResponseSerializer;
|
||||
import com.cloud.exception.CloudAuthenticationException;
|
||||
|
|
@ -110,14 +111,14 @@ public class DefaultLoginAPIAuthenticatorCmd extends BaseCmd implements APIAuthe
|
|||
// FIXME: ported from ApiServlet, refactor and cleanup
|
||||
final String[] username = (String[])params.get(ApiConstants.USERNAME);
|
||||
final String[] password = (String[])params.get(ApiConstants.PASSWORD);
|
||||
final String[] domainIdArr = (String[])params.get(ApiConstants.DOMAIN_ID);
|
||||
String domainIdStr = _apiServer.getDomainId(params);
|
||||
Long domainId = null;
|
||||
if (domainIdArr != null && domainIdArr.length > 0) {
|
||||
if (StringUtils.isNotEmpty(domainIdStr)) {
|
||||
try {
|
||||
//check if UUID is passed in for domain
|
||||
domainId = _apiServer.fetchDomainId(domainIdArr[0]);
|
||||
domainId = _apiServer.fetchDomainId(domainIdStr);
|
||||
if (domainId == null) {
|
||||
domainId = Long.parseLong(domainIdArr[0]);
|
||||
domainId = Long.parseLong(domainIdStr);
|
||||
}
|
||||
auditTrailSb.append(" domainid=" + domainId);// building the params for POST call
|
||||
} catch (final NumberFormatException e) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue