From 077e3c8d384a9c6ce56fd60b4d9efdaa34c7a69a Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Fri, 6 May 2016 08:16:12 +0200 Subject: [PATCH] add unit test for verification Signed-off-by: Michael Hirsch --- .../repository/TargetManagementTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java index 36fd2754b..a223c25b4 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java @@ -14,6 +14,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.net.URI; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -29,6 +30,7 @@ import javax.validation.ConstraintViolationException; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; +import org.eclipse.hawkbit.WithSpringAuthorityRule; import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.TenantNotExistException; @@ -724,4 +726,20 @@ public class TargetManagementTest extends AbstractIntegrationTest { assertThat(25).as("Targets with no tag").isEqualTo(targetsListWithNoTag.size()); } + + @Test + @Description("Tests the a target can be read with only the read target permission") + public void targetCanBeReadWithOnlyReadTargetPermission() throws Exception { + final String knownTargetControllerId = "readTarget"; + controllerManagament.findOrRegisterTargetIfItDoesNotexist(knownTargetControllerId, new URI("http://127.0.0.1")); + + securityRule.runAs(WithSpringAuthorityRule.withUser("bumlux", "READ_TARGET"), () -> { + final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownTargetControllerId); + assertThat(findTargetByControllerID).isNotNull(); + assertThat(findTargetByControllerID.getTargetInfo()).isNotNull(); + assertThat(findTargetByControllerID.getTargetInfo().getPollStatus()).isNotNull(); + return null; + }); + + } }