Merge branch 'master' into 'master'

Fix Authentication Handler Issue

See merge request entgra/carbon-device-mgt!64
4.x.x
Inosh Perara 6 years ago
commit b2f225a7f8

@ -209,7 +209,7 @@ public class AuthenticationHandler extends AbstractHandler {
private String getDeviceType(String url) { private String getDeviceType(String url) {
StringTokenizer parts = new StringTokenizer(url, "/"); StringTokenizer parts = new StringTokenizer(url, "/");
while (parts.hasMoreElements()) { while (parts.hasMoreElements()) {
if (parts.nextElement().equals("api")) { if (parts.nextElement().equals("device-mgt")) {
return (String) parts.nextElement(); return (String) parts.nextElement();
} }
} }

@ -96,7 +96,7 @@ public class AuthenticationHandlerTest extends BaseAPIHandlerTest {
this.mockClient.setResponse(getAccessTokenReponse()); this.mockClient.setResponse(getAccessTokenReponse());
this.mockClient.setResponse(getValidationResponse()); this.mockClient.setResponse(getValidationResponse());
boolean response = this.handler.handleRequest(createSynapseMessageContext("<empty/>", this.synapseConfiguration, boolean response = this.handler.handleRequest(createSynapseMessageContext("<empty/>", this.synapseConfiguration,
transportHeaders, "https://test.com/testservice/api/testdevice")); transportHeaders, "https://test.com/testservice/device-mgt/testdevice"));
Assert.assertTrue(response); Assert.assertTrue(response);
this.mockClient.reset(); this.mockClient.reset();
} }
@ -110,7 +110,7 @@ public class AuthenticationHandlerTest extends BaseAPIHandlerTest {
this.mockClient.setResponse(getAccessTokenReponse()); this.mockClient.setResponse(getAccessTokenReponse());
this.mockClient.setResponse(getValidationResponse()); this.mockClient.setResponse(getValidationResponse());
boolean response = this.handler.handleRequest(createSynapseMessageContext("<empty/>", this.synapseConfiguration, boolean response = this.handler.handleRequest(createSynapseMessageContext("<empty/>", this.synapseConfiguration,
transportHeaders, "https://test.com/testservice/api/testdevice")); transportHeaders, "https://test.com/testservice/device-mgt/testdevice"));
Assert.assertTrue(response); Assert.assertTrue(response);
this.mockClient.reset(); this.mockClient.reset();
} }
@ -124,7 +124,7 @@ public class AuthenticationHandlerTest extends BaseAPIHandlerTest {
this.mockClient.setResponse(getAccessTokenReponse()); this.mockClient.setResponse(getAccessTokenReponse());
this.mockClient.setResponse(getValidationResponse()); this.mockClient.setResponse(getValidationResponse());
MessageContext messageContext = createSynapseMessageContext("<empty/>", this.synapseConfiguration, MessageContext messageContext = createSynapseMessageContext("<empty/>", this.synapseConfiguration,
transportHeaders, "https://test.com/testservice/api/testdevice"); transportHeaders, "https://test.com/testservice/device-mgt/testdevice");
org.apache.axis2.context.MessageContext axisMC = ((Axis2MessageContext) messageContext).getAxis2MessageContext(); org.apache.axis2.context.MessageContext axisMC = ((Axis2MessageContext) messageContext).getAxis2MessageContext();
String certStr = getContent(TestUtils.getAbsolutePathOfConfig("ra_cert.pem")); String certStr = getContent(TestUtils.getAbsolutePathOfConfig("ra_cert.pem"));
X509Certificate cert = X509Certificate.getInstance(new ByteArrayInputStream(certStr. X509Certificate cert = X509Certificate.getInstance(new ByteArrayInputStream(certStr.
@ -144,7 +144,7 @@ public class AuthenticationHandlerTest extends BaseAPIHandlerTest {
this.mockClient.setResponse(getAccessTokenReponse()); this.mockClient.setResponse(getAccessTokenReponse());
this.mockClient.setResponse(getValidationResponse()); this.mockClient.setResponse(getValidationResponse());
MessageContext messageContext = createSynapseMessageContext("<empty/>", this.synapseConfiguration, MessageContext messageContext = createSynapseMessageContext("<empty/>", this.synapseConfiguration,
transportHeaders, "https://test.com/testservice/api/testdevice"); transportHeaders, "https://test.com/testservice/device-mgt/testdevice");
boolean response = this.handler.handleRequest(messageContext); boolean response = this.handler.handleRequest(messageContext);
Assert.assertTrue(response); Assert.assertTrue(response);
this.mockClient.reset(); this.mockClient.reset();
@ -159,7 +159,7 @@ public class AuthenticationHandlerTest extends BaseAPIHandlerTest {
this.mockClient.setResponse(getAccessTokenReponse()); this.mockClient.setResponse(getAccessTokenReponse());
this.mockClient.setResponse(getInvalidResponse()); this.mockClient.setResponse(getInvalidResponse());
MessageContext messageContext = createSynapseMessageContext("<empty/>", this.synapseConfiguration, MessageContext messageContext = createSynapseMessageContext("<empty/>", this.synapseConfiguration,
transportHeaders, "https://test.com/testservice/api/testdevice"); transportHeaders, "https://test.com/testservice/device-mgt/testdevice");
boolean response = this.handler.handleRequest(messageContext); boolean response = this.handler.handleRequest(messageContext);
Assert.assertFalse(response); Assert.assertFalse(response);
this.mockClient.reset(); this.mockClient.reset();
@ -173,7 +173,7 @@ public class AuthenticationHandlerTest extends BaseAPIHandlerTest {
setMockClient(); setMockClient();
this.mockClient.setResponse(null); this.mockClient.setResponse(null);
MessageContext messageContext = createSynapseMessageContext("<empty/>", this.synapseConfiguration, MessageContext messageContext = createSynapseMessageContext("<empty/>", this.synapseConfiguration,
transportHeaders, "https://test.com/testservice/api/testdevice"); transportHeaders, "https://test.com/testservice/device-mgt/testdevice");
boolean response = this.handler.handleRequest(messageContext); boolean response = this.handler.handleRequest(messageContext);
Assert.assertFalse(response); Assert.assertFalse(response);
this.mockClient.reset(); this.mockClient.reset();
@ -188,7 +188,7 @@ public class AuthenticationHandlerTest extends BaseAPIHandlerTest {
this.mockClient.setResponse(getAccessTokenReponse()); this.mockClient.setResponse(getAccessTokenReponse());
this.mockClient.setResponse(null); this.mockClient.setResponse(null);
MessageContext messageContext = createSynapseMessageContext("<empty/>", this.synapseConfiguration, MessageContext messageContext = createSynapseMessageContext("<empty/>", this.synapseConfiguration,
transportHeaders, "https://test.com/testservice/api/testdevice"); transportHeaders, "https://test.com/testservice/device-mgt/testdevice");
boolean response = this.handler.handleRequest(messageContext); boolean response = this.handler.handleRequest(messageContext);
Assert.assertFalse(response); Assert.assertFalse(response);
this.mockClient.reset(); this.mockClient.reset();
@ -202,7 +202,7 @@ public class AuthenticationHandlerTest extends BaseAPIHandlerTest {
transportHeaders.put(AuthConstants.MDM_SIGNATURE, "some cert"); transportHeaders.put(AuthConstants.MDM_SIGNATURE, "some cert");
AuthenticationHandler handler = new AuthenticationHandler(); AuthenticationHandler handler = new AuthenticationHandler();
boolean response = handler.handleRequest(createSynapseMessageContext("<empty/>", this.synapseConfiguration, boolean response = handler.handleRequest(createSynapseMessageContext("<empty/>", this.synapseConfiguration,
transportHeaders, "https://test.com/testservice/api/testdevice")); transportHeaders, "https://test.com/testservice/device-mgt/testdevice"));
Assert.assertFalse(response); Assert.assertFalse(response);
TestUtils.setSystemProperties(); TestUtils.setSystemProperties();
} }

Loading…
Cancel
Save