@Test public void containsDomainShouldReturnDetectedDomains() throws Exception { domainList.configure(DomainListConfiguration.builder() .autoDetect(true) .autoDetectIp(false)); String detected = "detected.tld"; when(dnsService.getLocalHost()).thenReturn(InetAddress.getByName("127.0.0.1")); when(dnsService.getHostName(any(InetAddress.class))).thenReturn(detected); assertThat(domainList.containsDomain(Domain.of(detected))).isTrue(); }
@Test public void getDomainsShouldContainDetectedDomains() throws Exception { domainList.configure(DomainListConfiguration.builder() .autoDetect(true) .autoDetectIp(false)); String detected = "detected.tld"; when(dnsService.getLocalHost()).thenReturn(InetAddress.getByName("127.0.0.1")); when(dnsService.getHostName(any(InetAddress.class))).thenReturn(detected); assertThat(domainList.getDomains()).contains(Domain.of(detected)); }
@Test public void envDomainShouldBeAddedUponConfiguration() throws Exception { String envDomain = "env.tld"; when(envDetector.getEnv(AbstractDomainList.ENV_DOMAIN)).thenReturn(envDomain); domainList.configure(DomainListConfiguration.builder() .autoDetect(true) .autoDetectIp(false)); assertThat(domainList.containsDomain(Domain.of(envDomain))).isTrue(); }
@Test public void configureShouldNotFailWhenConfiguringDefaultDomain() throws Exception { XMLDomainList testee = new XMLDomainList(setUpDNSServer("localhost")); testee.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false) .defaultDomain(Domain.LOCALHOST) .addConfiguredDomain(DOMAIN_1)); assertThat(testee.getDomainListInternal()) .containsOnly(DOMAIN_1, Domain.LOCALHOST); } }
@Test public void isLocalUserShouldReturnTrueWhenUsedWithLocalPartAndUserExistOnDefaultDomain() throws Exception { domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false) .defaultDomain(DOMAIN_COM) .build()); usersRepository.addUser(USERMAIL, PASSWORD); assertThat(testee.isLocalUser(USERNAME)).isTrue(); }
@Test public void configureShouldNotAttemptToChangeLocalHostDefaultDomainWhenNoAutoDetect() throws Exception { domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false) .defaultDomain(Domain.LOCALHOST)); assertThat(domainList.getDefaultDomain()).isEqualTo(Domain.LOCALHOST); }
@Test public void configuredDomainShouldBeAddedUponConfiguration() throws Exception { Domain domain1 = Domain.of("conf1.tld"); Domain domain2 = Domain.of("conf2.tld"); domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false) .addConfiguredDomains(domain1, domain2)); assertThat(domainList.getDomains()).contains(domain1, domain2); }
@Test public void containsDomainShouldReturnFalseWhenDomainIsNotContained() throws Exception { Domain domain = Domain.of("added.tld"); domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false)); assertThat(domainList.containsDomain(domain)).isFalse(); }
@Test public void testGetDomainsAutoDetectLocalHost() throws Exception { XMLDomainList dom = new XMLDomainList(setUpDNSServer("localhost")); dom.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false) .addConfiguredDomains(Domain.of("domain1.")) .defaultDomain(DEFAULT_DOMAIN)); assertThat(dom.getDomains()).hasSize(2); }
@Test public void containsDomainShouldReturnTrueWhenDomainIsContained() throws Exception { Domain domain = Domain.of("added.tld"); domainList.addDomain(domain); domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false)); assertThat(domainList.containsDomain(domain)).isTrue(); }
@Test public void getDomainsShouldNotInteractWithDNSWhenDisabled() throws Exception { domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false)); domainList.getDomains(); verifyZeroInteractions(dnsService); }
@Test public void getDomainsShouldNotDetectDomainsWhenDisabled() throws Exception { Domain domain = Domain.of("domain.tld"); domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false) .defaultDomain(domain)); assertThat(domainList.getDomains()).containsOnly(domain); }
@Test public void removeDomainShouldFailWhenAlreadyConfigured() throws Exception { expectedException.expect(DomainListException.class); XMLDomainList testee = new XMLDomainList(setUpDNSServer("localhost")); testee.configure(DomainListConfiguration.builder() .autoDetect(true) .autoDetectIp(false) .addConfiguredDomain(DOMAIN_1)); testee.removeDomain(Domain.of("newDomain")); }
@Test public void addDomainShouldFailWhenAlreadyConfigured() throws Exception { expectedException.expect(DomainListException.class); XMLDomainList testee = new XMLDomainList(setUpDNSServer("hostname")); testee.configure(DomainListConfiguration.builder() .autoDetect(true) .autoDetectIp(false) .addConfiguredDomain(DOMAIN_1) .defaultDomain(DEFAULT_DOMAIN)); testee.addDomain(Domain.of("newDomain")); }
@Test public void isLocalUserShouldReturnFalseWhenUsedWithLocalPartAndUserDoNotExistOnDefaultDomain() throws Exception { domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false) .defaultDomain(Domain.of("any")) .build()); domainList.addDomain(DOMAIN_COM); usersRepository.addUser(USERMAIL, PASSWORD); assertThat(testee.isLocalUser(USERNAME)).isFalse(); }
@Test public void containsDomainShouldNotInteractWithDNSWhenDisabled() throws Exception { domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false)); domainList.containsDomain(Domain.of("added.tld")); verifyZeroInteractions(dnsService); }
@Test public void testGetDomainsAutoDetectNotLocalHost() throws Exception { XMLDomainList dom = new XMLDomainList(setUpDNSServer("local")); dom.configure(DomainListConfiguration.builder() .autoDetect(true) .autoDetectIp(false) .addConfiguredDomains(Domain.of("domain1.")) .defaultDomain(DEFAULT_DOMAIN)); assertThat(dom.getDomains()).hasSize(3); }
@Test public void testGetDomains() throws Exception { XMLDomainList dom = new XMLDomainList(setUpDNSServer("localhost")); dom.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false) .addConfiguredDomains(Domain.of("domain1."), Domain.of("domain2.")) .defaultDomain(DEFAULT_DOMAIN)); assertThat(dom.getDomains()).hasSize(3); }
@Test public void testNoConfiguredDomains() throws Exception { XMLDomainList dom = new XMLDomainList(setUpDNSServer("localhost")); dom.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false) .defaultDomain(DEFAULT_DOMAIN)); assertThat(dom.getDomains()).containsOnly(DEFAULT_DOMAIN); }
@Test public void getDomainsShouldListAddedDomain() throws Exception { Domain defaultDomain = Domain.of("default.tld"); Domain domain = Domain.of("added.tld"); domainList.addDomain(domain); domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false) .defaultDomain(defaultDomain)); assertThat(domainList.getDomains()).containsOnly(domain, defaultDomain); }