Search in sources :

Example 1 with InvalidDomainException

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);
}
Also used : InvalidDomainException(io.gravitee.am.service.exception.InvalidDomainException) Domain(io.gravitee.am.model.Domain) Test(org.junit.Test)

Example 2 with 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);
}
Also used : Completable(io.reactivex.Completable) ArrayList(java.util.ArrayList) InvalidDomainException(io.gravitee.am.service.exception.InvalidDomainException)

Example 3 with InvalidDomainException

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);
}
Also used : InvalidDomainException(io.gravitee.am.service.exception.InvalidDomainException) Domain(io.gravitee.am.model.Domain) Test(org.junit.Test)

Example 4 with 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);
}
Also used : InvalidDomainException(io.gravitee.am.service.exception.InvalidDomainException) Domain(io.gravitee.am.model.Domain) Test(org.junit.Test)

Example 5 with 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);
}
Also used : InvalidDomainException(io.gravitee.am.service.exception.InvalidDomainException) Domain(io.gravitee.am.model.Domain) Test(org.junit.Test)

Aggregations

InvalidDomainException (io.gravitee.am.service.exception.InvalidDomainException)9 Domain (io.gravitee.am.model.Domain)8 Test (org.junit.Test)8 VirtualHost (io.gravitee.am.model.VirtualHost)1 Completable (io.reactivex.Completable)1 ArrayList (java.util.ArrayList)1