Skip to content

Commit 44d43e7

Browse files
deal with inexistent provided domain ID
1 parent c0089e3 commit 44d43e7

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

server/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManagerImpl.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
import javax.inject.Inject;
2929
import javax.naming.ConfigurationException;
3030

31+
import com.cloud.domain.Domain;
3132
import com.cloud.domain.dao.DomainDao;
33+
import com.cloud.exception.InvalidParameterValueException;
3234
import org.apache.cloudstack.api.ResponseGenerator;
3335
import org.apache.cloudstack.api.ResponseObject;
3436
import org.apache.cloudstack.api.command.user.consoleproxy.ConsoleEndpoint;
@@ -255,7 +257,12 @@ protected long getBaseDomainIdToListConsoleSessions(Long domainId) {
255257
return caller.getDomainId();
256258
}
257259

258-
accountManager.checkAccess(caller, domainDao.findById(domainId));
260+
Domain domain = domainDao.findById(domainId);
261+
if (domain == null) {
262+
throw new InvalidParameterValueException(String.format("Unable to find domain with ID [%s]. Verify the informed domain and try again.", domainId));
263+
}
264+
265+
accountManager.checkAccess(caller, domain);
259266
return domainId;
260267
}
261268

server/src/test/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManagerImplTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ public void listConsoleSessionsInternalTestAdminsShouldBeAllowedToRetrieveOtherA
172172
try (MockedStatic<CallContext> callContextStaticMock = Mockito.mockStatic(CallContext.class)) {
173173
callContextStaticMock.when(CallContext::current).thenReturn(callContextMock);
174174
Mockito.when(listConsoleSessionsCmdMock.getDomainId()).thenReturn(callerDomainId);
175+
Mockito.doReturn(callerDomainId).when(consoleAccessManager).getBaseDomainIdToListConsoleSessions(callerDomainId);
175176
Mockito.when(listConsoleSessionsCmdMock.getAccountId()).thenReturn(callerAccountId);
176177
Mockito.when(listConsoleSessionsCmdMock.getUserId()).thenReturn(callerUserId);
177178
Mockito.when(listConsoleSessionsCmdMock.isRecursive()).thenReturn(isRecursive);
@@ -199,6 +200,7 @@ public void listConsoleSessionsInternalTestShouldNotFetchConsoleSessionsRecursiv
199200
try (MockedStatic<CallContext> callContextStaticMock = Mockito.mockStatic(CallContext.class)) {
200201
callContextStaticMock.when(CallContext::current).thenReturn(callContextMock);
201202
Mockito.when(listConsoleSessionsCmdMock.getDomainId()).thenReturn(callerDomainId);
203+
Mockito.doReturn(callerDomainId).when(consoleAccessManager).getBaseDomainIdToListConsoleSessions(callerDomainId);
202204
Mockito.when(listConsoleSessionsCmdMock.getAccountId()).thenReturn(callerAccountId);
203205
Mockito.when(listConsoleSessionsCmdMock.getUserId()).thenReturn(callerUserId);
204206
Mockito.when(listConsoleSessionsCmdMock.isRecursive()).thenReturn(isRecursive);
@@ -226,6 +228,7 @@ public void listConsoleSessionsInternalTestShouldFetchConsoleSessionsRecursively
226228
try (MockedStatic<CallContext> callContextStaticMock = Mockito.mockStatic(CallContext.class)) {
227229
callContextStaticMock.when(CallContext::current).thenReturn(callContextMock);
228230
Mockito.when(listConsoleSessionsCmdMock.getDomainId()).thenReturn(callerDomainId);
231+
Mockito.doReturn(callerDomainId).when(consoleAccessManager).getBaseDomainIdToListConsoleSessions(callerDomainId);
229232
Mockito.when(listConsoleSessionsCmdMock.getAccountId()).thenReturn(callerAccountId);
230233
Mockito.when(listConsoleSessionsCmdMock.getUserId()).thenReturn(callerUserId);
231234
Mockito.when(listConsoleSessionsCmdMock.isRecursive()).thenReturn(isRecursive);

0 commit comments

Comments
 (0)