/** * @see org.apache.james.protocols.smtp.DNSService#getHostName(java.net.InetAddress) */ public String getHostName(InetAddress addr) { return dns.getHostName(addr); }
private void appendReportingMTA(StringBuffer buffer) { try { buffer.append("Reporting-MTA: dns; " + dns.getHostName(dns.getLocalHost())) .append(LINE_BREAK); } catch (Exception e) { LOGGER.error("Sending DSN without required Reporting-MTA Address", e); } }
/** * Simple localhost resolution. * * @throws UnknownHostException */ @Test public void testLocalhost() throws UnknownHostException { assertThat(DNS_SERVER.getByName("localhost").toString()).isEqualTo("localhost/127.0.0.1"); String localHost = DNS_SERVER.getHostName(InetAddress.getByName("127.0.0.1")); // We only can check if the returned localhost is not empty. Its value // depends on the hosts file. assertThat(localHost.length() > 0).isTrue(); }
private ImmutableList<Domain> detectDomains() { if (autoDetect) { String hostName; try { hostName = dns.getHostName(dns.getLocalHost()); } catch (UnknownHostException ue) { hostName = "localhost"; } LOGGER.info("Local host is: {}", hostName); if (hostName != null && !hostName.equals("localhost")) { return ImmutableList.of(Domain.of(hostName)); } } return ImmutableList.of(); }
hostName = getDNSServer().getHostName(getDNSServer().getLocalHost()); } catch (UnknownHostException ue) { hostName = "localhost";
@BeforeEach void setUp() throws Exception { DNSService dnsService = mock(DNSService.class); when(dnsService.getHostName(any())).thenReturn("localhost"); when(dnsService.getLocalHost()).thenReturn(InetAddress.getByName("localhost")); MemoryDomainList domainList = new MemoryDomainList(dnsService); domainList.setAutoDetectIP(false); createServer(domainList); }
@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(); }
@Before public void setUp() throws Exception { DNSService dnsService = mock(DNSService.class); dsnBounce = new DSNBounce(dnsService, DateFormats.getRFC822FormatForTimeZone(TimeZone.getTimeZone("UTC"))); fakeMailContext = FakeMailContext.defaultContext(); InetAddress localHost = InetAddress.getLocalHost(); when(dnsService.getLocalHost()) .thenReturn(localHost); when(dnsService.getHostName(localHost)) .thenReturn("myhost"); }
if (autodetect) { try { helloName = dns.getHostName(dns.getLocalHost()); } catch (UnknownHostException e) { helloName = "localhost";
@Test public void getDomainsShouldContainDetectedDomainsAndIps() throws Exception { domainList.configure(DomainListConfiguration.builder() .autoDetect(true) .autoDetectIp(true)); 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.getDomains()).contains(Domain.of(detected), Domain.of(detectedIp)); }
@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 getDomainsShouldContainDetectedDomainsAndIpsOfAddedDomains() throws Exception { domainList.configure(DomainListConfiguration.builder() .autoDetect(true) .autoDetectIp(true)); String added = "added.tld"; String detected = "detected.tld"; String detectedIp1 = "148.25.32.1"; String detectedIp2 = "148.25.32.2"; when(dnsService.getLocalHost()).thenReturn(InetAddress.getByName("127.0.0.1")); when(dnsService.getHostName(any(InetAddress.class))).thenReturn(detected); InetAddress detectedAddress1 = mock(InetAddress.class); InetAddress detectedAddress2 = mock(InetAddress.class); when(detectedAddress1.getHostAddress()).thenReturn(detectedIp1); when(detectedAddress2.getHostAddress()).thenReturn(detectedIp2); when(dnsService.getAllByName(detected)).thenReturn(ImmutableList.of(detectedAddress1)); when(dnsService.getAllByName(added)).thenReturn(ImmutableList.of(detectedAddress2)); domainList.addDomain(Domain.of(added)); assertThat(domainList.getDomains()) .extracting(Domain::name) .contains(detected, detectedIp1, added, detectedIp2); }
@BeforeEach void setup() throws Exception { DNSService dnsService = mock(DNSService.class); Mockito.when(dnsService.getHostName(any())).thenReturn("localhost"); Mockito.when(dnsService.getLocalHost()).thenReturn(InetAddress.getByName("localhost")); MemoryDomainList domainList = new MemoryDomainList(dnsService); domainList.setAutoDetectIP(false); domainList.setAutoDetect(false); domainList.addDomain(SENDER_DOMAIN); domainList.addDomain(SENDER_DOMAIN_2); dlpStore = new EventSourcingDLPConfigurationStore(new InMemoryEventStore()); createServer(dlpStore, domainList); }