@Test public void validateDomainVhosts_vhostPathSlashIsOverlapped() { Domain domain = getValidDomain(); domain.setVhostMode(true); Domain otherDomain = getValidDomain(); otherDomain.setId("otherDomain"); otherDomain.setVhostMode(true); otherDomain.getVhosts().get(0).setPath("/"); Set<Domain> otherDomains = new HashSet<>(); otherDomains.add(otherDomain); Throwable throwable = VirtualHostValidator.validateDomainVhosts(domain, otherDomains).blockingGet(); assertNotNull(throwable); assertTrue(throwable instanceof InvalidVirtualHostException); }
public static Completable validateDomainVhosts(Domain domain, Set<Domain> domains) { List<VirtualHost> otherVhosts = domains.stream() .filter(d -> !d.getId().equals(domain.getId())) .filter(Domain::isVhostMode) .flatMap(d -> d.getVhosts().stream()) .collect(Collectors.toList()); List<String> otherPaths = domains.stream() .filter(d -> !d.getId().equals(domain.getId())) .filter(d -> !d.isVhostMode()) .map(Domain::getPath) .collect(Collectors.toList()); List<String> paths; if (domain.isVhostMode()) { paths = domain.getVhosts().stream() .flatMap(virtualHost -> otherVhosts.stream() .filter(otherVhost -> virtualHost.getHost().equals(otherVhost.getHost()))) .map(VirtualHost::getPath).collect(Collectors.toList()); for (VirtualHost vhost : domain.getVhosts()) { List<String> pathsToCheck = paths; if(!vhost.getPath().equals("/")) { pathsToCheck = new ArrayList<>(paths); pathsToCheck.addAll(otherPaths); } for (String otherPath : pathsToCheck) { if (overlap(vhost.getPath(), otherPath)) { return Completable.error(new InvalidVirtualHostException("Path [" + vhost.getPath() + "] overlap path defined in another security domain")); } if (overlap(otherPath, vhost.getPath())) { return Completable.error(new InvalidVirtualHostException("Path [" + vhost.getPath() + "] is overlapped by another security domain")); } } } } else { paths = new ArrayList<>(otherPaths); paths.addAll(otherVhosts.stream().map(VirtualHost::getPath).filter(path -> !"/".equals(path)).collect(Collectors.toList())); for (String otherPath : paths) { if (overlap(domain.getPath(), otherPath)) { return Completable.error(new InvalidVirtualHostException("Path [" + domain.getPath() + "] overlap path defined in another security domain")); } if (overlap(otherPath, domain.getPath())) { return Completable.error(new InvalidVirtualHostException("Path [" + domain.getPath() + "] is overlapped by another security domain")); } } } return Completable.complete(); }
VirtualHostValidator { public static Completable validateDomainVhosts(Domain domain, Set<Domain> domains) { List<VirtualHost> otherVhosts = domains.stream() .filter(d -> !d.getId().equals(domain.getId())) .filter(Domain::isVhostMode) .flatMap(d -> d.getVhosts().stream()) .collect(Collectors.toList()); List<String> otherPaths = domains.stream() .filter(d -> !d.getId().equals(domain.getId())) .filter(d -> !d.isVhostMode()) .map(Domain::getPath) .collect(Collectors.toList()); List<String> paths; if (domain.isVhostMode()) { paths = domain.getVhosts().stream() .flatMap(virtualHost -> otherVhosts.stream() .filter(otherVhost -> virtualHost.getHost().equals(otherVhost.getHost()))) .map(VirtualHost::getPath).collect(Collectors.toList()); for (VirtualHost vhost : domain.getVhosts()) { List<String> pathsToCheck = paths; if(!vhost.getPath().equals("/")) { pathsToCheck = new ArrayList<>(paths); pathsToCheck.addAll(otherPaths); } for (String otherPath : pathsToCheck) { if (overlap(vhost.getPath(), otherPath)) { return Completable.error(new InvalidVirtualHostException("Path [" + vhost.getPath() + "] overlap path defined in another security domain")); } if (overlap(otherPath, vhost.getPath())) { return Completable.error(new InvalidVirtualHostException("Path [" + vhost.getPath() + "] is overlapped by another security domain")); } } } } else { paths = new ArrayList<>(otherPaths); paths.addAll(otherVhosts.stream().map(VirtualHost::getPath).filter(path -> !"/".equals(path)).collect(Collectors.toList())); for (String otherPath : paths) { if (overlap(domain.getPath(), otherPath)) { return Completable.error(new InvalidVirtualHostException("Path [" + domain.getPath() + "] overlap path defined in another security domain")); } if (overlap(otherPath, domain.getPath())) { return Completable.error(new InvalidVirtualHostException("Path [" + domain.getPath() + "] is overlapped by another security domain")); } } } return Completable.complete(); } }
VirtualHostValidator { public static Completable validateDomainVhosts(Domain domain, Set<Domain> domains) { List<VirtualHost> otherVhosts = domains.stream() .filter(d -> !d.getId().equals(domain.getId())) .filter(Domain::isVhostMode) .flatMap(d -> d.getVhosts().stream()) .collect(Collectors.toList()); List<String> otherPaths = domains.stream() .filter(d -> !d.getId().equals(domain.getId())) .filter(d -> !d.isVhostMode()) .map(Domain::getPath) .collect(Collectors.toList()); List<String> paths; if (domain.isVhostMode()) { paths = domain.getVhosts().stream() .flatMap(virtualHost -> otherVhosts.stream() .filter(otherVhost -> virtualHost.getHost().equals(otherVhost.getHost()))) .map(VirtualHost::getPath).collect(Collectors.toList()); for (VirtualHost vhost : domain.getVhosts()) { List<String> pathsToCheck = paths; if(!vhost.getPath().equals("/")) { pathsToCheck = new ArrayList<>(paths); pathsToCheck.addAll(otherPaths); } for (String otherPath : pathsToCheck) { if (overlap(vhost.getPath(), otherPath)) { return Completable.error(new InvalidVirtualHostException("Path [" + vhost.getPath() + "] overlap path defined in another security domain")); } if (overlap(otherPath, vhost.getPath())) { return Completable.error(new InvalidVirtualHostException("Path [" + vhost.getPath() + "] is overlapped by another security domain")); } } } } else { paths = new ArrayList<>(otherPaths); paths.addAll(otherVhosts.stream().map(VirtualHost::getPath).filter(path -> !"/".equals(path)).collect(Collectors.toList())); for (String otherPath : paths) { if (overlap(domain.getPath(), otherPath)) { return Completable.error(new InvalidVirtualHostException("Path [" + domain.getPath() + "] overlap path defined in another security domain")); } if (overlap(otherPath, domain.getPath())) { return Completable.error(new InvalidVirtualHostException("Path [" + domain.getPath() + "] is overlapped by another security domain")); } } } return Completable.complete(); }  }
VirtualHostValidator { public static Completable validateDomainVhosts(Domain domain, Set<Domain> domains) { List<VirtualHost> otherVhosts = domains.stream() .filter(d -> !d.getId().equals(domain.getId())) .filter(Domain::isVhostMode) .flatMap(d -> d.getVhosts().stream()) .collect(Collectors.toList()); List<String> otherPaths = domains.stream() .filter(d -> !d.getId().equals(domain.getId())) .filter(d -> !d.isVhostMode()) .map(Domain::getPath) .collect(Collectors.toList()); List<String> paths; if (domain.isVhostMode()) { paths = domain.getVhosts().stream() .flatMap(virtualHost -> otherVhosts.stream() .filter(otherVhost -> virtualHost.getHost().equals(otherVhost.getHost()))) .map(VirtualHost::getPath).collect(Collectors.toList()); for (VirtualHost vhost : domain.getVhosts()) { List<String> pathsToCheck = paths; if(!vhost.getPath().equals("/")) { pathsToCheck = new ArrayList<>(paths); pathsToCheck.addAll(otherPaths); } for (String otherPath : pathsToCheck) { if (overlap(vhost.getPath(), otherPath)) { return Completable.error(new InvalidVirtualHostException("Path [" + vhost.getPath() + "] overlap path defined in another security domain")); } if (overlap(otherPath, vhost.getPath())) { return Completable.error(new InvalidVirtualHostException("Path [" + vhost.getPath() + "] is overlapped by another security domain")); } } } } else { paths = new ArrayList<>(otherPaths); paths.addAll(otherVhosts.stream().map(VirtualHost::getPath).filter(path -> !"/".equals(path)).collect(Collectors.toList())); for (String otherPath : paths) { if (overlap(domain.getPath(), otherPath)) { return Completable.error(new InvalidVirtualHostException("Path [" + domain.getPath() + "] overlap path defined in another security domain")); } if (overlap(otherPath, domain.getPath())) { return Completable.error(new InvalidVirtualHostException("Path [" + domain.getPath() + "] is overlapped by another security domain")); } } } return Completable.complete(); }  static Completable validate(VirtualHost vhost); static Completable validateDomainVhosts(Domain domain, Set<Domain> domains); }
VirtualHostValidator { public static Completable validateDomainVhosts(Domain domain, Set<Domain> domains) { List<VirtualHost> otherVhosts = domains.stream() .filter(d -> !d.getId().equals(domain.getId())) .filter(Domain::isVhostMode) .flatMap(d -> d.getVhosts().stream()) .collect(Collectors.toList()); List<String> otherPaths = domains.stream() .filter(d -> !d.getId().equals(domain.getId())) .filter(d -> !d.isVhostMode()) .map(Domain::getPath) .collect(Collectors.toList()); List<String> paths; if (domain.isVhostMode()) { paths = domain.getVhosts().stream() .flatMap(virtualHost -> otherVhosts.stream() .filter(otherVhost -> virtualHost.getHost().equals(otherVhost.getHost()))) .map(VirtualHost::getPath).collect(Collectors.toList()); for (VirtualHost vhost : domain.getVhosts()) { List<String> pathsToCheck = paths; if(!vhost.getPath().equals("/")) { pathsToCheck = new ArrayList<>(paths); pathsToCheck.addAll(otherPaths); } for (String otherPath : pathsToCheck) { if (overlap(vhost.getPath(), otherPath)) { return Completable.error(new InvalidVirtualHostException("Path [" + vhost.getPath() + "] overlap path defined in another security domain")); } if (overlap(otherPath, vhost.getPath())) { return Completable.error(new InvalidVirtualHostException("Path [" + vhost.getPath() + "] is overlapped by another security domain")); } } } } else { paths = new ArrayList<>(otherPaths); paths.addAll(otherVhosts.stream().map(VirtualHost::getPath).filter(path -> !"/".equals(path)).collect(Collectors.toList())); for (String otherPath : paths) { if (overlap(domain.getPath(), otherPath)) { return Completable.error(new InvalidVirtualHostException("Path [" + domain.getPath() + "] overlap path defined in another security domain")); } if (overlap(otherPath, domain.getPath())) { return Completable.error(new InvalidVirtualHostException("Path [" + domain.getPath() + "] is overlapped by another security domain")); } } } return Completable.complete(); }  static Completable validate(VirtualHost vhost); static Completable validateDomainVhosts(Domain domain, Set<Domain> domains);  }