Fix Controller Management null address (#550)

* Forbid null address in controller management.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Constant.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix AMQP test.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2017-06-21 14:59:47 +02:00
committed by GitHub
parent 1c283d12c2
commit b6d73c578f
5 changed files with 26 additions and 16 deletions

View File

@@ -35,6 +35,7 @@ import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.repository.test.matcher.Expect;
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
@@ -428,11 +429,11 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
@Expect(type = ActionCreatedEvent.class, count = 1),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) })
@Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2) })
public void receiveDownLoadAndInstallMessageAfterAssignment() {
// setup
controllerManagement.findOrRegisterTargetIfItDoesNotexist(REGISTER_TARGET, null);
controllerManagement.findOrRegisterTargetIfItDoesNotexist(REGISTER_TARGET, TEST_URI);
final DistributionSet distributionSet = testdataFactory.createDistributionSet(UUID.randomUUID().toString());
assignDistributionSet(distributionSet.getId(), REGISTER_TARGET);
@@ -453,18 +454,19 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = CancelTargetAssignmentEvent.class, count = 1),
@Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 1),
@Expect(type = TargetPollEvent.class, count = 1) })
@Expect(type = TargetPollEvent.class, count = 2) })
public void receiveCancelUpdateMessageAfterAssignmentWasCanceled() {
// Setup
controllerManagement.findOrRegisterTargetIfItDoesNotexist(REGISTER_TARGET, null);
final Target target = controllerManagement.findOrRegisterTargetIfItDoesNotexist(REGISTER_TARGET, TEST_URI);
final DistributionSet distributionSet = testdataFactory.createDistributionSet(UUID.randomUUID().toString());
final DistributionSetAssignmentResult distributionSetAssignmentResult = assignDistributionSet(
distributionSet.getId(), REGISTER_TARGET);
deploymentManagement.cancelAction(distributionSetAssignmentResult.getActions().get(0));
// test
registerAndAssertTargetWithExistingTenant(REGISTER_TARGET, 1, TargetUpdateStatus.PENDING, "bumlux");
registerSameTargetAndAssertBasedOnLastPolling(REGISTER_TARGET, 1, TargetUpdateStatus.PENDING,
target.getLastTargetQuery());
// verify
assertCancelActionMessage(distributionSetAssignmentResult.getActions().get(0));

View File

@@ -8,10 +8,12 @@
*/
package org.eclipse.hawkbit.rabbitmq.test;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.eclipse.hawkbit.repository.jpa.RepositoryApplicationConfiguration;
import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest;
import org.eclipse.hawkbit.util.IpUtil;
import org.junit.Before;
import org.junit.Rule;
import org.springframework.amqp.core.Message;
@@ -35,6 +37,8 @@ import com.jayway.awaitility.core.ConditionFactory;
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public abstract class AbstractAmqpIntegrationTest extends AbstractIntegrationTest {
protected static final URI TEST_URI = IpUtil.createAmqpUri("testHost", "testExcange");
@Rule
@Autowired
public BrokerRunning brokerRunning;

View File

@@ -168,7 +168,7 @@ public interface ControllerManagement {
* @return target reference
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
Target findOrRegisterTargetIfItDoesNotexist(@NotEmpty String controllerId, URI address);
Target findOrRegisterTargetIfItDoesNotexist(@NotEmpty String controllerId, @NotNull URI address);
/**
* Retrieves last {@link Action} for a download of an artifact of given

View File

@@ -24,6 +24,7 @@ import javax.validation.ConstraintViolationException;
import org.apache.commons.lang3.RandomUtils;
import org.eclipse.hawkbit.repository.RepositoryProperties;
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
import org.eclipse.hawkbit.repository.event.remote.TargetPollEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.ActionCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent;
@@ -60,6 +61,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("Controller Management")
public class ControllerManagementTest extends AbstractJpaIntegrationTest {
private static final URI LOCALHOST = URI.create("http://127.0.0.1");
@Autowired
private RepositoryProperties repositoryProperties;
@@ -419,21 +421,21 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Register a controller which does not exist")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = TargetPollEvent.class, count = 2) })
public void findOrRegisterTargetIfItDoesNotexist() {
final Target target = controllerManagement.findOrRegisterTargetIfItDoesNotexist("AA", null);
final Target target = controllerManagement.findOrRegisterTargetIfItDoesNotexist("AA",
LOCALHOST);
assertThat(target).as("target should not be null").isNotNull();
final Target sameTarget = controllerManagement.findOrRegisterTargetIfItDoesNotexist("AA", null);
final Target sameTarget = controllerManagement.findOrRegisterTargetIfItDoesNotexist("AA",
LOCALHOST);
assertThat(target.getId()).as("Target should be the equals").isEqualTo(sameTarget.getId());
assertThat(targetRepository.count()).as("Only 1 target should be registred").isEqualTo(1L);
// throws exception
try {
controllerManagement.findOrRegisterTargetIfItDoesNotexist("", null);
fail("should fail as target does not exist");
} catch (final ConstraintViolationException e) {
}
assertThatExceptionOfType(ConstraintViolationException.class).isThrownBy(
() -> controllerManagement.findOrRegisterTargetIfItDoesNotexist("", LOCALHOST))
.as("register target with empty controllerId should fail");
}
@Test

View File

@@ -28,6 +28,7 @@ import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.TargetPollEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.ActionCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
@@ -797,7 +798,8 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Tests the a target can be read with only the read target permission")
@Expect(type = TargetCreatedEvent.class, count = 0)
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = TargetPollEvent.class, count = 1) })
public void targetCanBeReadWithOnlyReadTargetPermission() throws Exception {
final String knownTargetControllerId = "readTarget";
controllerManagement.findOrRegisterTargetIfItDoesNotexist(knownTargetControllerId, new URI("http://127.0.0.1"));