mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
plugins: fix test case, interface usage and checkstyle import issue
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
a3e6942e85
commit
869a83f8f8
@ -1246,7 +1246,7 @@ public class LibvirtComputingResourceTest {
|
|||||||
when(conn.domainLookupByName(vmName)).thenReturn(dm);
|
when(conn.domainLookupByName(vmName)).thenReturn(dm);
|
||||||
|
|
||||||
when(libvirtComputingResource.getPrivateIp()).thenReturn("127.0.0.1");
|
when(libvirtComputingResource.getPrivateIp()).thenReturn("127.0.0.1");
|
||||||
when(dm.getXMLDesc(0)).thenReturn("host_domain");
|
when(dm.getXMLDesc(8)).thenReturn("host_domain");
|
||||||
when(dm.isPersistent()).thenReturn(1);
|
when(dm.isPersistent()).thenReturn(1);
|
||||||
doNothing().when(dm).undefine();
|
doNothing().when(dm).undefine();
|
||||||
|
|
||||||
@ -1274,7 +1274,7 @@ public class LibvirtComputingResourceTest {
|
|||||||
verify(libvirtComputingResource, times(1)).getDisks(conn, vmName);
|
verify(libvirtComputingResource, times(1)).getDisks(conn, vmName);
|
||||||
try {
|
try {
|
||||||
verify(conn, times(1)).domainLookupByName(vmName);
|
verify(conn, times(1)).domainLookupByName(vmName);
|
||||||
verify(dm, times(1)).getXMLDesc(0);
|
verify(dm, times(1)).getXMLDesc(8);
|
||||||
} catch (final LibvirtException e) {
|
} catch (final LibvirtException e) {
|
||||||
fail(e.getMessage());
|
fail(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,6 +52,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -99,7 +100,7 @@ public class ListAndSwitchSAMLAccountCmd extends BaseCmd implements APIAuthentic
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String authenticate(final String command, final Map<String, Object[]> params, final HttpSession session, final String remoteAddress, final String responseType, final StringBuilder auditTrailSb, final HttpServletRequest req, final HttpServletResponse resp) throws ServerApiException {
|
public String authenticate(final String command, final Map<String, Object[]> params, final HttpSession session, InetAddress remoteAddress, final String responseType, final StringBuilder auditTrailSb, final HttpServletRequest req, final HttpServletResponse resp) throws ServerApiException {
|
||||||
if (session == null || session.isNew()) {
|
if (session == null || session.isNew()) {
|
||||||
throw new ServerApiException(ApiErrorCode.UNAUTHORIZED, _apiServer.getSerializedApiError(ApiErrorCode.UNAUTHORIZED.getHttpCode(),
|
throw new ServerApiException(ApiErrorCode.UNAUTHORIZED, _apiServer.getSerializedApiError(ApiErrorCode.UNAUTHORIZED.getHttpCode(),
|
||||||
"Only authenticated saml users can request this API",
|
"Only authenticated saml users can request this API",
|
||||||
|
|||||||
@ -70,8 +70,6 @@ import javax.xml.parsers.ParserConfigurationException;
|
|||||||
import javax.xml.stream.FactoryConfigurationError;
|
import javax.xml.stream.FactoryConfigurationError;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.URLEncoder;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|||||||
@ -49,6 +49,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -121,7 +122,7 @@ public class ListAndSwitchSAMLAccountCmdTest extends TestCase {
|
|||||||
|
|
||||||
// invalid session test
|
// invalid session test
|
||||||
try {
|
try {
|
||||||
cmd.authenticate("command", params, null, "random", HttpUtils.RESPONSE_TYPE_JSON, new StringBuilder(), req, resp);
|
cmd.authenticate("command", params, null, null, HttpUtils.RESPONSE_TYPE_JSON, new StringBuilder(), req, resp);
|
||||||
} catch (ServerApiException exception) {
|
} catch (ServerApiException exception) {
|
||||||
assertEquals(exception.getErrorCode(), ApiErrorCode.UNAUTHORIZED);
|
assertEquals(exception.getErrorCode(), ApiErrorCode.UNAUTHORIZED);
|
||||||
} finally {
|
} finally {
|
||||||
@ -132,7 +133,7 @@ public class ListAndSwitchSAMLAccountCmdTest extends TestCase {
|
|||||||
params.put(ApiConstants.SESSIONKEY, new String[]{"someOtherValue"});
|
params.put(ApiConstants.SESSIONKEY, new String[]{"someOtherValue"});
|
||||||
try {
|
try {
|
||||||
Mockito.when(session.isNew()).thenReturn(false);
|
Mockito.when(session.isNew()).thenReturn(false);
|
||||||
cmd.authenticate("command", params, session, "random", HttpUtils.RESPONSE_TYPE_JSON, new StringBuilder(), req, resp);
|
cmd.authenticate("command", params, session, null, HttpUtils.RESPONSE_TYPE_JSON, new StringBuilder(), req, resp);
|
||||||
} catch (ServerApiException exception) {
|
} catch (ServerApiException exception) {
|
||||||
assertEquals(exception.getErrorCode(), ApiErrorCode.UNAUTHORIZED);
|
assertEquals(exception.getErrorCode(), ApiErrorCode.UNAUTHORIZED);
|
||||||
} finally {
|
} finally {
|
||||||
@ -142,7 +143,7 @@ public class ListAndSwitchSAMLAccountCmdTest extends TestCase {
|
|||||||
// valid sessionkey value test
|
// valid sessionkey value test
|
||||||
params.put(ApiConstants.SESSIONKEY, new String[]{sessionKeyValue});
|
params.put(ApiConstants.SESSIONKEY, new String[]{sessionKeyValue});
|
||||||
try {
|
try {
|
||||||
cmd.authenticate("command", params, session, "random", HttpUtils.RESPONSE_TYPE_JSON, new StringBuilder(), req, resp);
|
cmd.authenticate("command", params, session, null, HttpUtils.RESPONSE_TYPE_JSON, new StringBuilder(), req, resp);
|
||||||
} catch (ServerApiException exception) {
|
} catch (ServerApiException exception) {
|
||||||
assertEquals(exception.getErrorCode(), ApiErrorCode.ACCOUNT_ERROR);
|
assertEquals(exception.getErrorCode(), ApiErrorCode.ACCOUNT_ERROR);
|
||||||
} finally {
|
} finally {
|
||||||
@ -159,7 +160,7 @@ public class ListAndSwitchSAMLAccountCmdTest extends TestCase {
|
|||||||
mockedUserAccount.setSource(User.Source.UNKNOWN);
|
mockedUserAccount.setSource(User.Source.UNKNOWN);
|
||||||
Mockito.when(accountService.getUserAccountById(Mockito.anyLong())).thenReturn(mockedUserAccount);
|
Mockito.when(accountService.getUserAccountById(Mockito.anyLong())).thenReturn(mockedUserAccount);
|
||||||
try {
|
try {
|
||||||
cmd.authenticate("command", params, session, "random", HttpUtils.RESPONSE_TYPE_JSON, new StringBuilder(), req, resp);
|
cmd.authenticate("command", params, session, null, HttpUtils.RESPONSE_TYPE_JSON, new StringBuilder(), req, resp);
|
||||||
} catch (ServerApiException exception) {
|
} catch (ServerApiException exception) {
|
||||||
assertEquals(exception.getErrorCode(), ApiErrorCode.ACCOUNT_ERROR);
|
assertEquals(exception.getErrorCode(), ApiErrorCode.ACCOUNT_ERROR);
|
||||||
} finally {
|
} finally {
|
||||||
@ -181,9 +182,9 @@ public class ListAndSwitchSAMLAccountCmdTest extends TestCase {
|
|||||||
loginCmdResponse.setLastName("lastName");
|
loginCmdResponse.setLastName("lastName");
|
||||||
loginCmdResponse.setSessionKey("newSessionKeyString");
|
loginCmdResponse.setSessionKey("newSessionKeyString");
|
||||||
Mockito.when(apiServer.loginUser(Mockito.any(HttpSession.class), Mockito.anyString(), Mockito.anyString(),
|
Mockito.when(apiServer.loginUser(Mockito.any(HttpSession.class), Mockito.anyString(), Mockito.anyString(),
|
||||||
Mockito.anyLong(), Mockito.anyString(), Mockito.anyString(), Mockito.anyMap())).thenReturn(loginCmdResponse);
|
Mockito.anyLong(), Mockito.anyString(), Mockito.any(InetAddress.class), Mockito.anyMap())).thenReturn(loginCmdResponse);
|
||||||
try {
|
try {
|
||||||
cmd.authenticate("command", params, session, "random", HttpUtils.RESPONSE_TYPE_JSON, new StringBuilder(), req, resp);
|
cmd.authenticate("command", params, session, null, HttpUtils.RESPONSE_TYPE_JSON, new StringBuilder(), req, resp);
|
||||||
} catch (ServerApiException exception) {
|
} catch (ServerApiException exception) {
|
||||||
fail("SAML list and switch account API failed to pass for all valid data: " + exception.getMessage());
|
fail("SAML list and switch account API failed to pass for all valid data: " + exception.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user