improve code-coverage and fix HsPostgreSqlInstanceHostingAssetValidatorUnitTest did actually test MARIADB_INSTANCE
This commit is contained in:
parent
6b9fe2e780
commit
4008c35ac6
@ -72,8 +72,8 @@ class HashGeneratorUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void generatesMySqlNativePasswordHash() {
|
void generatesMySqlNativePasswordHash() {
|
||||||
final var hash = HashGenerator.using(MYSQL_NATIVE).hash("Test1234");
|
final var hash = HashGenerator.using(MYSQL_NATIVE).hash("t8L7FULt"); // results in line+branch-coverage
|
||||||
assertThat(hash).isEqualTo("*14F1A8C42F8B6D4662BB3ED290FD37BF135FE45C");
|
assertThat(hash).isEqualTo("*F1E107E5C47E0939C7BC941DDE59EDBBDA1F7E39");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -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}");
|
"{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
|
@Test
|
||||||
void acceptsValidEntity() {
|
void acceptsValidEntity() {
|
||||||
// given
|
// given
|
||||||
|
@ -9,18 +9,17 @@ import org.junit.jupiter.api.Test;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static java.util.Map.entry;
|
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.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.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;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
class HsPostgreSqlInstanceHostingAssetValidatorUnitTest {
|
class HsPostgreSqlInstanceHostingAssetValidatorUnitTest {
|
||||||
|
|
||||||
static HsHostingAssetRbacEntity.HsHostingAssetRbacEntityBuilder<?, ?> validEntityBuilder() {
|
static HsHostingAssetRbacEntity.HsHostingAssetRbacEntityBuilder<?, ?> validEntityBuilder() {
|
||||||
return HsHostingAssetRbacEntity.builder()
|
return HsHostingAssetRbacEntity.builder()
|
||||||
.type(MARIADB_INSTANCE)
|
.type(PGSQL_INSTANCE)
|
||||||
.parentAsset(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY)
|
.parentAsset(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY)
|
||||||
.identifier(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY.getIdentifier() + DEFAULT_INSTANCE_IDENTIFIER_SUFFIX);
|
.identifier(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY.getIdentifier() + DEFAULT_INSTANCE_IDENTIFIER_SUFFIX);
|
||||||
}
|
}
|
||||||
@ -28,7 +27,7 @@ class HsPostgreSqlInstanceHostingAssetValidatorUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
void containsExpectedProperties() {
|
void containsExpectedProperties() {
|
||||||
// when
|
// when
|
||||||
final var validator = HostingAssetEntityValidatorRegistry.forType(DOMAIN_SMTP_SETUP);
|
final var validator = HostingAssetEntityValidatorRegistry.forType(PGSQL_INSTANCE);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(validator.properties()).map(Map::toString).isEmpty();
|
assertThat(validator.properties()).map(Map::toString).isEmpty();
|
||||||
@ -45,7 +44,7 @@ class HsPostgreSqlInstanceHostingAssetValidatorUnitTest {
|
|||||||
validator.preprocessEntity(givenEntity);
|
validator.preprocessEntity(givenEntity);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(givenEntity.getIdentifier()).isEqualTo("vm1234|MariaDB.default");
|
assertThat(givenEntity.getIdentifier()).isEqualTo("vm1234|PgSql.default");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -64,7 +63,7 @@ class HsPostgreSqlInstanceHostingAssetValidatorUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
void rejectsInvalidIdentifier() {
|
void rejectsInvalidIdentifier() {
|
||||||
// given
|
// given
|
||||||
final var givenEntity = validEntityBuilder().identifier("example.org").build();
|
final var givenEntity = validEntityBuilder().identifier("PostgreSQL").build();
|
||||||
final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
|
final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@ -72,7 +71,7 @@ class HsPostgreSqlInstanceHostingAssetValidatorUnitTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result).containsExactly(
|
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
|
// then
|
||||||
assertThat(result).containsExactlyInAnyOrder(
|
assertThat(result).containsExactlyInAnyOrder(
|
||||||
"'MARIADB_INSTANCE:vm1234|MariaDB.default.bookingItem' must be null but is of type CLOUD_SERVER",
|
"'PGSQL_INSTANCE:vm1234|PgSql.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",
|
"'PGSQL_INSTANCE:vm1234|PgSql.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.assignedToAsset' must be null but is of type MANAGED_WEBSPACE");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -111,6 +110,6 @@ class HsPostgreSqlInstanceHostingAssetValidatorUnitTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result).containsExactlyInAnyOrder(
|
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'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user