diff --git a/src/test/java/net/hostsharing/hsadminng/hash/HashGeneratorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hash/HashGeneratorUnitTest.java index fcb2ce3d..c43550b9 100644 --- a/src/test/java/net/hostsharing/hsadminng/hash/HashGeneratorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hash/HashGeneratorUnitTest.java @@ -72,8 +72,8 @@ class HashGeneratorUnitTest { @Test void generatesMySqlNativePasswordHash() { - final var hash = HashGenerator.using(MYSQL_NATIVE).hash("Test1234"); - assertThat(hash).isEqualTo("*14F1A8C42F8B6D4662BB3ED290FD37BF135FE45C"); + final var hash = HashGenerator.using(MYSQL_NATIVE).hash("t8L7FULt"); // results in line+branch-coverage + assertThat(hash).isEqualTo("*F1E107E5C47E0939C7BC941DDE59EDBBDA1F7E39"); } @Test diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidatorUnitTest.java index 88adb55b..58950534 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidatorUnitTest.java @@ -56,6 +56,35 @@ class HsEMailAddressHostingAssetValidatorUnitTest { "{type=string[], propertyName=target, elementsOf={type=string, propertyName=target, matchesRegEx=[^[a-z][a-z0-9]{2}[0-9]{2}(-[a-z0-9][a-z0-9\\.+_-]*)?$, ^([a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+)?@[a-zA-Z0-9.-]+$, ^nobody$, ^/dev/null$], maxLength=320}, required=true, minLength=1}"); } + @Test + void preprocessEntityWithInitializedIdentifier() { + // given + final var givenEntity = validEntityBuilder().identifier("some-local-part@example.org").build(); + assertThat(givenEntity.getParentAsset().getIdentifier()).as("preconditon failed").isEqualTo("example.org|MBOX"); + final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + + // when + validator.preprocessEntity(givenEntity); + + // then + assertThat(givenEntity.getIdentifier()).isEqualTo("some-local-part@example.org"); + } + + @Test + void preprocessEntityWithUninitializedIdentifier() { + // given + final var givenEntity = validEntityBuilder().identifier(null).build(); + assertThat(givenEntity.getParentAsset().getIdentifier()).as("preconditon failed").isEqualTo("example.org|MBOX"); + final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + + // when + validator.preprocessEntity(givenEntity); + + // then + assertThat(givenEntity.getIdentifier()) + .isEqualTo(givenEntity.getDirectValue("local-part", String.class) + "@example.org"); + } + @Test void acceptsValidEntity() { // given diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlInstanceHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlInstanceHostingAssetValidatorUnitTest.java index e277d202..ea2378e1 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlInstanceHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlInstanceHostingAssetValidatorUnitTest.java @@ -9,18 +9,17 @@ import org.junit.jupiter.api.Test; import java.util.Map; import static java.util.Map.entry; -import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SMTP_SETUP; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE; -import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MARIADB_INSTANCE; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetTestEntities.MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY; -import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsMariaDbInstanceHostingAssetValidator.DEFAULT_INSTANCE_IDENTIFIER_SUFFIX; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.PGSQL_INSTANCE; +import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsPostgreSqlDbInstanceHostingAssetValidator.DEFAULT_INSTANCE_IDENTIFIER_SUFFIX; import static org.assertj.core.api.Assertions.assertThat; class HsPostgreSqlInstanceHostingAssetValidatorUnitTest { static HsHostingAssetRbacEntity.HsHostingAssetRbacEntityBuilder validEntityBuilder() { return HsHostingAssetRbacEntity.builder() - .type(MARIADB_INSTANCE) + .type(PGSQL_INSTANCE) .parentAsset(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY) .identifier(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY.getIdentifier() + DEFAULT_INSTANCE_IDENTIFIER_SUFFIX); } @@ -28,7 +27,7 @@ class HsPostgreSqlInstanceHostingAssetValidatorUnitTest { @Test void containsExpectedProperties() { // when - final var validator = HostingAssetEntityValidatorRegistry.forType(DOMAIN_SMTP_SETUP); + final var validator = HostingAssetEntityValidatorRegistry.forType(PGSQL_INSTANCE); // then assertThat(validator.properties()).map(Map::toString).isEmpty(); @@ -45,7 +44,7 @@ class HsPostgreSqlInstanceHostingAssetValidatorUnitTest { validator.preprocessEntity(givenEntity); // then - assertThat(givenEntity.getIdentifier()).isEqualTo("vm1234|MariaDB.default"); + assertThat(givenEntity.getIdentifier()).isEqualTo("vm1234|PgSql.default"); } @Test @@ -64,7 +63,7 @@ class HsPostgreSqlInstanceHostingAssetValidatorUnitTest { @Test void rejectsInvalidIdentifier() { // given - final var givenEntity = validEntityBuilder().identifier("example.org").build(); + final var givenEntity = validEntityBuilder().identifier("PostgreSQL").build(); final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); // when @@ -72,7 +71,7 @@ class HsPostgreSqlInstanceHostingAssetValidatorUnitTest { // then assertThat(result).containsExactly( - "'identifier' expected to match '^\\Qvm1234|MariaDB.default\\E$', but is 'example.org'" + "'identifier' expected to match '^\\Qvm1234|PgSql.default\\E$', but is 'PostgreSQL'" ); } @@ -91,9 +90,9 @@ class HsPostgreSqlInstanceHostingAssetValidatorUnitTest { // then assertThat(result).containsExactlyInAnyOrder( - "'MARIADB_INSTANCE:vm1234|MariaDB.default.bookingItem' must be null but is of type CLOUD_SERVER", - "'MARIADB_INSTANCE:vm1234|MariaDB.default.parentAsset' must be of type MANAGED_SERVER but is of type MANAGED_WEBSPACE", - "'MARIADB_INSTANCE:vm1234|MariaDB.default.assignedToAsset' must be null but is of type MANAGED_WEBSPACE"); + "'PGSQL_INSTANCE:vm1234|PgSql.default.bookingItem' must be null but is of type CLOUD_SERVER", + "'PGSQL_INSTANCE:vm1234|PgSql.default.parentAsset' must be of type MANAGED_SERVER but is of type MANAGED_WEBSPACE", + "'PGSQL_INSTANCE:vm1234|PgSql.default.assignedToAsset' must be null but is of type MANAGED_WEBSPACE"); } @Test @@ -111,6 +110,6 @@ class HsPostgreSqlInstanceHostingAssetValidatorUnitTest { // then assertThat(result).containsExactlyInAnyOrder( - "'MARIADB_INSTANCE:vm1234|MariaDB.default.config.any' is not expected but is set to 'false'"); + "'PGSQL_INSTANCE:vm1234|PgSql.default.config.any' is not expected but is set to 'false'"); } }