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

@@ -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"));