use of io.gravitee.am.service.exception.InvalidDomainException in project gravitee-access-management by gravitee-io.
the class DomainValidatorTest method validate_invalidEmptyVhosts.
@Test
public void validate_invalidEmptyVhosts() {
Domain domain = getValidDomain();
domain.setVhostMode(true);
domain.setVhosts(emptyList());
Throwable throwable = domainValidator.validate(domain, emptyList()).blockingGet();
assertNotNull(throwable);
assertTrue(throwable instanceof InvalidDomainException);
}
use of io.gravitee.am.service.exception.InvalidDomainException in project gravitee-access-management by gravitee-io.
the class DomainValidatorImpl method validate.
@Override
public Completable validate(Domain domain, List<String> domainRestrictions) {
List<Completable> chain = new ArrayList<>();
if (domain.getName().contains("/")) {
return Completable.error(new InvalidDomainException("Domain name cannot contain '/' character"));
}
if (!CollectionUtils.isEmpty(domainRestrictions) && !domain.isVhostMode()) {
return Completable.error(new InvalidDomainException("Domain can only work in vhost mode"));
}
if (domain.isVhostMode()) {
if (domain.getVhosts() == null || domain.getVhosts().isEmpty()) {
return Completable.error(new InvalidDomainException("VHost mode requires at least one VHost"));
}
// Check at there is only one vhost flagged with override entrypoint.
long count = domain.getVhosts().stream().filter(VirtualHost::isOverrideEntrypoint).count();
if (count > 1) {
return Completable.error(new InvalidDomainException("Only one vhost can be used to override entrypoint"));
} else if (count == 0) {
return Completable.error(new InvalidDomainException("You must select one vhost to override entrypoint"));
}
chain.addAll(domain.getVhosts().stream().map(vhost -> virtualHostValidator.validate(vhost, domainRestrictions)).collect(Collectors.toList()));
} else {
if ("/".equals(domain.getPath())) {
return Completable.error(new InvalidDomainException("'/' path is not allowed in context-path mode"));
}
chain.add(pathValidator.validate(domain.getPath()));
}
if (domain.getWebAuthnSettings() != null && domain.getWebAuthnSettings().getCertificates() != null) {
boolean containsInvalidCertFormat = domain.getWebAuthnSettings().getCertificates().values().stream().anyMatch(cert -> !(cert instanceof String) || (((String) cert).startsWith("-----") || ((String) cert).endsWith("-----")));
if (containsInvalidCertFormat) {
return Completable.error(new InvalidDomainException("WebAuthnSettings contains certificates with boundaries"));
}
}
return Completable.merge(chain);
}
use of io.gravitee.am.service.exception.InvalidDomainException in project gravitee-access-management by gravitee-io.
the class DomainValidatorTest method validate_invalidName.
@Test
public void validate_invalidName() {
Domain domain = getValidDomain();
domain.setName("Invalid/Name");
Throwable throwable = domainValidator.validate(domain, emptyList()).blockingGet();
assertNotNull(throwable);
assertTrue(throwable instanceof InvalidDomainException);
}
use of io.gravitee.am.service.exception.InvalidDomainException in project gravitee-access-management by gravitee-io.
the class DomainValidatorTest method validate_invalidNullVhosts.
@Test
public void validate_invalidNullVhosts() {
Domain domain = getValidDomain();
domain.setVhostMode(true);
domain.setVhosts(null);
Throwable throwable = domainValidator.validate(domain, emptyList()).blockingGet();
assertNotNull(throwable);
assertTrue(throwable instanceof InvalidDomainException);
}
use of io.gravitee.am.service.exception.InvalidDomainException in project gravitee-access-management by gravitee-io.
the class DomainValidatorTest method validate_invalidNoVhostFlaggedWithOverrideEntrypoint.
@Test
public void validate_invalidNoVhostFlaggedWithOverrideEntrypoint() {
Domain domain = getValidDomain();
domain.setVhostMode(true);
domain.getVhosts().get(0).setOverrideEntrypoint(false);
Throwable throwable = domainValidator.validate(domain, emptyList()).blockingGet();
assertNotNull(throwable);
assertTrue(throwable instanceof InvalidDomainException);
}
Aggregations