Remove unused DistributionSetManagement#findByDistributionSetFilterOrderByLinkedTarget (#2141)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -41,12 +41,9 @@ public abstract class AbstractAccessControllerTest extends AbstractJpaIntegratio
|
||||
}
|
||||
|
||||
protected void permitAllOperations(final AccessController.Operation operation) {
|
||||
testAccessControlManger.defineAccessRule(
|
||||
JpaTarget.class, operation, Specification.where(null), type -> true);
|
||||
testAccessControlManger.defineAccessRule(
|
||||
JpaTargetType.class, operation, Specification.where(null), type -> true);
|
||||
testAccessControlManger.defineAccessRule(
|
||||
JpaDistributionSet.class, operation, Specification.where(null), type -> true);
|
||||
testAccessControlManger.defineAccessRule(JpaTarget.class, operation, Specification.where(null), type -> true);
|
||||
testAccessControlManger.defineAccessRule(JpaTargetType.class, operation, Specification.where(null), type -> true);
|
||||
testAccessControlManger.defineAccessRule(JpaDistributionSet.class, operation, Specification.where(null), type -> true);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
@@ -79,17 +76,17 @@ public abstract class AbstractAccessControllerTest extends AbstractJpaIntegratio
|
||||
|
||||
@Override
|
||||
public Optional<Specification<JpaTarget>> getAccessRules(final Operation operation) {
|
||||
if (contextAware.getCurrentTenant() != null && SecurityContextTenantAware.SYSTEM_USER.equals(
|
||||
contextAware.getCurrentUsername())) {
|
||||
if (contextAware.getCurrentTenant() != null
|
||||
&& SecurityContextTenantAware.SYSTEM_USER.equals(contextAware.getCurrentUsername())) {
|
||||
// as tenant, no restrictions
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return Optional.ofNullable(testAccessControlManger.getAccessRule(JpaTarget.class, operation));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assertOperationAllowed(final Operation operation, final JpaTarget entity)
|
||||
throws InsufficientPermissionException {
|
||||
public void assertOperationAllowed(final Operation operation, final JpaTarget entity) throws InsufficientPermissionException {
|
||||
testAccessControlManger.assertOperation(JpaTarget.class, operation, List.of(entity));
|
||||
}
|
||||
|
||||
@@ -101,17 +98,17 @@ public abstract class AbstractAccessControllerTest extends AbstractJpaIntegratio
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AccessController<JpaTargetType> targetTypeAccessController(
|
||||
final TestAccessControlManger testAccessControlManger) {
|
||||
public AccessController<JpaTargetType> targetTypeAccessController(final TestAccessControlManger testAccessControlManger) {
|
||||
return new AccessController<>() {
|
||||
|
||||
@Override
|
||||
public Optional<Specification<JpaTargetType>> getAccessRules(final Operation operation) {
|
||||
if (contextAware.getCurrentTenant() != null && SecurityContextTenantAware.SYSTEM_USER.equals(
|
||||
contextAware.getCurrentUsername())) {
|
||||
if (contextAware.getCurrentTenant() != null
|
||||
&& SecurityContextTenantAware.SYSTEM_USER.equals(contextAware.getCurrentUsername())) {
|
||||
// as tenant, no restrictions
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return Optional.ofNullable(testAccessControlManger.getAccessRule(JpaTargetType.class, operation));
|
||||
}
|
||||
|
||||
@@ -129,17 +126,17 @@ public abstract class AbstractAccessControllerTest extends AbstractJpaIntegratio
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AccessController<JpaDistributionSet> distributionSetAccessController(
|
||||
final TestAccessControlManger testAccessControlManger) {
|
||||
public AccessController<JpaDistributionSet> distributionSetAccessController(final TestAccessControlManger testAccessControlManger) {
|
||||
return new AccessController<>() {
|
||||
|
||||
@Override
|
||||
public Optional<Specification<JpaDistributionSet>> getAccessRules(final Operation operation) {
|
||||
if (contextAware.getCurrentTenant() != null && SecurityContextTenantAware.SYSTEM_USER.equals(
|
||||
contextAware.getCurrentUsername())) {
|
||||
if (contextAware.getCurrentTenant() != null
|
||||
&& SecurityContextTenantAware.SYSTEM_USER.equals(contextAware.getCurrentUsername())) {
|
||||
// as tenant, no restrictions
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return Optional.ofNullable(testAccessControlManger.getAccessRule(JpaDistributionSet.class, operation));
|
||||
}
|
||||
|
||||
@@ -156,4 +153,4 @@ public abstract class AbstractAccessControllerTest extends AbstractJpaIntegratio
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,9 +13,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
@@ -26,8 +29,8 @@ import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
|
||||
import org.eclipse.hawkbit.repository.jpa.acm.AccessController;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetSpecification;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
@@ -37,6 +40,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
@Feature("Component Tests - Access Control")
|
||||
@Story("Test Distribution Set Access Controller")
|
||||
@@ -136,47 +140,43 @@ class DistributionSetAccessControllerTest extends AbstractAccessControllerTest {
|
||||
defineAccess(AccessController.Operation.UPDATE, permitted);
|
||||
|
||||
// verify distributionSetManagement#assignSoftwareModules
|
||||
assertThat(distributionSetManagement.assignSoftwareModules(permitted.getId(),
|
||||
Collections.singletonList(swModule.getId()))).satisfies(ds -> {
|
||||
assertThat(ds.getModules().stream().map(Identifiable::getId).toList()).contains(swModule.getId());
|
||||
});
|
||||
assertThatThrownBy(() -> {
|
||||
distributionSetManagement.assignSoftwareModules(readOnly.getId(),
|
||||
Collections.singletonList(swModule.getId()));
|
||||
}).as("Distribution set not allowed to me modified.").isInstanceOf(EntityNotFoundException.class);
|
||||
assertThatThrownBy(() -> {
|
||||
distributionSetManagement.assignSoftwareModules(hidden.getId(),
|
||||
Collections.singletonList(swModule.getId()));
|
||||
}).as("Distribution set should not be visible.").isInstanceOf(EntityNotFoundException.class);
|
||||
assertThat(distributionSetManagement.assignSoftwareModules(permitted.getId(), Collections.singletonList(swModule.getId())))
|
||||
.satisfies(ds -> assertThat(ds.getModules().stream().map(Identifiable::getId).toList()).contains(swModule.getId()));
|
||||
assertThatThrownBy(() -> distributionSetManagement.assignSoftwareModules(readOnly.getId(), Collections.singletonList(swModule.getId())))
|
||||
.as("Distribution set not allowed to me modified.")
|
||||
.isInstanceOf(EntityNotFoundException.class);
|
||||
assertThatThrownBy(() -> distributionSetManagement.assignSoftwareModules(hidden.getId(), Collections.singletonList(swModule.getId())))
|
||||
.as("Distribution set should not be visible.")
|
||||
.isInstanceOf(EntityNotFoundException.class);
|
||||
|
||||
final JpaDistributionSetMetadata metadata = new JpaDistributionSetMetadata("test", "test");
|
||||
|
||||
// verify distributionSetManagement#createMetaData
|
||||
distributionSetManagement.createMetaData(permitted.getId(), Collections.singletonList(metadata));
|
||||
assertThatThrownBy(() -> {
|
||||
distributionSetManagement.createMetaData(readOnly.getId(), Collections.singletonList(metadata));
|
||||
}).as("Distribution set not allowed to me modified.").isInstanceOf(EntityNotFoundException.class);
|
||||
assertThatThrownBy(() -> {
|
||||
distributionSetManagement.createMetaData(hidden.getId(), Collections.singletonList(metadata));
|
||||
}).as("Distribution set should not be visible.").isInstanceOf(EntityNotFoundException.class);
|
||||
assertThatThrownBy(() -> distributionSetManagement.createMetaData(readOnly.getId(), Collections.singletonList(metadata)))
|
||||
.as("Distribution set not allowed to me modified.")
|
||||
.isInstanceOf(EntityNotFoundException.class);
|
||||
assertThatThrownBy(() -> distributionSetManagement.createMetaData(hidden.getId(), Collections.singletonList(metadata)))
|
||||
.as("Distribution set should not be visible.")
|
||||
.isInstanceOf(EntityNotFoundException.class);
|
||||
|
||||
// verify distributionSetManagement#updateMetaData
|
||||
distributionSetManagement.updateMetaData(permitted.getId(), metadata);
|
||||
assertThatThrownBy(() -> {
|
||||
distributionSetManagement.updateMetaData(readOnly.getId(), metadata);
|
||||
}).as("Distribution set not allowed to me modified.").isInstanceOf(EntityNotFoundException.class);
|
||||
assertThatThrownBy(() -> {
|
||||
distributionSetManagement.updateMetaData(hidden.getId(), metadata);
|
||||
}).as("Distribution set should not be visible.").isInstanceOf(EntityNotFoundException.class);
|
||||
assertThatThrownBy(() -> distributionSetManagement.updateMetaData(readOnly.getId(), metadata))
|
||||
.as("Distribution set not allowed to me modified.")
|
||||
.isInstanceOf(EntityNotFoundException.class);
|
||||
assertThatThrownBy(() -> distributionSetManagement.updateMetaData(hidden.getId(), metadata))
|
||||
.as("Distribution set should not be visible.")
|
||||
.isInstanceOf(EntityNotFoundException.class);
|
||||
|
||||
// verify distributionSetManagement#deleteMetaData
|
||||
distributionSetManagement.deleteMetaData(permitted.getId(), metadata.getKey());
|
||||
assertThatThrownBy(() -> {
|
||||
distributionSetManagement.deleteMetaData(readOnly.getId(), metadata.getKey());
|
||||
}).as("Distribution set not allowed to me modified.").isInstanceOf(EntityNotFoundException.class);
|
||||
assertThatThrownBy(() -> {
|
||||
distributionSetManagement.deleteMetaData(hidden.getId(), metadata.getKey());
|
||||
}).as("Distribution set should not be visible.").isInstanceOf(EntityNotFoundException.class);
|
||||
assertThatThrownBy(() -> distributionSetManagement.deleteMetaData(readOnly.getId(), metadata.getKey()))
|
||||
.as("Distribution set not allowed to me modified.")
|
||||
.isInstanceOf(EntityNotFoundException.class);
|
||||
assertThatThrownBy(() -> distributionSetManagement.deleteMetaData(hidden.getId(), metadata.getKey()))
|
||||
.as("Distribution set should not be visible.")
|
||||
.isInstanceOf(EntityNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -303,7 +303,15 @@ class DistributionSetAccessControllerTest extends AbstractAccessControllerTest {
|
||||
final List<Long> ids = targets.stream().map(DistributionSet::getId).toList();
|
||||
testAccessControlManger.defineAccessRule(
|
||||
JpaDistributionSet.class, operation,
|
||||
DistributionSetSpecification.byIds(ids),
|
||||
dsByIds(ids),
|
||||
distributionSet -> ids.contains(distributionSet.getId()));
|
||||
}
|
||||
|
||||
private static Specification<JpaDistributionSet> dsByIds(final Collection<Long> distids) {
|
||||
return (dsRoot, query, cb) -> {
|
||||
final Predicate predicate = dsRoot.get(JpaDistributionSet_.id).in(distids);
|
||||
query.distinct(true);
|
||||
return predicate;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
@@ -25,8 +27,8 @@ import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
|
||||
import org.eclipse.hawkbit.repository.jpa.acm.AccessController;
|
||||
import org.eclipse.hawkbit.repository.jpa.autoassign.AutoAssignChecker;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetSpecification;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
@@ -39,6 +41,7 @@ import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
@Feature("Component Tests - Access Control")
|
||||
@Story("Test Target Access Controller")
|
||||
@@ -75,13 +78,14 @@ class TargetAccessControllerTest extends AbstractAccessControllerTest {
|
||||
|
||||
// verify targetManagement#getByControllerID
|
||||
assertThat(targetManagement.getByControllerID(permittedTarget.getControllerId())).isPresent();
|
||||
assertThatThrownBy(() -> targetManagement.getByControllerID(hiddenTarget.getControllerId()))
|
||||
final String hiddenTargetControllerId = hiddenTarget.getControllerId();
|
||||
assertThatThrownBy(() -> targetManagement.getByControllerID(hiddenTargetControllerId))
|
||||
.as("Missing read permissions for hidden target.")
|
||||
.isInstanceOf(InsufficientPermissionException.class);
|
||||
|
||||
// verify targetManagement#getByControllerID
|
||||
assertThat(targetManagement
|
||||
.getByControllerID(Arrays.asList(permittedTarget.getControllerId(), hiddenTarget.getControllerId()))
|
||||
.getByControllerID(Arrays.asList(permittedTarget.getControllerId(), hiddenTargetControllerId))
|
||||
.stream().map(Identifiable::getId).toList()).containsOnly(permittedTarget.getId());
|
||||
|
||||
// verify targetManagement#get
|
||||
@@ -94,9 +98,9 @@ class TargetAccessControllerTest extends AbstractAccessControllerTest {
|
||||
|
||||
// verify targetManagement#getControllerAttributes
|
||||
assertThat(targetManagement.getControllerAttributes(permittedTarget.getControllerId())).isEmpty();
|
||||
assertThatThrownBy(() -> {
|
||||
assertThat(targetManagement.getControllerAttributes(hiddenTarget.getControllerId())).isEmpty();
|
||||
}).as("Target should not be found.").isInstanceOf(InsufficientPermissionException.class);
|
||||
assertThatThrownBy(() -> targetManagement.getControllerAttributes(hiddenTargetControllerId))
|
||||
.as("Target should not be found.")
|
||||
.isInstanceOf(InsufficientPermissionException.class);
|
||||
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
||||
.create(entityFactory.targetFilterQuery().create().name("test").query("id==*"));
|
||||
@@ -149,16 +153,13 @@ class TargetAccessControllerTest extends AbstractAccessControllerTest {
|
||||
.map(Identifiable::getId).toList()).containsOnly(permittedTarget.getId(), readOnlyTarget.getId());
|
||||
|
||||
// verify targetManagement#assignTag on permitted target
|
||||
assertThat(targetManagement
|
||||
.assignTag(Collections.singletonList(permittedTarget.getControllerId()), myTag.getId())
|
||||
.size()).isEqualTo(1);
|
||||
assertThat(targetManagement.assignTag(Collections.singletonList(permittedTarget.getControllerId()), myTag.getId()))
|
||||
.hasSize(1);
|
||||
// verify targetManagement#unassignTag on permitted target
|
||||
assertThat(targetManagement
|
||||
.unassignTag(Collections.singletonList(permittedTarget.getControllerId()), myTag.getId())
|
||||
.size()).isEqualTo(1);
|
||||
assertThat(targetManagement.unassignTag(Collections.singletonList(permittedTarget.getControllerId()), myTag.getId()))
|
||||
.hasSize(1);
|
||||
// verify targetManagement#assignTag on permitted target
|
||||
assertThat(
|
||||
targetManagement.assignTag(Collections.singletonList(permittedTarget.getControllerId()), myTag.getId()))
|
||||
assertThat(targetManagement.assignTag(Collections.singletonList(permittedTarget.getControllerId()), myTag.getId()))
|
||||
.hasSize(1);
|
||||
// verify targetManagement#unAssignTag on permitted target
|
||||
assertThat(targetManagement.unassignTag(List.of(permittedTarget.getControllerId()), myTag.getId()).get(0).getControllerId())
|
||||
@@ -174,29 +175,23 @@ class TargetAccessControllerTest extends AbstractAccessControllerTest {
|
||||
// .isInstanceOf(InsufficientPermissionException.class);
|
||||
|
||||
// assignment is denied for readOnlyTarget (read, but no update permissions)
|
||||
assertThatThrownBy(() -> {
|
||||
targetManagement.assignTag(Collections.singletonList(readOnlyTarget.getControllerId()), myTag.getId());
|
||||
}).as("Missing update permissions for target to toggle tag assignment.")
|
||||
assertThatThrownBy(() -> targetManagement.assignTag(Collections.singletonList(readOnlyTarget.getControllerId()), myTag.getId()))
|
||||
.as("Missing update permissions for target to toggle tag assignment.")
|
||||
.isInstanceOfAny(InsufficientPermissionException.class);
|
||||
|
||||
// assignment is denied for readOnlyTarget (read, but no update permissions)
|
||||
assertThatThrownBy(() -> {
|
||||
targetManagement.unassignTag(List.of(readOnlyTarget.getControllerId()), myTag.getId());
|
||||
}).as("Missing update permissions for target to toggle tag assignment.")
|
||||
assertThatThrownBy(() -> targetManagement.unassignTag(List.of(readOnlyTarget.getControllerId()), myTag.getId()))
|
||||
.as("Missing update permissions for target to toggle tag assignment.")
|
||||
.isInstanceOf(InsufficientPermissionException.class);
|
||||
|
||||
// assignment is denied for hiddenTarget since it's hidden
|
||||
assertThatThrownBy(() -> {
|
||||
targetManagement
|
||||
.assignTag(Collections.singletonList(hiddenTarget.getControllerId()), myTag.getId())
|
||||
.size();
|
||||
}).as("Missing update permissions for target to toggle tag assignment.")
|
||||
assertThatThrownBy(() -> targetManagement.assignTag(Collections.singletonList(hiddenTarget.getControllerId()), myTag.getId()))
|
||||
.as("Missing update permissions for target to toggle tag assignment.")
|
||||
.isInstanceOf(InsufficientPermissionException.class);
|
||||
|
||||
// assignment is denied for hiddenTarget since it's hidden
|
||||
assertThatThrownBy(() -> {
|
||||
targetManagement.assignTag(Collections.singletonList(hiddenTarget.getControllerId()), myTag.getId());
|
||||
}).as("Missing update permissions for target to toggle tag assignment.")
|
||||
assertThatThrownBy(() -> targetManagement.assignTag(Collections.singletonList(hiddenTarget.getControllerId()), myTag.getId()))
|
||||
.as("Missing update permissions for target to toggle tag assignment.")
|
||||
.isInstanceOf(InsufficientPermissionException.class);
|
||||
|
||||
// assignment is denied for hiddenTarget since it's hidden
|
||||
@@ -358,14 +353,13 @@ class TargetAccessControllerTest extends AbstractAccessControllerTest {
|
||||
|
||||
defineAccess(AccessController.Operation.UPDATE, updateTargets);
|
||||
defineAccess(AccessController.Operation.READ, merge(updateTargets, readTargets));
|
||||
;
|
||||
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
||||
.create(entityFactory.targetFilterQuery().create().name("testName").query("id==*"));
|
||||
|
||||
testAccessControlManger.defineAccessRule(
|
||||
JpaDistributionSet.class, AccessController.Operation.READ,
|
||||
DistributionSetSpecification.byId(distributionSet.getId()),
|
||||
dsById(distributionSet.getId()),
|
||||
ds -> ds.getId().equals(distributionSet.getId()));
|
||||
|
||||
targetFilterQueryManagement.updateAutoAssignDS(entityFactory.targetFilterQuery()
|
||||
@@ -395,4 +389,12 @@ class TargetAccessControllerTest extends AbstractAccessControllerTest {
|
||||
TargetSpecifications.hasIdIn(ids),
|
||||
target -> ids.contains(target.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
private static Specification<JpaDistributionSet> dsById(final Long distid) {
|
||||
return (dsRoot, query, cb) -> {
|
||||
final Predicate predicate = cb.equal(dsRoot.get(JpaDistributionSet_.id), distid);
|
||||
query.distinct(true);
|
||||
return predicate;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -31,13 +31,13 @@ public class TestAccessControlManger {
|
||||
public <T> void defineAccessRule(
|
||||
final Class<T> ruleClass, final AccessController.Operation operation,
|
||||
final Specification<T> specification, final Predicate<T> check) {
|
||||
accessRules.put(new AccessRuleId<T>(ruleClass, operation), new AccessRule<T>(specification, check));
|
||||
accessRules.put(new AccessRuleId<>(ruleClass, operation), new AccessRule<>(specification, check));
|
||||
}
|
||||
|
||||
public <T extends AbstractJpaBaseEntity> Specification<T> getAccessRule(final Class<T> ruleClass,
|
||||
final AccessController.Operation operation) {
|
||||
@SuppressWarnings("unchecked") final AccessRule<T> accessRule = (AccessRule<T>) accessRules.getOrDefault(
|
||||
new AccessRuleId<T>(ruleClass, operation), null);
|
||||
@SuppressWarnings("unchecked")
|
||||
final AccessRule<T> accessRule = (AccessRule<T>) accessRules.getOrDefault(new AccessRuleId<>(ruleClass, operation), null);
|
||||
if (accessRule == null) {
|
||||
return nop();
|
||||
} else {
|
||||
@@ -46,8 +46,8 @@ public class TestAccessControlManger {
|
||||
}
|
||||
|
||||
public <T> void assertOperation(final Class<T> ruleClass, final AccessController.Operation operation, final List<T> entities) {
|
||||
@SuppressWarnings("unchecked") final AccessRule<T> accessRule = (AccessRule<T>) accessRules.getOrDefault(
|
||||
new AccessRuleId<T>(ruleClass, operation), null);
|
||||
@SuppressWarnings("unchecked")
|
||||
final AccessRule<T> accessRule = (AccessRule<T>) accessRules.getOrDefault(new AccessRuleId<>(ruleClass, operation), null);
|
||||
if (accessRule == null) {
|
||||
throw new InsufficientPermissionException("No access define - reject all");
|
||||
} else {
|
||||
|
||||
@@ -18,7 +18,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Optional;
|
||||
@@ -75,8 +74,6 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
|
||||
/**
|
||||
* {@link DistributionSetManagement} tests.
|
||||
@@ -532,89 +529,6 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(updated.getDistributionSet().getId()).isEqualTo(ds.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests that a DS queue is possible where the result is ordered by the target assignment, i.e. assigned first in the list.")
|
||||
void findDistributionSetsAllOrderedByLinkTarget() {
|
||||
final List<DistributionSet> buildDistributionSets = testdataFactory.createDistributionSets("dsOrder", 10);
|
||||
|
||||
final List<Target> buildTargetFixtures = testdataFactory.createTargets(5, "tOrder", "someDesc");
|
||||
|
||||
final Iterator<DistributionSet> dsIterator = buildDistributionSets.iterator();
|
||||
final Iterator<Target> tIterator = buildTargetFixtures.iterator();
|
||||
final DistributionSet dsFirst = dsIterator.next();
|
||||
final DistributionSet dsSecond = dsIterator.next();
|
||||
final DistributionSet dsThree = dsIterator.next();
|
||||
final DistributionSet dsFour = dsIterator.next();
|
||||
final Target tFirst = tIterator.next();
|
||||
final Target tSecond = tIterator.next();
|
||||
|
||||
// set assigned
|
||||
assignDistributionSet(dsSecond.getId(), tSecond.getControllerId());
|
||||
implicitLock(dsSecond);
|
||||
assignDistributionSet(dsThree.getId(), tFirst.getControllerId());
|
||||
implicitLock(dsThree);
|
||||
// set installed
|
||||
testdataFactory.sendUpdateActionStatusToTargets(Collections.singleton(tSecond), Status.FINISHED,
|
||||
singletonList("some message"));
|
||||
|
||||
assignDistributionSet(dsFour.getId(), tSecond.getControllerId());
|
||||
implicitLock(dsFour);
|
||||
|
||||
final DistributionSetFilter distributionSetFilter =
|
||||
DistributionSetFilter.builder()
|
||||
.isDeleted(false)
|
||||
.isComplete(true)
|
||||
.selectDSWithNoTag(Boolean.FALSE).build();
|
||||
|
||||
// target first only has an assigned DS-three so check order correct
|
||||
final List<DistributionSet> tFirstPin = distributionSetManagement
|
||||
.findByDistributionSetFilterOrderByLinkedTarget(PAGE, distributionSetFilter, tFirst.getControllerId())
|
||||
.getContent();
|
||||
assertThat(tFirstPin).hasSize(10);
|
||||
// assigned
|
||||
assertThat(tFirstPin.get(0)).isEqualTo(dsThree);
|
||||
// remaining id:ASC
|
||||
assertThat(tFirstPin.get(1)).isEqualTo(dsFirst);
|
||||
assertThat(tFirstPin.get(2)).isEqualTo(dsSecond);
|
||||
assertThat(tFirstPin.get(3)).isEqualTo(dsFour);
|
||||
|
||||
// target second has installed DS-2 and assigned DS-4 so check order
|
||||
// correct
|
||||
final List<DistributionSet> tSecondPin = distributionSetManagement
|
||||
.findByDistributionSetFilterOrderByLinkedTarget(PAGE, distributionSetFilter, tSecond.getControllerId())
|
||||
.getContent();
|
||||
assertThat(tSecondPin).hasSize(10);
|
||||
// installed
|
||||
assertThat(tSecondPin.get(0)).isEqualTo(dsSecond);
|
||||
// assigned
|
||||
assertThat(tSecondPin.get(1)).isEqualTo(dsFour);
|
||||
// remaining id:ASC
|
||||
assertThat(tSecondPin.get(2)).isEqualTo(dsFirst);
|
||||
assertThat(tSecondPin.get(3)).isEqualTo(dsThree);
|
||||
|
||||
// target second has installed DS-2 and assigned DS-4 so check order
|
||||
// correct
|
||||
final List<DistributionSet> tSecondPinOrderedByName = distributionSetManagement
|
||||
.findByDistributionSetFilterOrderByLinkedTarget(
|
||||
PageRequest.of(0, 500, Sort.by(Direction.DESC, "version")), distributionSetFilter,
|
||||
tSecond.getControllerId())
|
||||
.getContent();
|
||||
assertThat(tSecondPinOrderedByName).hasSize(10);
|
||||
// installed
|
||||
assertThat(tSecondPinOrderedByName.get(0)).isEqualTo(buildDistributionSets.get(1));
|
||||
// assigned
|
||||
assertThat(tSecondPinOrderedByName.get(1)).isEqualTo(buildDistributionSets.get(3));
|
||||
// remaining version:DESC
|
||||
assertThat(tSecondPinOrderedByName.get(2)).isEqualTo(buildDistributionSets.get(9));
|
||||
assertThat(tSecondPinOrderedByName.get(3)).isEqualTo(buildDistributionSets.get(8));
|
||||
assertThat(tSecondPinOrderedByName.get(4)).isEqualTo(buildDistributionSets.get(7));
|
||||
assertThat(tSecondPinOrderedByName.get(5)).isEqualTo(buildDistributionSets.get(6));
|
||||
assertThat(tSecondPinOrderedByName.get(6)).isEqualTo(buildDistributionSets.get(5));
|
||||
assertThat(tSecondPinOrderedByName.get(7)).isEqualTo(buildDistributionSets.get(4));
|
||||
assertThat(tSecondPinOrderedByName.get(8)).isEqualTo(buildDistributionSets.get(2));
|
||||
assertThat(tSecondPinOrderedByName.get(9)).isEqualTo(buildDistributionSets.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("searches for distribution sets based on the various filter options, e.g. name, version, desc., tags.")
|
||||
void searchDistributionSetsOnFilters() {
|
||||
|
||||
Reference in New Issue
Block a user