1
0

add-domain-http-setup-validation (#73)

Co-authored-by: Michael Hoennig <michael@hoennig.de>
Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/73
Reviewed-by: Timotheus Pokorra <timotheus.pokorra@hostsharing.net>
This commit is contained in:
Michael Hoennig
2024-07-10 15:54:02 +02:00
parent afb6771ed7
commit 0af389d7c6
26 changed files with 363 additions and 81 deletions

View File

@@ -246,6 +246,59 @@ public class HsHostingAssetControllerRestTest {
}
}
]
"""),
DOMAIN_HTTP_SETUP(
List.of(
HsHostingAssetEntity.builder()
.type(HsHostingAssetType.DOMAIN_HTTP_SETUP)
.identifier("example.org")
.caption("some fake Domain-HTTP-Setup")
.config(Map.ofEntries(
entry("htdocsfallback", false),
entry("indexes", false),
entry("cgi", false),
entry("passenger", false),
entry("passenger-errorpage", true),
entry("fastcgi", false),
entry("autoconfig", false),
entry("greylisting", false),
entry("includes", false),
entry("letsencrypt", false),
entry("multiviews", false),
entry("fcgi-php-bin", "/usr/lib/cgi-bin/php8"),
entry("passenger-nodejs", "/usr/bin/node-js7"),
entry("passenger-python", "/usr/bin/python6"),
entry("passenger-ruby", "/usr/bin/ruby5"),
entry("subdomains", Array.of("www", "test1", "test2"))
))
.build()),
"""
[
{
"type": "DOMAIN_HTTP_SETUP",
"identifier": "example.org",
"caption": "some fake Domain-HTTP-Setup",
"alarmContact": null,
"config": {
"autoconfig": false,
"cgi": false,
"fastcgi": false,
"greylisting": false,
"htdocsfallback": false,
"includes": false,
"indexes": false,
"letsencrypt": false,
"multiviews": false,
"passenger": false,
"passenger-errorpage": true,
"passenger-nodejs": "/usr/bin/node-js7",
"passenger-python": "/usr/bin/python6",
"passenger-ruby": "/usr/bin/ruby5",
"fcgi-php-bin": "/usr/lib/cgi-bin/php8",
"subdomains": ["www","test1","test2"]
}
}
]
""");
final HsHostingAssetType assetType;

View File

@@ -37,7 +37,8 @@ class HsHostingAssetPropsControllerAcceptanceTest {
"UNIX_USER",
"EMAIL_ALIAS",
"DOMAIN_SETUP",
"DOMAIN_DNS_SETUP"
"DOMAIN_DNS_SETUP",
"DOMAIN_HTTP_SETUP"
]
"""));
// @formatter:on

View File

@@ -6,13 +6,13 @@ import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
class HsHostingAssetEntityValidatorRegistryUnitTest {
class HostingAssetEntityValidatorRegistryUnitTest {
@Test
void forTypeWithUnknownTypeThrowsException() {
// when
final var thrown = catchThrowable(() -> {
HsHostingAssetEntityValidatorRegistry.forType(null);
HostingAssetEntityValidatorRegistry.forType(null);
});
// then
@@ -22,7 +22,7 @@ class HsHostingAssetEntityValidatorRegistryUnitTest {
@Test
void typesReturnsAllImplementedTypes() {
// when
final var types = HsHostingAssetEntityValidatorRegistry.types();
final var types = HostingAssetEntityValidatorRegistry.types();
// then
// TODO.test: when all types are implemented, replace with set of all types:
@@ -35,7 +35,8 @@ class HsHostingAssetEntityValidatorRegistryUnitTest {
HsHostingAssetType.UNIX_USER,
HsHostingAssetType.EMAIL_ALIAS,
HsHostingAssetType.DOMAIN_SETUP,
HsHostingAssetType.DOMAIN_DNS_SETUP
HsHostingAssetType.DOMAIN_DNS_SETUP,
HsHostingAssetType.DOMAIN_HTTP_SETUP
);
}
}

View File

@@ -25,7 +25,7 @@ class HsCloudServerHostingAssetValidatorUnitTest {
entry("RAM", 2000)
))
.build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(cloudServerHostingAssetEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(cloudServerHostingAssetEntity.getType());
// when
@@ -45,7 +45,7 @@ class HsCloudServerHostingAssetValidatorUnitTest {
.identifier("xyz99")
.bookingItem(TEST_CLOUD_SERVER_BOOKING_ITEM)
.build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(cloudServerHostingAssetEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(cloudServerHostingAssetEntity.getType());
// when
@@ -59,7 +59,7 @@ class HsCloudServerHostingAssetValidatorUnitTest {
@Test
void containsAllValidations() {
// when
final var validator = HsHostingAssetEntityValidatorRegistry.forType(CLOUD_SERVER);
final var validator = HostingAssetEntityValidatorRegistry.forType(CLOUD_SERVER);
// then
assertThat(validator.properties()).map(Map::toString).isEmpty();
@@ -73,7 +73,7 @@ class HsCloudServerHostingAssetValidatorUnitTest {
.identifier("xyz00")
.bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build())
.build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
// when
final var result = validator.validateEntity(mangedServerHostingAssetEntity);
@@ -93,7 +93,7 @@ class HsCloudServerHostingAssetValidatorUnitTest {
.parentAsset(HsHostingAssetEntity.builder().type(MANAGED_SERVER).build())
.assignedToAsset(HsHostingAssetEntity.builder().type(CLOUD_SERVER).build())
.build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
// when
final var result = validator.validateEntity(mangedServerHostingAssetEntity);

View File

@@ -46,7 +46,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest {
@Test
void containsExpectedProperties() {
// when
final var validator = HsHostingAssetEntityValidatorRegistry.forType(DOMAIN_DNS_SETUP);
final var validator = HostingAssetEntityValidatorRegistry.forType(DOMAIN_DNS_SETUP);
// then
assertThat(validator.properties()).map(Map::toString).containsExactlyInAnyOrder(
@@ -75,7 +75,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest {
// given
final var givenEntity = validEntityBuilder().build();
assertThat(givenEntity.getParentAsset().getIdentifier()).as("preconditon failed").isEqualTo("example.org");
final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
// when
validator.preprocessEntity(givenEntity);
@@ -88,7 +88,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest {
void rejectsInvalidIdentifier() {
// given
final var givenEntity = validEntityBuilder().identifier("example.org").build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
// when
final var result = validator.validateEntity(givenEntity);
@@ -103,7 +103,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest {
void acceptsValidIdentifier() {
// given
final var givenEntity = validEntityBuilder().identifier(validDomainSetupEntity.getIdentifier()+"|DNS").build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
// when
final var result = validator.validateEntity(givenEntity);
@@ -120,7 +120,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest {
.parentAsset(null)
.assignedToAsset(HsHostingAssetEntity.builder().type(DOMAIN_SETUP).build())
.build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
// when
final var result = validator.validateEntity(mangedServerHostingAssetEntity);
@@ -136,7 +136,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest {
void acceptsValidEntity() {
// given
final var givenEntity = validEntityBuilder().build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
// when
final var errors = validator.validateEntity(givenEntity);
@@ -146,7 +146,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest {
}
@Test
void recectsInvalidProperties() {
void rejectsInvalidProperties() {
// given
final var mangedServerHostingAssetEntity = validEntityBuilder()
.config(Map.ofEntries(
@@ -156,14 +156,14 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest {
"www BAD1 Record-Class missing / not enough columns"))
))
.build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
// when
final var result = validator.validateEntity(mangedServerHostingAssetEntity);
// then
assertThat(result).containsExactlyInAnyOrder(
"'DOMAIN_DNS_SETUP:example.org|DNS.config.TTL' is expected to be of type class java.lang.Integer, but is of type 'String'",
"'DOMAIN_DNS_SETUP:example.org|DNS.config.TTL' is expected to be of type Integer, but is of type String",
"'DOMAIN_DNS_SETUP:example.org|DNS.config.user-RR' is expected to match any of [([a-z0-9\\.-]+|@)\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*IN\\s+[A-Z]+\\s+[^;].*(;.*)*, ([a-z0-9\\.-]+|@)\\s+IN\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*[A-Z]+\\s+[^;].*(;.*)*] but '@ 1814400 IN 1814400 BAD1 TTL only allowed once' does not match any",
"'DOMAIN_DNS_SETUP:example.org|DNS.config.user-RR' is expected to match any of [([a-z0-9\\.-]+|@)\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*IN\\s+[A-Z]+\\s+[^;].*(;.*)*, ([a-z0-9\\.-]+|@)\\s+IN\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*[A-Z]+\\s+[^;].*(;.*)*] but 'www BAD1 Record-Class missing / not enough columns' does not match any");
}
@@ -200,7 +200,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest {
void generatesZonefile() {
// given
final var givenEntity = validEntityBuilder().build();
final var validator = (HsDomainDnsSetupHostingAssetValidator) HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
final var validator = (HsDomainDnsSetupHostingAssetValidator) HostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
// when
final var zonefile = validator.toZonefileString(givenEntity);
@@ -231,7 +231,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest {
))
))
.build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
// when
final var errors = validator.validateContext(givenEntity);

View File

@@ -0,0 +1,163 @@
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.hosting.asset.HsHostingAssetEntity;
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity.HsHostingAssetEntityBuilder;
import net.hostsharing.hsadminng.mapper.Array;
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_HTTP_SETUP;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SETUP;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.UNIX_USER;
import static org.assertj.core.api.Assertions.assertThat;
class HsDomainHttpSetupHostingAssetValidatorUnitTest {
static final HsHostingAssetEntity validDomainSetupEntity = HsHostingAssetEntity.builder()
.type(DOMAIN_SETUP)
.identifier("example.org")
.build();
static HsHostingAssetEntityBuilder validEntityBuilder() {
return HsHostingAssetEntity.builder()
.type(DOMAIN_HTTP_SETUP)
.parentAsset(validDomainSetupEntity)
.assignedToAsset(HsHostingAssetEntity.builder().type(UNIX_USER).build())
.identifier("example.org|HTTP")
.config(Map.ofEntries(
entry("passenger-errorpage", true),
entry("subdomains", Array.of("www", "test")
)
));
}
@Test
void containsExpectedProperties() {
// when
final var validator = HostingAssetEntityValidatorRegistry.forType(DOMAIN_HTTP_SETUP);
// then
assertThat(validator.properties()).map(Map::toString).containsExactlyInAnyOrder(
"{type=boolean, propertyName=htdocsfallback, defaultValue=true}",
"{type=boolean, propertyName=indexes, defaultValue=true}",
"{type=boolean, propertyName=cgi, defaultValue=true}",
"{type=boolean, propertyName=passenger, defaultValue=true}",
"{type=boolean, propertyName=passenger-errorpage}",
"{type=boolean, propertyName=fastcgi, defaultValue=true}",
"{type=boolean, propertyName=autoconfig, defaultValue=true}",
"{type=boolean, propertyName=greylisting, defaultValue=true}",
"{type=boolean, propertyName=includes, defaultValue=true}",
"{type=boolean, propertyName=letsencrypt, defaultValue=true}",
"{type=boolean, propertyName=multiviews, defaultValue=true}",
"{type=string, propertyName=fcgi-php-bin, matchesRegEx=[^/], provided=[/usr/lib/cgi-bin/php], defaultValue=/usr/lib/cgi-bin/php}",
"{type=string, propertyName=passenger-nodejs, matchesRegEx=[^/], provided=[/usr/bin/node], defaultValue=/usr/bin/node}",
"{type=string, propertyName=passenger-python, matchesRegEx=[^/], provided=[/usr/bin/python3], defaultValue=/usr/bin/python3}",
"{type=string, propertyName=passenger-ruby, matchesRegEx=[^/], provided=[/usr/bin/ruby], defaultValue=/usr/bin/ruby}",
"{type=string[], propertyName=subdomains, elementsOf={type=string, propertyName=subdomains, matchesRegEx=[(?!-)[A-Za-z0-9-]{1,63}(?<!-)], required=true}}"
);
}
@Test
void preprocessesTakesIdentifierFromParent() {
// given
final var givenEntity = validEntityBuilder().build();
assertThat(givenEntity.getParentAsset().getIdentifier()).as("preconditon failed").isEqualTo("example.org");
final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
// when
validator.preprocessEntity(givenEntity);
// then
assertThat(givenEntity.getIdentifier()).isEqualTo("example.org|HTTP");
}
@Test
void rejectsInvalidIdentifier() {
// given
final var givenEntity = validEntityBuilder().identifier("example.org").build();
final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
// when
final var result = validator.validateEntity(givenEntity);
// then
assertThat(result).containsExactly(
"'identifier' expected to match '^example.org\\Q|HTTP\\E$', but is 'example.org'"
);
}
@Test
void acceptsValidIdentifier() {
// given
final var givenEntity = validEntityBuilder().identifier(validDomainSetupEntity.getIdentifier()+"|HTTP").build();
final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
// when
final var result = validator.validateEntity(givenEntity);
// then
assertThat(result).isEmpty();
}
@Test
void rejectsInvalidReferencedEntities() {
// given
final var mangedServerHostingAssetEntity = validEntityBuilder()
.bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build())
.parentAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).build())
.assignedToAsset(null)
.build();
final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
// when
final var result = validator.validateEntity(mangedServerHostingAssetEntity);
// then
assertThat(result).containsExactlyInAnyOrder(
"'DOMAIN_HTTP_SETUP:example.org|HTTP.bookingItem' must be null but is of type CLOUD_SERVER",
"'DOMAIN_HTTP_SETUP:example.org|HTTP.parentAsset' must be of type DOMAIN_SETUP but is of type MANAGED_WEBSPACE",
"'DOMAIN_HTTP_SETUP:example.org|HTTP.assignedToAsset' must be of type UNIX_USER but is null");
}
@Test
void acceptsValidEntity() {
// given
final var givenEntity = validEntityBuilder().build();
final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
// when
final var errors = validator.validateEntity(givenEntity);
// then
assertThat(errors).isEmpty();
}
@Test
void rejectsInvalidProperties() {
// given
final var mangedServerHostingAssetEntity = validEntityBuilder()
.config(Map.ofEntries(
entry("htdocsfallback", "false"),
entry("fcgi-php-bin", "false"),
entry("subdomains", Array.of("", "@", "example.com"))
))
.build();
final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
// when
final var result = validator.validateEntity(mangedServerHostingAssetEntity);
// then
assertThat(result).containsExactlyInAnyOrder(
"'DOMAIN_HTTP_SETUP:example.org|HTTP.config.htdocsfallback' is expected to be of type Boolean, but is of type String",
"'DOMAIN_HTTP_SETUP:example.org|HTTP.config.fcgi-php-bin' is expected to match any of [^/] but 'false' does not match",
"'DOMAIN_HTTP_SETUP:example.org|HTTP.config.subdomains' is expected to match any of [(?!-)[A-Za-z0-9-]{1,63}(?<!-)] but '' does not match",
"'DOMAIN_HTTP_SETUP:example.org|HTTP.config.subdomains' is expected to match any of [(?!-)[A-Za-z0-9-]{1,63}(?<!-)] but '@' does not match",
"'DOMAIN_HTTP_SETUP:example.org|HTTP.config.subdomains' is expected to match any of [(?!-)[A-Za-z0-9-]{1,63}(?<!-)] but 'example.com' does not match");
}
}

View File

@@ -42,7 +42,7 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
void rejectsInvalidIdentifier(final InvalidDomainNameIdentifier testCase) {
// given
final var givenEntity = validEntityBuilder().identifier(testCase.domainName).build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
// when
final var result = validator.validateEntity(givenEntity);
@@ -72,7 +72,7 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
void acceptsValidIdentifier(final ValidDomainNameIdentifier testCase) {
// given
final var givenEntity = validEntityBuilder().identifier(testCase.domainName).build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
// when
final var result = validator.validateEntity(givenEntity);
@@ -84,7 +84,7 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
@Test
void containsNoProperties() {
// when
final var validator = HsHostingAssetEntityValidatorRegistry.forType(CLOUD_SERVER);
final var validator = HostingAssetEntityValidatorRegistry.forType(CLOUD_SERVER);
// then
assertThat(validator.properties()).map(Map::toString).isEmpty();
@@ -98,7 +98,7 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
.assignedToAsset(HsHostingAssetEntity.builder().type(MANAGED_SERVER).build())
.bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build())
.build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
// when
final var result = validator.validateEntity(mangedServerHostingAssetEntity);

View File

@@ -18,7 +18,7 @@ class HsEMailAliasHostingAssetValidatorUnitTest {
@Test
void containsAllValidations() {
// when
final var validator = HsHostingAssetEntityValidatorRegistry.forType(EMAIL_ALIAS);
final var validator = HostingAssetEntityValidatorRegistry.forType(EMAIL_ALIAS);
// then
assertThat(validator.properties()).map(Map::toString).containsExactlyInAnyOrder(
@@ -36,7 +36,7 @@ class HsEMailAliasHostingAssetValidatorUnitTest {
entry("target", Array.of("xyz00", "xyz00-abc", "office@example.com"))
))
.build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(emailAliasHostingAssetEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(emailAliasHostingAssetEntity.getType());
// when
final var result = validator.validateEntity(emailAliasHostingAssetEntity);
@@ -56,7 +56,7 @@ class HsEMailAliasHostingAssetValidatorUnitTest {
entry("target", Array.of("xyz00", "xyz00-abc", "garbage", "office@example.com"))
))
.build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(emailAliasHostingAssetEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(emailAliasHostingAssetEntity.getType());
// when
final var result = validator.validateEntity(emailAliasHostingAssetEntity);
@@ -77,7 +77,7 @@ class HsEMailAliasHostingAssetValidatorUnitTest {
entry("target", Array.of("office@example.com"))
))
.build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(emailAliasHostingAssetEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(emailAliasHostingAssetEntity.getType());
// when
final var result = validator.validateEntity(emailAliasHostingAssetEntity);
@@ -100,7 +100,7 @@ class HsEMailAliasHostingAssetValidatorUnitTest {
entry("target", Array.of("office@example.com"))
))
.build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(emailAliasHostingAssetEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(emailAliasHostingAssetEntity.getType());
// when
final var result = validator.validateEntity(emailAliasHostingAssetEntity);

View File

@@ -31,7 +31,7 @@ class HsManagedServerHostingAssetValidatorUnitTest {
entry("monit_max_ram_usage", 101)
))
.build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedWebspaceHostingAssetEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(mangedWebspaceHostingAssetEntity.getType());
// when
final var result = validator.validateEntity(mangedWebspaceHostingAssetEntity);
@@ -42,7 +42,7 @@ class HsManagedServerHostingAssetValidatorUnitTest {
"'MANAGED_SERVER:vm1234.assignedToAsset' must be null but is of type CLOUD_SERVER",
"'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'");
"'MANAGED_SERVER:vm1234.config.monit_max_hdd_usage' is expected to be of type Integer, but is of type String");
}
@Test
@@ -53,7 +53,7 @@ class HsManagedServerHostingAssetValidatorUnitTest {
.identifier("xyz00")
.bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.MANAGED_SERVER).build())
.build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
// when
final var result = validator.validateEntity(mangedServerHostingAssetEntity);
@@ -73,7 +73,7 @@ class HsManagedServerHostingAssetValidatorUnitTest {
.parentAsset(HsHostingAssetEntity.builder().type(CLOUD_SERVER).build())
.assignedToAsset(HsHostingAssetEntity.builder().type(MANAGED_SERVER).build())
.build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
// when
final var result = validator.validateEntity(mangedServerHostingAssetEntity);

View File

@@ -59,7 +59,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest {
@Test
void acceptsAlienIdentifierPrefixForPreExistingEntity() {
// given
final var validator = HsHostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE);
final var validator = HostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE);
final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder()
.type(MANAGED_WEBSPACE)
.bookingItem(HsBookingItemEntity.builder()
@@ -81,7 +81,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest {
@Test
void validatesIdentifierAndReferencedEntities() {
// given
final var validator = HsHostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE);
final var validator = HostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE);
final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder()
.type(MANAGED_WEBSPACE)
.bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.MANAGED_WEBSPACE).build())
@@ -99,7 +99,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest {
@Test
void validatesUnknownProperties() {
// given
final var validator = HsHostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE);
final var validator = HostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE);
final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder()
.type(MANAGED_WEBSPACE)
.bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.MANAGED_WEBSPACE).build())
@@ -120,7 +120,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest {
@Test
void validatesValidEntity() {
// given
final var validator = HsHostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE);
final var validator = HostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE);
final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder()
.type(MANAGED_WEBSPACE)
.bookingItem(HsBookingItemEntity.builder()
@@ -145,7 +145,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest {
@Test
void rejectsInvalidEntityReferences() {
// given
final var validator = HsHostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE);
final var validator = HostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE);
final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder()
.type(MANAGED_WEBSPACE)
.bookingItem(HsBookingItemEntity.builder()

View File

@@ -47,7 +47,7 @@ class HsUnixUserHostingAssetValidatorUnitTest {
void preparesUnixUser() {
// given
final var unixUserHostingAsset = GIVEN_VALID_UNIX_USER_HOSTING_ASSET;
final var validator = HsHostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType());
// when
LinuxEtcShadowHashGenerator.nextSalt("Ly3LbsArtL5u4EVt");
@@ -66,7 +66,7 @@ class HsUnixUserHostingAssetValidatorUnitTest {
void validatesValidUnixUser() {
// given
final var unixUserHostingAsset = GIVEN_VALID_UNIX_USER_HOSTING_ASSET;
final var validator = HsHostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType());
// when
final var result = Stream.concat(
@@ -97,7 +97,7 @@ class HsUnixUserHostingAssetValidatorUnitTest {
entry("password", "short")
))
.build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType());
// when
final var result = validator.validateEntity(unixUserHostingAsset);
@@ -110,7 +110,7 @@ class HsUnixUserHostingAssetValidatorUnitTest {
"'UNIX_USER:abc00-temp.config.HDD soft quota' is expected to be at most 100 but is 200",
"'UNIX_USER:abc00-temp.config.shell' is expected to be one of [/bin/false, /bin/bash, /bin/csh, /bin/dash, /usr/bin/tcsh, /usr/bin/zsh, /usr/bin/passwd] but is '/is/invalid'",
"'UNIX_USER:abc00-temp.config.homedir' is readonly but given as '/is/read-only'",
"'UNIX_USER:abc00-temp.config.totpKey' is expected to match any of [^0x([0-9A-Fa-f]{2})+$] but provided value does not match any",
"'UNIX_USER:abc00-temp.config.totpKey' is expected to match any of [^0x([0-9A-Fa-f]{2})+$] but provided value does not match",
"'UNIX_USER:abc00-temp.config.password' length is expected to be at min 8 but length of provided value is 5",
"'UNIX_USER:abc00-temp.config.password' must contain at least one character of at least 3 of the following groups: upper case letters, lower case letters, digits, special characters"
);
@@ -124,7 +124,7 @@ class HsUnixUserHostingAssetValidatorUnitTest {
.parentAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).identifier("abc00").build())
.identifier("xyz99-temp")
.build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType());
// when
final var result = validator.validateEntity(unixUserHostingAsset);
@@ -138,7 +138,7 @@ class HsUnixUserHostingAssetValidatorUnitTest {
void revampsUnixUser() {
// given
final var unixUserHostingAsset = GIVEN_VALID_UNIX_USER_HOSTING_ASSET;
final var validator = HsHostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType());
final var validator = HostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType());
// when
LinuxEtcShadowHashGenerator.nextSalt("Ly3LbsArtL5u4EVt");
@@ -155,7 +155,7 @@ class HsUnixUserHostingAssetValidatorUnitTest {
@Test
void describesItsProperties() {
// given
final var validator = HsHostingAssetEntityValidatorRegistry.forType(UNIX_USER);
final var validator = HostingAssetEntityValidatorRegistry.forType(UNIX_USER);
// when
final var props = validator.properties();