integrate-sha512-password-hashing #68
@ -1,45 +0,0 @@
|
|||||||
package net.hostsharing.hsadminng.hs.hosting.asset.validators;
|
|
||||||
|
|
||||||
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_MANAGED_SERVER_BOOKING_ITEM;
|
|
||||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_SERVER;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
class HsHostingAssetEntityValidatorUnitTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void validatesEntity() {
|
|
||||||
// given
|
|
||||||
final var managedServerHostingAssetEntity = HsHostingAssetEntity.builder()
|
|
||||||
.type(MANAGED_SERVER)
|
|
||||||
.identifier("vm1234")
|
|
||||||
.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());
|
|
||||||
final List<String> result = Stream.concat(
|
|
||||||
validator.validateEntity(managedServerHostingAssetEntity).stream(),
|
|
||||||
validator.validateContext(managedServerHostingAssetEntity).stream()
|
|
||||||
).toList();
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(result).containsExactlyInAnyOrder(
|
|
||||||
"'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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: add tests for prepareProperties, validatesContext + revampProperties
|
|
@ -1,12 +1,14 @@
|
|||||||
package net.hostsharing.hsadminng.hs.hosting.asset.validators;
|
package net.hostsharing.hsadminng.hs.hosting.asset.validators;
|
||||||
|
|
||||||
|
import net.hostsharing.hsadminng.hash.LinuxEtcShadowHashGenerator;
|
||||||
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity;
|
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity;
|
||||||
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType;
|
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.HashMap;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static java.util.Map.ofEntries;
|
||||||
import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_MANAGED_SERVER_BOOKING_ITEM;
|
import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_MANAGED_SERVER_BOOKING_ITEM;
|
||||||
import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_MANAGED_WEBSPACE_BOOKING_ITEM;
|
import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_MANAGED_WEBSPACE_BOOKING_ITEM;
|
||||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE;
|
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE;
|
||||||
@ -22,28 +24,48 @@ class HsUnixUserHostingAssetValidatorUnitTest {
|
|||||||
.caption("some managed server")
|
.caption("some managed server")
|
||||||
.bookingItem(TEST_MANAGED_SERVER_BOOKING_ITEM)
|
.bookingItem(TEST_MANAGED_SERVER_BOOKING_ITEM)
|
||||||
.build();
|
.build();
|
||||||
private HsHostingAssetEntity TEST_MANAGED_WEBSPACE_HOSTING_ASSET = HsHostingAssetEntity.builder()
|
private final HsHostingAssetEntity TEST_MANAGED_WEBSPACE_HOSTING_ASSET = HsHostingAssetEntity.builder()
|
||||||
.type(MANAGED_WEBSPACE)
|
.type(MANAGED_WEBSPACE)
|
||||||
.bookingItem(TEST_MANAGED_WEBSPACE_BOOKING_ITEM)
|
.bookingItem(TEST_MANAGED_WEBSPACE_BOOKING_ITEM)
|
||||||
.parentAsset(TEST_MANAGED_SERVER_HOSTING_ASSET)
|
.parentAsset(TEST_MANAGED_SERVER_HOSTING_ASSET)
|
||||||
.identifier("abc00")
|
.identifier("abc00")
|
||||||
.build();;
|
.build();
|
||||||
|
private final HsHostingAssetEntity GIVEN_VALID_UNIX_USER_HOSTING_ASSET = HsHostingAssetEntity.builder()
|
||||||
@Test
|
|
||||||
void validatesValidUnixUser() {
|
|
||||||
// given
|
|
||||||
final var unixUserHostingAsset = HsHostingAssetEntity.builder()
|
|
||||||
.type(UNIX_USER)
|
.type(UNIX_USER)
|
||||||
.parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET)
|
.parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET)
|
||||||
.identifier("abc00-temp")
|
.identifier("abc00-temp")
|
||||||
.caption("some valid test UnixUser")
|
.caption("some valid test UnixUser")
|
||||||
.config(Map.ofEntries(
|
.config(new HashMap<>(ofEntries(
|
||||||
entry("SSD hard quota", 50),
|
entry("SSD hard quota", 50),
|
||||||
entry("SSD soft quota", 40),
|
entry("SSD soft quota", 40),
|
||||||
entry("totpKey", "0x123456789abcdef01234"),
|
entry("totpKey", "0x123456789abcdef01234"),
|
||||||
entry("password", "Hallo Computer, lass mich rein!")
|
entry("password", "Hallo Computer, lass mich rein!")
|
||||||
))
|
)))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void preparesUnixUser() {
|
||||||
|
// given
|
||||||
|
final var unixUserHostingAsset = GIVEN_VALID_UNIX_USER_HOSTING_ASSET;
|
||||||
|
final var validator = HsHostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType());
|
||||||
|
|
||||||
|
// when
|
||||||
|
LinuxEtcShadowHashGenerator.nextSalt("Ly3LbsArtL5u4EVt");
|
||||||
|
validator.prepareProperties(unixUserHostingAsset);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(unixUserHostingAsset.getConfig()).containsExactlyInAnyOrderEntriesOf(ofEntries(
|
||||||
|
entry("SSD hard quota", 50),
|
||||||
|
entry("SSD soft quota", 40),
|
||||||
|
entry("totpKey", "0x123456789abcdef01234"),
|
||||||
|
entry("password", "$6$Ly3LbsArtL5u4EVt$i/ayIEvm0y4bjkFB6wbg8imbRIaw4mAA4gqYRVyoSkj.iIxJKS3KiRkSjP8gweNcpKL0Q0N31EadT8fCnWErL.")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void validatesValidUnixUser() {
|
||||||
|
// given
|
||||||
|
final var unixUserHostingAsset = GIVEN_VALID_UNIX_USER_HOSTING_ASSET;
|
||||||
final var validator = HsHostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType());
|
final var validator = HsHostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@ -64,7 +86,7 @@ class HsUnixUserHostingAssetValidatorUnitTest {
|
|||||||
.parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET)
|
.parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET)
|
||||||
.identifier("abc00-temp")
|
.identifier("abc00-temp")
|
||||||
.caption("some test UnixUser with invalid properties")
|
.caption("some test UnixUser with invalid properties")
|
||||||
.config(Map.ofEntries(
|
.config(ofEntries(
|
||||||
entry("SSD hard quota", 100),
|
entry("SSD hard quota", 100),
|
||||||
entry("SSD soft quota", 200),
|
entry("SSD soft quota", 200),
|
||||||
entry("HDD hard quota", 100),
|
entry("HDD hard quota", 100),
|
||||||
@ -112,6 +134,24 @@ class HsUnixUserHostingAssetValidatorUnitTest {
|
|||||||
"'identifier' expected to match '^abc00$|^abc00-[a-z0-9]+$', but is 'xyz99-temp'");
|
"'identifier' expected to match '^abc00$|^abc00-[a-z0-9]+$', but is 'xyz99-temp'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void revampsUnixUser() {
|
||||||
|
// given
|
||||||
|
final var unixUserHostingAsset = GIVEN_VALID_UNIX_USER_HOSTING_ASSET;
|
||||||
|
final var validator = HsHostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType());
|
||||||
|
|
||||||
|
// when
|
||||||
|
LinuxEtcShadowHashGenerator.nextSalt("Ly3LbsArtL5u4EVt");
|
||||||
|
final var result = validator.revampProperties(unixUserHostingAsset, unixUserHostingAsset.getConfig());
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(result).containsExactlyInAnyOrderEntriesOf(ofEntries(
|
||||||
|
entry("SSD hard quota", 50),
|
||||||
|
entry("SSD soft quota", 40),
|
||||||
|
entry("homedir", "/home/pacs/abc00/users/temp")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void describesItsProperties() {
|
void describesItsProperties() {
|
||||||
// given
|
// given
|
||||||
|
Loading…
Reference in New Issue
Block a user