Merge branch 'master' into Multiple_VHost_Connection
Conflicts: hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java hawkbit-security-core/src/test/java/org/eclipse/hawkbit/util/IpUtilTest.java Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
@@ -45,7 +45,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Test Amqp controller authentfication.
|
||||
*/
|
||||
@Features("AMQP Authenfication Test")
|
||||
@Stories("Tests the authenfication")
|
||||
@@ -82,24 +82,34 @@ public class AmqpControllerAuthentficationTest {
|
||||
amqpMessageHandlerService.setAuthenticationManager(authenticationManager);
|
||||
}
|
||||
|
||||
@Test(expected = BadCredentialsException.class)
|
||||
@Test
|
||||
@Description("Tests authentication manager without principal")
|
||||
public void testAuthenticationeBadCredantialsWithoutPricipal() {
|
||||
final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345");
|
||||
authenticationManager.doAuthenticate(securityToken);
|
||||
fail();
|
||||
try {
|
||||
authenticationManager.doAuthenticate(securityToken);
|
||||
fail("BadCredentialsException was excepeted since principal was missing");
|
||||
} catch (final BadCredentialsException exception) {
|
||||
// test ok - exception was excepted
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = BadCredentialsException.class)
|
||||
@Description("Tests authentication manager without wrong credential")
|
||||
@Test
|
||||
@Description("Tests authentication manager without wrong credential")
|
||||
public void testAuthenticationBadCredantialsWithWrongCredential() {
|
||||
final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345");
|
||||
when(systemManagement.getConfigurationValue(
|
||||
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), any()))
|
||||
.thenReturn(Boolean.TRUE);
|
||||
securityToken.getHeaders().put(TenantSecruityToken.AUTHORIZATION_HEADER, "TargetToken 12" + CONTROLLLER_ID);
|
||||
authenticationManager.doAuthenticate(securityToken);
|
||||
fail();
|
||||
try {
|
||||
authenticationManager.doAuthenticate(securityToken);
|
||||
fail("BadCredentialsException was excepeted due to wrong credential");
|
||||
} catch (final BadCredentialsException exception) {
|
||||
// test ok - exception was excepted
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -93,7 +93,8 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit
|
||||
amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent);
|
||||
final Message sendMessage = createArgumentCapture(targetAssignDistributionSetEvent.getTargetAdress());
|
||||
final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage);
|
||||
assertTrue(downloadAndUpdateRequest.getSoftwareModules().isEmpty());
|
||||
assertTrue("No softwaremmodule should be contained in the request",
|
||||
downloadAndUpdateRequest.getSoftwareModules().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,17 +107,22 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit
|
||||
amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent);
|
||||
final Message sendMessage = createArgumentCapture(targetAssignDistributionSetEvent.getTargetAdress());
|
||||
final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage);
|
||||
assertEquals(3, downloadAndUpdateRequest.getSoftwareModules().size());
|
||||
assertEquals("Expecting a size of 3 software modules in the reuqest", 3,
|
||||
downloadAndUpdateRequest.getSoftwareModules().size());
|
||||
for (final org.eclipse.hawkbit.dmf.json.model.SoftwareModule softwareModule : downloadAndUpdateRequest
|
||||
.getSoftwareModules()) {
|
||||
assertTrue(softwareModule.getArtifacts().isEmpty());
|
||||
assertTrue("Artifact list for softwaremodule should be empty", softwareModule.getArtifacts().isEmpty());
|
||||
for (final SoftwareModule softwareModule2 : dsA.getModules()) {
|
||||
assertNotNull(softwareModule.getModuleId());
|
||||
assertNotNull("Sofware module ID should be set", softwareModule.getModuleId());
|
||||
if (!softwareModule.getModuleId().equals(softwareModule2.getId())) {
|
||||
continue;
|
||||
}
|
||||
assertEquals(softwareModule.getModuleType(), softwareModule2.getType().getKey());
|
||||
assertEquals(softwareModule.getModuleVersion(), softwareModule2.getVersion());
|
||||
assertEquals(
|
||||
"Software module type in event should be the same as the softwaremodule in the distribution set",
|
||||
softwareModule.getModuleType(), softwareModule2.getType().getKey());
|
||||
assertEquals(
|
||||
"Software module version in event should be the same as the softwaremodule in the distribution set",
|
||||
softwareModule.getModuleVersion(), softwareModule2.getVersion());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,13 +146,14 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit
|
||||
amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent);
|
||||
final Message sendMessage = createArgumentCapture(targetAssignDistributionSetEvent.getTargetAdress());
|
||||
final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage);
|
||||
assertEquals(3, downloadAndUpdateRequest.getSoftwareModules().size());
|
||||
assertEquals("DownloadAndUpdateRequest event should contains 3 software modules", 3,
|
||||
downloadAndUpdateRequest.getSoftwareModules().size());
|
||||
for (final org.eclipse.hawkbit.dmf.json.model.SoftwareModule softwareModule : downloadAndUpdateRequest
|
||||
.getSoftwareModules()) {
|
||||
if (!softwareModule.getModuleId().equals(module.getId())) {
|
||||
continue;
|
||||
}
|
||||
assertFalse(softwareModule.getArtifacts().isEmpty());
|
||||
assertFalse("The software module artifacts should not be empty", softwareModule.getArtifacts().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,8 +172,8 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit
|
||||
private void assertCancelMessage(final Message sendMessage) {
|
||||
assertEventMessage(sendMessage);
|
||||
final Long actionId = convertMessage(sendMessage, Long.class);
|
||||
assertEquals(actionId, Long.valueOf(1));
|
||||
assertEquals(EventTopic.CANCEL_DOWNLOAD,
|
||||
assertEquals("Action ID should be 1", actionId, Long.valueOf(1));
|
||||
assertEquals("The topc in the message should be a CANCEL_DOWNLOAD value", EventTopic.CANCEL_DOWNLOAD,
|
||||
sendMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.TOPIC));
|
||||
|
||||
}
|
||||
@@ -175,8 +182,9 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit
|
||||
assertEventMessage(sendMessage);
|
||||
final DownloadAndUpdateRequest downloadAndUpdateRequest = convertMessage(sendMessage,
|
||||
DownloadAndUpdateRequest.class);
|
||||
assertEquals(downloadAndUpdateRequest.getActionId(), Long.valueOf(1));
|
||||
assertEquals(EventTopic.DOWNLOAD_AND_INSTALL,
|
||||
assertEquals("The action ID of the downloadAndUpdateRequest event shuold be 1",
|
||||
downloadAndUpdateRequest.getActionId(), Long.valueOf(1));
|
||||
assertEquals("The topic of the event shuold contain DOWNLOAD_AND_INSTALL", EventTopic.DOWNLOAD_AND_INSTALL,
|
||||
sendMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.TOPIC));
|
||||
return downloadAndUpdateRequest;
|
||||
|
||||
@@ -186,11 +194,14 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit
|
||||
* @param sendMessage
|
||||
*/
|
||||
private void assertEventMessage(final Message sendMessage) {
|
||||
assertNotNull(sendMessage);
|
||||
assertNotNull("The message should not be null", sendMessage);
|
||||
|
||||
assertEquals(CONTROLLER_ID, sendMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.THING_ID));
|
||||
assertEquals(MessageType.EVENT, sendMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.TYPE));
|
||||
assertEquals(MessageProperties.CONTENT_TYPE_JSON, sendMessage.getMessageProperties().getContentType());
|
||||
assertEquals("The value of the message header THING_ID should be " + CONTROLLER_ID, CONTROLLER_ID,
|
||||
sendMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.THING_ID));
|
||||
assertEquals("The value of the message header TYPE should be EVENT", MessageType.EVENT,
|
||||
sendMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.TYPE));
|
||||
assertEquals("The content type message should be " + MessageProperties.CONTENT_TYPE_JSON,
|
||||
MessageProperties.CONTENT_TYPE_JSON, sendMessage.getMessageProperties().getContentType());
|
||||
}
|
||||
|
||||
protected Message createArgumentCapture(final URI uri) {
|
||||
|
||||
@@ -133,18 +133,16 @@ public class AmqpMessageHandlerServiceTest {
|
||||
messageProperties.setHeader(MessageHeaderKey.THING_ID, "1");
|
||||
final Message message = messageConverter.toMessage(new byte[0], messageProperties);
|
||||
|
||||
// mock
|
||||
final ArgumentCaptor<String> targetIdCaptor = ArgumentCaptor.forClass(String.class);
|
||||
final ArgumentCaptor<URI> uriCaptor = ArgumentCaptor.forClass(URI.class);
|
||||
when(controllerManagementMock.findOrRegisterTargetIfItDoesNotexist(targetIdCaptor.capture(),
|
||||
uriCaptor.capture())).thenReturn(null);
|
||||
|
||||
// test
|
||||
amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT, "vHost");
|
||||
|
||||
// verify
|
||||
assertThat(targetIdCaptor.getValue()).isEqualTo(knownThingId);
|
||||
assertThat(uriCaptor.getValue().toString()).isEqualTo("amqp://vHost/MyTest");
|
||||
assertThat(targetIdCaptor.getValue()).as("Thing id is wrong").isEqualTo(knownThingId);
|
||||
assertThat(uriCaptor.getValue().toString()).as("Uri is not right").isEqualTo("amqp://vHost/MyTest");
|
||||
|
||||
}
|
||||
|
||||
@@ -271,8 +269,9 @@ public class AmqpMessageHandlerServiceTest {
|
||||
|
||||
// verify
|
||||
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage);
|
||||
assertThat(downloadResponse).isNotNull();
|
||||
assertThat(downloadResponse.getResponseCode()).isEqualTo(HttpStatus.NOT_FOUND.value());
|
||||
assertThat(downloadResponse).as("Message body should not null").isNotNull();
|
||||
assertThat(downloadResponse.getResponseCode()).as("Message body response code is wrong")
|
||||
.isEqualTo(HttpStatus.NOT_FOUND.value());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -294,8 +293,9 @@ public class AmqpMessageHandlerServiceTest {
|
||||
|
||||
// verify
|
||||
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage);
|
||||
assertThat(downloadResponse).isNotNull();
|
||||
assertThat(downloadResponse.getResponseCode()).isEqualTo(HttpStatus.NOT_FOUND.value());
|
||||
assertThat(downloadResponse).as("Message body should not null").isNotNull();
|
||||
assertThat(downloadResponse.getResponseCode()).as("Message body response code is wrong")
|
||||
.isEqualTo(HttpStatus.NOT_FOUND.value());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -325,9 +325,10 @@ public class AmqpMessageHandlerServiceTest {
|
||||
|
||||
// verify
|
||||
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage);
|
||||
assertThat(downloadResponse).isNotNull();
|
||||
assertThat(downloadResponse.getResponseCode()).isEqualTo(HttpStatus.OK.value());
|
||||
assertThat(downloadResponse.getArtifact().getSize()).isEqualTo(1L);
|
||||
assertThat(downloadResponse).as("Message body should not null").isNotNull();
|
||||
assertThat(downloadResponse.getResponseCode()).as("Message body response code is wrong")
|
||||
.isEqualTo(HttpStatus.OK.value());
|
||||
assertThat(downloadResponse.getArtifact().getSize()).as("Wrong artifact size in message body").isEqualTo(1L);
|
||||
assertThat(downloadResponse.getDownloadUrl()).startsWith("http://localhost/api/v1/downloadserver/downloadId/");
|
||||
}
|
||||
|
||||
@@ -364,9 +365,11 @@ public class AmqpMessageHandlerServiceTest {
|
||||
final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent = captorTargetAssignDistributionSetEvent
|
||||
.getValue();
|
||||
|
||||
assertThat(targetAssignDistributionSetEvent.getControllerId()).isEqualTo("target1");
|
||||
assertThat(targetAssignDistributionSetEvent.getActionId()).isEqualTo(22L);
|
||||
assertThat(targetAssignDistributionSetEvent.getSoftwareModules()).isEqualTo(softwareModuleList);
|
||||
assertThat(targetAssignDistributionSetEvent.getControllerId()).as("event has wrong controller id")
|
||||
.isEqualTo("target1");
|
||||
assertThat(targetAssignDistributionSetEvent.getActionId()).as("event has wrong action id").isEqualTo(22L);
|
||||
assertThat(targetAssignDistributionSetEvent.getSoftwareModules()).as("event has wrong sofware modules")
|
||||
.isEqualTo(softwareModuleList);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user