Improve WithUser testing (#2943)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -39,6 +39,7 @@ import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import org.eclipse.hawkbit.auth.SpRole;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtId;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType;
|
||||
@@ -836,7 +837,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
|
||||
* Ensures that multiple DS requested are listed with expected payload.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void getDistributionSets() throws Exception {
|
||||
// prepare test data
|
||||
assertThat(distributionSetManagement.findAll(PAGE)).isEmpty();
|
||||
@@ -879,7 +880,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
|
||||
* Ensures that single DS requested by ID is listed with expected payload.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void getDistributionSet() throws Exception {
|
||||
final DistributionSet set = testdataFactory.createUpdatedDistributionSet();
|
||||
|
||||
@@ -915,7 +916,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
|
||||
* Ensures that multiple DS posted to API are created in the repository.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void createDistributionSets() throws Exception {
|
||||
assertThat(distributionSetManagement.findAll(PAGE)).isEmpty();
|
||||
final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP);
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import org.eclipse.hawkbit.auth.SpRole;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPost;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeAssignment;
|
||||
@@ -61,7 +62,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
|
||||
* Checks the correct behaviour of /rest/v1/distributionsettypes GET requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void getDistributionSetTypes() throws Exception {
|
||||
DistributionSetType testType = distributionSetTypeManagement.create(
|
||||
DistributionSetTypeManagement.Create.builder()
|
||||
@@ -103,7 +104,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
|
||||
* Checks the correct behaviour of /rest/v1/distributionsettypes GET requests with sorting by KEY.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void getDistributionSetTypesSortedByKey() throws Exception {
|
||||
DistributionSetType testType = distributionSetTypeManagement.create(
|
||||
DistributionSetTypeManagement.Create.builder()
|
||||
@@ -156,7 +157,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
|
||||
* Checks the correct behaviour of /rest/v1/distributionsettypes POST requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void createDistributionSetTypes() throws Exception {
|
||||
final MvcResult mvcResult = runPostDistributionSetType(createTestDistributionSetTestTypes());
|
||||
verifyCreatedDistributionSetTypes(mvcResult);
|
||||
@@ -166,7 +167,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
|
||||
* Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes POST requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void addMandatoryModuleToDistributionSetType() throws Exception {
|
||||
DistributionSetType testType = distributionSetTypeManagement.create(
|
||||
DistributionSetTypeManagement.Create.builder()
|
||||
@@ -192,7 +193,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
|
||||
* Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes POST requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void addOptionalModuleToDistributionSetType() throws Exception {
|
||||
DistributionSetType testType = distributionSetTypeManagement.create(
|
||||
DistributionSetTypeManagement.Create.builder()
|
||||
@@ -218,7 +219,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
|
||||
* Verifies quota enforcement for /rest/v1/distributionsettypes/{ID}/optionalmoduletypes POST requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void assignModuleTypesToDistributionSetTypeUntilQuotaExceeded() throws Exception {
|
||||
// create software module types
|
||||
final int maxSoftwareModuleTypes = quotaManagement.getMaxSoftwareModuleTypesPerDistributionSetType();
|
||||
@@ -278,7 +279,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
|
||||
* Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes GET requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void getMandatoryModulesOfDistributionSetType() throws Exception {
|
||||
final DistributionSetType testType = generateTestType();
|
||||
|
||||
@@ -297,7 +298,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
|
||||
* Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes GET requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void getOptionalModulesOfDistributionSetType() throws Exception {
|
||||
final DistributionSetType testType = generateTestType();
|
||||
|
||||
@@ -316,7 +317,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
|
||||
* Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes/{ID} GET requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void getMandatoryModuleOfDistributionSetType() throws Exception {
|
||||
final DistributionSetType testType = generateTestType();
|
||||
|
||||
@@ -337,7 +338,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
|
||||
* Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes/{ID} GET requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void getOptionalModuleOfDistributionSetType() throws Exception {
|
||||
final DistributionSetType testType = generateTestType();
|
||||
|
||||
@@ -358,7 +359,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
|
||||
* Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes/{ID} DELETE requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void removeMandatoryModuleToDistributionSetType() throws Exception {
|
||||
DistributionSetType testType = generateTestType();
|
||||
|
||||
@@ -377,7 +378,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
|
||||
* Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes/{ID} DELETE requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void removeOptionalModuleToDistributionSetType() throws Exception {
|
||||
DistributionSetType testType = generateTestType();
|
||||
|
||||
@@ -396,7 +397,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
|
||||
* Checks the correct behaviour of /rest/v1/distributionsettypes/{ID} GET requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void getDistributionSetType() throws Exception {
|
||||
DistributionSetType testType = distributionSetTypeManagement.create(DistributionSetTypeManagement.Create.builder()
|
||||
.key("test123").name("TestName123").description("Desc123").build());
|
||||
@@ -431,7 +432,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
|
||||
* Checks the correct behaviour of /rest/v1/DistributionSetTypes/{ID} DELETE requests (hard delete scenario).
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void deleteDistributionSetTypeUnused() throws Exception {
|
||||
final DistributionSetType testType = distributionSetTypeManagement.create(
|
||||
DistributionSetTypeManagement.Create.builder()
|
||||
@@ -460,7 +461,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
|
||||
* Checks the correct behaviour of /rest/v1/DistributionSetTypes/{ID} DELETE requests (soft delete scenario).
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void deleteDistributionSetTypeUsed() throws Exception {
|
||||
final DistributionSetType testType = distributionSetTypeManagement.create(
|
||||
DistributionSetTypeManagement.Create.builder()
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.util.stream.Stream;
|
||||
|
||||
import org.awaitility.Awaitility;
|
||||
import org.awaitility.core.ConditionFactory;
|
||||
import org.eclipse.hawkbit.auth.SpRole;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutResponseBody;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
@@ -344,21 +345,6 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andExpect(jsonPath("errorCode", equalTo("hawkbit.server.error.rest.body.notReadable")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing that creating rollout with insufficient permission returns forbidden
|
||||
*/
|
||||
@Test
|
||||
@WithUser(allSpPermissions = true, removeFromAllPermission = "CREATE_ROLLOUT")
|
||||
void createRolloutWithInsufficientPermissionReturnsForbidden() throws Exception {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
mvc.perform(post("/rest/v1/rollouts")
|
||||
.content(JsonBuilder.rollout("name", "desc", 10, dsA.getId(), "name==test", null))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().is(403))
|
||||
.andReturn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing that creating rollout with not existing distribution set returns not found
|
||||
*/
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.eclipse.hawkbit.artifact.exception.ArtifactBinaryNotFoundException;
|
||||
import org.eclipse.hawkbit.artifact.exception.FileSizeQuotaExceededException;
|
||||
import org.eclipse.hawkbit.artifact.exception.StorageQuotaExceededException;
|
||||
import org.eclipse.hawkbit.artifact.model.ArtifactStream;
|
||||
import org.eclipse.hawkbit.auth.SpRole;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModule;
|
||||
@@ -219,7 +220,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
* Tests the update of software module metadata. It is verified that only the selected fields for the update are really updated and the modification values are filled (i.e. updated by and at).
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "smUpdateTester", allSpPermissions = true)
|
||||
@WithUser(principal = "smUpdateTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void updateSoftwareModuleOnlyDescriptionAndVendorNameUntouched() throws Exception {
|
||||
final String knownSWName = "name1";
|
||||
final String knownSWVersion = "version1";
|
||||
@@ -272,7 +273,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
* Tests the update of the deletion flag. It is verified that the software module can't be marked as deleted through update operation.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "smUpdateTester", allSpPermissions = true)
|
||||
@WithUser(principal = "smUpdateTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void updateSoftwareModuleDeletedFlag() throws Exception {
|
||||
final String knownSWName = "name1";
|
||||
final String knownSWVersion = "version1";
|
||||
@@ -307,7 +308,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
* Tests the lock. It is verified that the software module can be marked as locked through update operation.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "smUpdateTester", allSpPermissions = true)
|
||||
@WithUser(principal = "smUpdateTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void lockSoftwareModule() throws Exception {
|
||||
final SoftwareModule sm = softwareModuleManagement.create(
|
||||
SoftwareModuleManagement.Create.builder().type(osType).name("name1").version("version1").build());
|
||||
@@ -338,7 +339,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
* Tests the unlock.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "smUpdateTester", allSpPermissions = true)
|
||||
@WithUser(principal = "smUpdateTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void unlockSoftwareModule() throws Exception {
|
||||
final SoftwareModule sm = softwareModuleManagement.create(
|
||||
SoftwareModuleManagement.Create.builder().type(osType).name("name1").version("version1").build());
|
||||
@@ -1105,7 +1106,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
* Test retrieval of all software modules the user has access to.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void getSoftwareModules() throws Exception {
|
||||
final SoftwareModule os = testdataFactory.createSoftwareModuleOs();
|
||||
final SoftwareModule app = testdataFactory.createSoftwareModuleApp();
|
||||
@@ -1231,7 +1232,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
* Tests GET request on /rest/v1/softwaremodules/{smId}.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void getSoftwareModule() throws Exception {
|
||||
final SoftwareModule os = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
@@ -1261,7 +1262,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
* Verifies that the create request actually results in the creation of the modules in the repository.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
void createSoftwareModules() throws Exception {
|
||||
final MgmtSoftwareModuleRequestBodyPost os = new MgmtSoftwareModuleRequestBodyPost()
|
||||
.setType(osType.getKey())
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import org.eclipse.hawkbit.auth.SpRole;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
||||
@@ -52,7 +53,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
|
||||
* Checks the correct behaviour of /rest/v1/softwaremoduletypes GET requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
public void getSoftwareModuleTypes() throws Exception {
|
||||
final SoftwareModuleType testType = createTestType();
|
||||
|
||||
@@ -98,7 +99,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
|
||||
* Handles the GET request of retrieving all software module types within SP with parameters. In this case the first 10 result in ascending order by name where the name starts with 'a'.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
public void getSoftwareModuleTypesWithParameters() throws Exception {
|
||||
final SoftwareModuleType testType = testdataFactory.findOrCreateSoftwareModuleType("test123");
|
||||
softwareModuleTypeManagement
|
||||
@@ -115,7 +116,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
|
||||
* Checks the correct behaviour of /rest/v1/softwaremoduletypes GET requests with sorting by MAXASSIGNMENTS field.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
public void getSoftwareModuleTypesSortedByMaxAssignments() throws Exception {
|
||||
final SoftwareModuleType testType = createTestType();
|
||||
|
||||
@@ -159,7 +160,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
|
||||
* Checks the correct behaviour of /rest/v1/softwaremoduletypes POST requests when max assignment is smaller than 1
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
public void createSoftwareModuleTypesInvalidAssignmentBadRequest() throws Exception {
|
||||
|
||||
final List<SoftwareModuleTypeManagement.Create> types = new ArrayList<>();
|
||||
@@ -183,7 +184,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
|
||||
* Checks the correct behaviour of /rest/v1/softwaremoduletypes POST requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
public void createSoftwareModuleTypes() throws Exception {
|
||||
|
||||
final List<SoftwareModuleTypeManagement.Create> types = Arrays.asList(
|
||||
@@ -236,7 +237,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
|
||||
* Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} GET requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
public void getSoftwareModuleType() throws Exception {
|
||||
final SoftwareModuleType testType = createTestType();
|
||||
|
||||
@@ -259,7 +260,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
|
||||
* Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} DELETE requests (hard delete scenario).
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
public void deleteSoftwareModuleTypeUnused() throws Exception {
|
||||
final SoftwareModuleType testType = createTestType();
|
||||
|
||||
@@ -286,7 +287,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
|
||||
* Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} DELETE requests (soft delete scenario).
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@WithUser(principal = "uploadTester", authorities = SpRole.TENANT_ADMIN)
|
||||
public void deleteSoftwareModuleTypeUsed() throws Exception {
|
||||
final SoftwareModuleType testType = createTestType();
|
||||
softwareModuleManagement.create(SoftwareModuleManagement.Create.builder().type(testType).name("name").version("version").build());
|
||||
|
||||
@@ -413,7 +413,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Ensures that security token is not returned if user does not have READ_TARGET_SEC_TOKEN permission.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(allSpPermissions = false, authorities = { SpPermission.READ_TARGET, SpPermission.CREATE_TARGET })
|
||||
@WithUser(authorities = { SpPermission.READ_TARGET, SpPermission.CREATE_TARGET })
|
||||
void securityTokenIsNotInResponseIfMissingPermission() throws Exception {
|
||||
|
||||
final String knownControllerId = "knownControllerId";
|
||||
@@ -428,10 +428,8 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Ensures that security token is returned if user does have READ_TARGET_SEC_TOKEN permission.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(allSpPermissions = false, authorities = { SpPermission.READ_TARGET, SpPermission.CREATE_TARGET,
|
||||
SpPermission.READ_TARGET_SECURITY_TOKEN })
|
||||
@WithUser(authorities = { SpPermission.READ_TARGET, SpPermission.CREATE_TARGET, SpPermission.READ_TARGET_SECURITY_TOKEN })
|
||||
void securityTokenIsInResponseWithCorrectPermission() throws Exception {
|
||||
|
||||
final String knownControllerId = "knownControllerId";
|
||||
final Target createTarget = testdataFactory.createTarget(knownControllerId);
|
||||
mvc.perform(get(TARGETS_V1 + "/{targetId}", knownControllerId))
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.Set;
|
||||
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import org.eclipse.hawkbit.auth.SpPermission;
|
||||
import org.eclipse.hawkbit.auth.SpRole;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtId;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi;
|
||||
@@ -43,6 +44,7 @@ import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter;
|
||||
import org.json.JSONObject;
|
||||
@@ -71,22 +73,25 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* GET targettypes returns Forbidden when permission is missing
|
||||
*/
|
||||
@Test
|
||||
@WithUser(
|
||||
principal = "targetTypeTester", allSpPermissions = true,
|
||||
removeFromAllPermission = {
|
||||
SpPermission.CREATE_TARGET, SpPermission.READ_TARGET, SpPermission.UPDATE_TARGET, SpPermission.DELETE_TARGET,
|
||||
SpPermission.READ_TARGET_TYPE })
|
||||
void getTargetTypesWithoutPermission() throws Exception {
|
||||
mvc.perform(get(TARGETTYPES_ENDPOINT).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isForbidden());
|
||||
SecurityContextSwitch.callAs(
|
||||
SecurityContextSwitch.withUser("test", SpPermission.READ_TARGET_TYPE),
|
||||
() -> mvc.perform(get(TARGETTYPES_ENDPOINT).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk()));
|
||||
SecurityContextSwitch.callAs(
|
||||
SecurityContextSwitch.withUser("test", SpPermission.READ_SOFTWARE_MODULE_ARTIFACT),
|
||||
() -> mvc.perform(get(TARGETTYPES_ENDPOINT).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isForbidden()));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the correct behaviour of /rest/v1/targettypes/{id} GET request.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void getTargetType() throws Exception {
|
||||
String typeName = "TestTypeGET";
|
||||
TargetType testType = createTestTargetTypeInDB(typeName);
|
||||
@@ -115,7 +120,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Checks the correct behaviour of /rest/v1/targettypes GET requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void getTargetTypes() throws Exception {
|
||||
String typeName = "TestTypeGET";
|
||||
int count = 5;
|
||||
@@ -155,7 +160,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Checks the correct behaviour of /rest/v1/targettypes GET requests without prior created target types.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void getDefaultTargetTypes() throws Exception {
|
||||
|
||||
// 0 types overall (no default types are created)
|
||||
@@ -172,7 +177,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Checks the correct behaviour of /rest/v1/targettypes GET requests with sorting by name.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void getTargetTypesSortedByName() throws Exception {
|
||||
String typeNameA = "ATestTypeGETsorted";
|
||||
String typeNameB = "BTestTypeGETsorted";
|
||||
@@ -238,7 +243,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Checks the correct behaviour of /rest/v1/targettypes GET requests with paging.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void getTargetTypesWithPagingLimitRequestParameter() throws Exception {
|
||||
final String typePrefix = "TestTypeGETPaging";
|
||||
final int count = 10;
|
||||
@@ -258,7 +263,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Checks the correct behaviour of /rest/v1/targettypes GET requests with paging and offset.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void getTargetTypesWithPagingLimitAndOffsetRequestParameter() throws Exception {
|
||||
final int count = 10;
|
||||
final int offset = 2;
|
||||
@@ -280,7 +285,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Checks the correct behaviour of /rest/v1/targettypes/{ID} PUT requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void updateTargetType() throws Exception {
|
||||
String typeName = "TestTypePUT";
|
||||
final TargetType testType = createTestTargetTypeInDB(typeName);
|
||||
@@ -302,7 +307,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Checks the correct behaviour of /rest/v1/targettypes/{id} GET requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void getUpdatedTargetType() throws Exception {
|
||||
final String initialTypeName = "TestTypeGET";
|
||||
TargetType testType = createTestTargetTypeInDB(initialTypeName);
|
||||
@@ -330,7 +335,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Checks the correct behaviour of /rest/v1/targettypes POST requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void createTargetTypes() throws Exception {
|
||||
String typeName = "TestTypePOST";
|
||||
final List<Create> types = buildTestTargetTypesWithoutDsTypes(typeName, 5);
|
||||
@@ -342,7 +347,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Checks the correct behaviour of /rest/v1/targettypes/{ID}/compatibledistributionsettypes POST requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void addDistributionSetTypeToTargetType() throws Exception {
|
||||
String typeName = "TestTypeAddDs";
|
||||
TargetType testType = createTestTargetTypeInDB(typeName);
|
||||
@@ -363,7 +368,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Checks the correct behaviour of /rest/v1/targettypes/{ID}/compatibledistributionsettypes GET requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void getDistributionSetsOfTargetType() throws Exception {
|
||||
String typeName = "TestTypeGetDs";
|
||||
final TargetType testType = createTestTargetTypeInDB(typeName, Set.of(standardDsType));
|
||||
@@ -383,7 +388,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Checks the correct behaviour of /rest/v1/targettypes/{ID}/compatibledistributionsettypes/{ID} GET requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void getDistributionSetOfTargetTypeReturnsNotAllowed() throws Exception {
|
||||
String typeName = "TestTypeAddDs";
|
||||
final TargetType testType = createTestTargetTypeInDB(typeName);
|
||||
@@ -399,7 +404,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Checks the correct behaviour of /rest/v1/targettypes/{ID}/compatibledistributionsettypes/{ID} DELETE requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void removeDsTypeFromTargetType() throws Exception {
|
||||
String typeName = "TestTypeRemoveDs";
|
||||
TargetType testType = createTestTargetTypeInDB(typeName, Set.of(standardDsType));
|
||||
@@ -419,7 +424,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Checks the correct behaviour of /rest/v1/distributionsettypes/{ID} DELETE requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void deletingDsTypeRemovesAssignmentFromTargetType() throws Exception {
|
||||
TargetType testType = createTestTargetTypeInDB("TestTypeRemoveDs", Set.of(standardDsType));
|
||||
assertThat(testType.getDistributionSetTypes()).hasSize(1);
|
||||
@@ -440,7 +445,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Checks the correct behaviour of /rest/v1/targettypes/{ID} DELETE requests - Deletion when not in use.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void deleteTargetTypeUnused() throws Exception {
|
||||
String typeName = "TestTypeUnusedDelete";
|
||||
final TargetType testType = createTestTargetTypeInDB(typeName);
|
||||
@@ -458,7 +463,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Checks the correct behaviour of /rest/v1/targettypes/{ID} DELETE requests - Deletion not possible when in use.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void deleteTargetTypeUsed() throws Exception {
|
||||
String typeName = "TestTypeUsedDelete";
|
||||
final TargetType testType = createTestTargetTypeInDB(typeName);
|
||||
@@ -481,7 +486,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Ensures that target type deletion request to API on an entity that does not exist results in NOT_FOUND.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void deleteTargetTypeThatDoesNotExistLeadsToNotFound() throws Exception {
|
||||
mvc.perform(delete(TARGETTYPE_SINGLE_ENDPOINT, 1234))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
@@ -492,7 +497,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Tests the update of the deletion flag. It is verified that the target type can't be marked as deleted through update operation.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void updateTargetTypeDeletedFlag() throws Exception {
|
||||
String typeName = "TestTypePUT";
|
||||
final TargetType testType = createTestTargetTypeInDB(typeName);
|
||||
@@ -630,7 +635,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
* Verifies quota enforcement for /rest/v1/targettypes/{ID}/compatibledistributionsettypes POST requests.
|
||||
*/
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@WithUser(principal = TEST_USER, authorities = SpRole.TENANT_ADMIN)
|
||||
void assignDistributionSetTypeToTargetTypeUntilQuotaExceeded() throws Exception {
|
||||
final TargetType testType = createTestTargetTypeInDB("TestTypeQuota");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user