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:
@@ -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.Action.Status;
|
||||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
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.model.TargetUpdateStatus;
|
||||||
import org.eclipse.hawkbit.repository.test.matcher.Expect;
|
import org.eclipse.hawkbit.repository.test.matcher.Expect;
|
||||||
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
|
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 = ActionCreatedEvent.class, count = 1),
|
||||||
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
|
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
|
||||||
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
|
@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() {
|
public void receiveDownLoadAndInstallMessageAfterAssignment() {
|
||||||
|
|
||||||
// setup
|
// setup
|
||||||
controllerManagement.findOrRegisterTargetIfItDoesNotexist(REGISTER_TARGET, null);
|
controllerManagement.findOrRegisterTargetIfItDoesNotexist(REGISTER_TARGET, TEST_URI);
|
||||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet(UUID.randomUUID().toString());
|
final DistributionSet distributionSet = testdataFactory.createDistributionSet(UUID.randomUUID().toString());
|
||||||
assignDistributionSet(distributionSet.getId(), REGISTER_TARGET);
|
assignDistributionSet(distributionSet.getId(), REGISTER_TARGET);
|
||||||
|
|
||||||
@@ -453,18 +454,19 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra
|
|||||||
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
|
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
|
||||||
@Expect(type = CancelTargetAssignmentEvent.class, count = 1),
|
@Expect(type = CancelTargetAssignmentEvent.class, count = 1),
|
||||||
@Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.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() {
|
public void receiveCancelUpdateMessageAfterAssignmentWasCanceled() {
|
||||||
|
|
||||||
// Setup
|
// Setup
|
||||||
controllerManagement.findOrRegisterTargetIfItDoesNotexist(REGISTER_TARGET, null);
|
final Target target = controllerManagement.findOrRegisterTargetIfItDoesNotexist(REGISTER_TARGET, TEST_URI);
|
||||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet(UUID.randomUUID().toString());
|
final DistributionSet distributionSet = testdataFactory.createDistributionSet(UUID.randomUUID().toString());
|
||||||
final DistributionSetAssignmentResult distributionSetAssignmentResult = assignDistributionSet(
|
final DistributionSetAssignmentResult distributionSetAssignmentResult = assignDistributionSet(
|
||||||
distributionSet.getId(), REGISTER_TARGET);
|
distributionSet.getId(), REGISTER_TARGET);
|
||||||
deploymentManagement.cancelAction(distributionSetAssignmentResult.getActions().get(0));
|
deploymentManagement.cancelAction(distributionSetAssignmentResult.getActions().get(0));
|
||||||
|
|
||||||
// test
|
// test
|
||||||
registerAndAssertTargetWithExistingTenant(REGISTER_TARGET, 1, TargetUpdateStatus.PENDING, "bumlux");
|
registerSameTargetAndAssertBasedOnLastPolling(REGISTER_TARGET, 1, TargetUpdateStatus.PENDING,
|
||||||
|
target.getLastTargetQuery());
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
assertCancelActionMessage(distributionSetAssignmentResult.getActions().get(0));
|
assertCancelActionMessage(distributionSetAssignmentResult.getActions().get(0));
|
||||||
|
|||||||
@@ -8,10 +8,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.rabbitmq.test;
|
package org.eclipse.hawkbit.rabbitmq.test;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.repository.jpa.RepositoryApplicationConfiguration;
|
import org.eclipse.hawkbit.repository.jpa.RepositoryApplicationConfiguration;
|
||||||
import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest;
|
import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest;
|
||||||
|
import org.eclipse.hawkbit.util.IpUtil;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.springframework.amqp.core.Message;
|
import org.springframework.amqp.core.Message;
|
||||||
@@ -35,6 +37,8 @@ import com.jayway.awaitility.core.ConditionFactory;
|
|||||||
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
|
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
|
||||||
public abstract class AbstractAmqpIntegrationTest extends AbstractIntegrationTest {
|
public abstract class AbstractAmqpIntegrationTest extends AbstractIntegrationTest {
|
||||||
|
|
||||||
|
protected static final URI TEST_URI = IpUtil.createAmqpUri("testHost", "testExcange");
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
@Autowired
|
@Autowired
|
||||||
public BrokerRunning brokerRunning;
|
public BrokerRunning brokerRunning;
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ public interface ControllerManagement {
|
|||||||
* @return target reference
|
* @return target reference
|
||||||
*/
|
*/
|
||||||
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
@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
|
* Retrieves last {@link Action} for a download of an artifact of given
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import javax.validation.ConstraintViolationException;
|
|||||||
import org.apache.commons.lang3.RandomUtils;
|
import org.apache.commons.lang3.RandomUtils;
|
||||||
import org.eclipse.hawkbit.repository.RepositoryProperties;
|
import org.eclipse.hawkbit.repository.RepositoryProperties;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
|
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.ActionCreatedEvent;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent;
|
||||||
@@ -60,6 +61,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
|||||||
@Features("Component Tests - Repository")
|
@Features("Component Tests - Repository")
|
||||||
@Stories("Controller Management")
|
@Stories("Controller Management")
|
||||||
public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||||
|
private static final URI LOCALHOST = URI.create("http://127.0.0.1");
|
||||||
@Autowired
|
@Autowired
|
||||||
private RepositoryProperties repositoryProperties;
|
private RepositoryProperties repositoryProperties;
|
||||||
|
|
||||||
@@ -419,21 +421,21 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Register a controller which does not exist")
|
@Description("Register a controller which does not exist")
|
||||||
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
|
||||||
|
@Expect(type = TargetPollEvent.class, count = 2) })
|
||||||
public void findOrRegisterTargetIfItDoesNotexist() {
|
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();
|
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(target.getId()).as("Target should be the equals").isEqualTo(sameTarget.getId());
|
||||||
assertThat(targetRepository.count()).as("Only 1 target should be registred").isEqualTo(1L);
|
assertThat(targetRepository.count()).as("Only 1 target should be registred").isEqualTo(1L);
|
||||||
|
|
||||||
// throws exception
|
assertThatExceptionOfType(ConstraintViolationException.class).isThrownBy(
|
||||||
try {
|
() -> controllerManagement.findOrRegisterTargetIfItDoesNotexist("", LOCALHOST))
|
||||||
controllerManagement.findOrRegisterTargetIfItDoesNotexist("", null);
|
.as("register target with empty controllerId should fail");
|
||||||
fail("should fail as target does not exist");
|
|
||||||
} catch (final ConstraintViolationException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import org.apache.commons.lang3.RandomStringUtils;
|
|||||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
|
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent;
|
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.ActionCreatedEvent;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
|
||||||
@@ -797,7 +798,8 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Tests the a target can be read with only the read target permission")
|
@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 {
|
public void targetCanBeReadWithOnlyReadTargetPermission() throws Exception {
|
||||||
final String knownTargetControllerId = "readTarget";
|
final String knownTargetControllerId = "readTarget";
|
||||||
controllerManagement.findOrRegisterTargetIfItDoesNotexist(knownTargetControllerId, new URI("http://127.0.0.1"));
|
controllerManagement.findOrRegisterTargetIfItDoesNotexist(knownTargetControllerId, new URI("http://127.0.0.1"));
|
||||||
|
|||||||
Reference in New Issue
Block a user