@Test public void containsDomainShouldReturnDetectedIp() throws Exception { String detected = "detected.tld"; String detectedIp = "148.25.32.1"; when(dnsService.getLocalHost()).thenReturn(InetAddress.getByName("127.0.0.1")); when(dnsService.getHostName(any(InetAddress.class))).thenReturn(detected); InetAddress detectedAddress = mock(InetAddress.class); when(detectedAddress.getHostAddress()).thenReturn(detectedIp); when(dnsService.getAllByName(detected)).thenReturn(ImmutableList.of(detectedAddress)); assertThat(domainList.containsDomain(Domain.of(detectedIp))).isTrue(); }
@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 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 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 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 containsDomainShouldNotInteractWithDNSWhenDisabled() throws Exception { domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false)); domainList.containsDomain(Domain.of("added.tld")); verifyZeroInteractions(dnsService); }