integrate-sha512-password-hashing #68

Merged
hsh-michaelhoennig merged 12 commits from integrate-sha512-password-hashing into master 2024-07-01 15:53:50 +02:00
9 changed files with 34 additions and 27 deletions
Showing only changes of commit 14cae92ba5 - Show all commits

View File

@ -22,22 +22,17 @@ public class HsBookingItemEntityValidator extends HsEntityValidator<HsBookingIte
@Override
public List<String> validateEntity(final HsBookingItemEntity bookingItem) {
return validateProperties(bookingItem);
return enrich(prefix(bookingItem.toShortString(), "resources"), super.validateProperties(bookingItem));
}
@Override
public List<String> validateContext(final HsBookingItemEntity bookingItem) {
return sequentiallyValidate(
() -> validateProperties(bookingItem),
() -> optionallyValidate(bookingItem.getParentItem()),
() -> validateAgainstSubEntities(bookingItem)
);
}
private List<String> validateProperties(final HsBookingItemEntity bookingItem) {
return enrich(prefix(bookingItem.toShortString(), "resources"), super.validateProperties(bookingItem));
}
private static List<String> optionallyValidate(final HsBookingItemEntity bookingItem) {
return bookingItem != null
? enrich(prefix(bookingItem.toShortString(), ""),

View File

@ -55,7 +55,8 @@ public class HsHostingAssetEntityProcessor {
/// removes write-only-properties and ads computed-properties
@SuppressWarnings("unchecked")
public HsHostingAssetResource revampProperties() {
validator.revampProperties(entity, (Map<String, Object>) resource.getConfig());
final var revampedProps = validator.revampProperties(entity, (Map<String, Object>) resource.getConfig());
resource.setConfig(revampedProps);
return resource;
}
}

View File

@ -4,7 +4,6 @@ import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity;
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType;
import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetResource;
import net.hostsharing.hsadminng.hs.validation.HsEntityValidator;
import net.hostsharing.hsadminng.errors.MultiValidationException;
import java.util.*;

View File

@ -16,6 +16,12 @@ public class TestHsBookingItem {
.project(TEST_PROJECT)
.type(HsBookingItemType.CLOUD_SERVER)
.caption("test cloud server booking item")
.resources(Map.ofEntries(
entry("CPUs", 2),
entry("RAM", 4),
entry("SSD", 50),
entry("Traffic", 250)
))
.validity(Range.closedInfinite(LocalDate.of(2020, 1, 15)))
.build();

View File

@ -68,15 +68,15 @@ class HsCloudServerHostingAssetValidatorUnitTest {
@Test
void validatesBookingItemType() {
// given
final var mangedServerHostingAssetEntity = HsHostingAssetEntity.builder()
final var mangedServerHostingAssetEntity = linkBookingItem(HsHostingAssetEntity.builder()
.type(MANAGED_SERVER)
.identifier("xyz00")
.bookingItem(TEST_CLOUD_SERVER_BOOKING_ITEM)
.build();
.bookingItem(TEST_CLOUD_SERVER_BOOKING_ITEM.toBuilder().build())
.build());
final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
// when
final var result = validator.validateContext(mangedServerHostingAssetEntity);
final var result = validator.validateEntity(mangedServerHostingAssetEntity);
// then
assertThat(result).containsExactlyInAnyOrder(
@ -103,4 +103,9 @@ class HsCloudServerHostingAssetValidatorUnitTest {
"'CLOUD_SERVER:xyz00.parentAsset' must be null but is set to D-???????-?:null",
"'CLOUD_SERVER:xyz00.assignedToAsset' must be null but is set to D-???????-?:null");
}
private static HsHostingAssetEntity linkBookingItem(final HsHostingAssetEntity mangedServerHostingAssetEntity) {
mangedServerHostingAssetEntity.getBookingItem().setRelatedHostingAsset(mangedServerHostingAssetEntity);
return mangedServerHostingAssetEntity;
}
}

View File

@ -1,10 +1,6 @@
package net.hostsharing.hsadminng.hs.hosting.asset.validators;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType;
import net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem;
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity;
import net.hostsharing.hsadminng.mapper.Array;
import org.junit.jupiter.api.Test;
import java.util.List;
@ -22,10 +18,11 @@ class HsHostingAssetEntityValidatorUnitTest {
final var managedServerHostingAssetEntity = HsHostingAssetEntity.builder()
.type(MANAGED_SERVER)
.identifier("vm1234")
.bookingItem(TEST_MANAGED_SERVER_BOOKING_ITEM)
.bookingItem(TEST_MANAGED_SERVER_BOOKING_ITEM.toBuilder().build())
.parentAsset(HsHostingAssetEntity.builder().type(MANAGED_SERVER).build())
.assignedToAsset(HsHostingAssetEntity.builder().type(MANAGED_SERVER).build())
.build();
linkBookingItem(managedServerHostingAssetEntity);
// when
final var validator = HsHostingAssetEntityValidatorRegistry.forType(managedServerHostingAssetEntity.getType());
@ -36,8 +33,12 @@ class HsHostingAssetEntityValidatorUnitTest {
// then
assertThat(result).containsExactlyInAnyOrder(
"'MANAGED_SERVER:vm1234.parentAsset' must be null but is set to D-???????-?:null",
"'MANAGED_SERVER:vm1234.assignedToAsset' must be null but is set to D-???????-?:null");
"'MANAGED_SERVER:vm1234.parentAsset' must be null but is set to D-1234500:test project:test project booking item",
"'MANAGED_SERVER:vm1234.assignedToAsset' must be null but is set to D-1234500:test project:test project booking item");
}
private static void linkBookingItem(final HsHostingAssetEntity managedServerHostingAssetEntity) {
managedServerHostingAssetEntity.getBookingItem().setRelatedHostingAsset(managedServerHostingAssetEntity);
}
}

View File

@ -33,12 +33,12 @@ class HsManagedServerHostingAssetValidatorUnitTest {
final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedWebspaceHostingAssetEntity.getType());
// when
final var result = validator.validateContext(mangedWebspaceHostingAssetEntity);
final var result = validator.validateEntity(mangedWebspaceHostingAssetEntity);
// then
assertThat(result).containsExactlyInAnyOrder(
"'MANAGED_SERVER:vm1234.parentAsset' must be null but is set to D-???????-?:null",
"'MANAGED_SERVER:vm1234.assignedToAsset' must be null but is set to D-???????-?:null",
"'MANAGED_SERVER:vm1234.parentAsset' must be null but is set to D-1234500:test project:test project booking item",
"'MANAGED_SERVER:vm1234.assignedToAsset' must be null but is set to D-1234500:test project:test project booking item",
"'MANAGED_SERVER:vm1234.config.monit_max_cpu_usage' is expected to be at least 10 but is 2",
"'MANAGED_SERVER:vm1234.config.monit_max_ram_usage' is expected to be at most 100 but is 101",
"'MANAGED_SERVER:vm1234.config.monit_max_hdd_usage' is expected to be of type class java.lang.Integer, but is of type 'String'");
@ -75,12 +75,12 @@ class HsManagedServerHostingAssetValidatorUnitTest {
final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
// when
final var result = validator.validateContext(mangedServerHostingAssetEntity);
final var result = validator.validateEntity(mangedServerHostingAssetEntity);
// then
assertThat(result).containsExactlyInAnyOrder(
"'MANAGED_SERVER:xyz00.bookingItem' must be of type MANAGED_SERVER but is of type CLOUD_SERVER",
"'MANAGED_SERVER:xyz00.parentAsset' must be null but is set to D-???????-?:null",
"'MANAGED_SERVER:xyz00.assignedToAsset' must be null but is set to D-???????-?:null");
"'MANAGED_SERVER:xyz00.parentAsset' must be null but is set to D-1234500:test project:test cloud server booking item",
"'MANAGED_SERVER:xyz00.assignedToAsset' must be null but is set to D-1234500:test project:test cloud server booking item");
}
}

View File

@ -158,7 +158,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest {
.build();
// when
final var result = validator.validateContext(mangedWebspaceHostingAssetEntity);
final var result = validator.validateEntity(mangedWebspaceHostingAssetEntity);
// then
assertThat(result).containsExactly(

View File

@ -125,7 +125,7 @@ class HsUnixUserHostingAssetValidatorUnitTest {
"{type=enumeration, propertyName=shell, values=[/bin/false, /bin/bash, /bin/csh, /bin/dash, /usr/bin/tcsh, /usr/bin/zsh, /usr/bin/passwd], defaultValue=/bin/false}",
"{type=string, propertyName=homedir, readOnly=true, computed=true}",
"{type=string, propertyName=totpKey, matchesRegEx=^0x([0-9A-Fa-f]{2})+$, minLength=20, maxLength=256, writeOnly=true, undisclosed=true}",
"{type=password, propertyName=password, minLength=8, maxLength=40, writeOnly=true, hashedUsing=SHA512, undisclosed=true}"
"{type=password, propertyName=password, minLength=8, maxLength=40, writeOnly=true, computed=true, hashedUsing=SHA512, undisclosed=true}"
);
}
}