public InMemoryDNSService registerRecord(String hostname, List<InetAddress> addresses, Collection<String> mxRecords, Collection<String> txtRecords) { records.put(hostname, dnsRecordFor(mxRecords, txtRecords, addresses)); return this; }
private DNSRecord hostRecord(final String host) throws UnknownHostException { Predicate<? super Entry<String, DNSRecord>> filterByKey = entry -> entry.getKey().equals(host); return getDNSEntry(filterByKey).getValue(); }
@Override public List<InetAddress> getAllByName(String host) throws UnknownHostException { return hostRecord(host).addresses; }
/** * Return a fake DNSServer. */ protected DNSService getDNSServer(final String hostName) throws UnknownHostException { return new InMemoryDNSService() .registerMxRecord(hostName, "127.0.0.1") .registerMxRecord("127.0.0.1", "127.0.0.1"); }
@Before public void setUp() throws Exception { getInMemoryDns() .registerMxRecord("yopmail.com", fakeSmtp.getContainer().getContainerIp()); guiceJamesServer = getJmapServer(); guiceJamesServer.start(); DataProbe dataProbe = guiceJamesServer.getProbe(DataProbeImpl.class); dataProbe.addDomain(DOMAIN); dataProbe.addUser(USER_WITH_DOMAIN, PASSWORD); MailboxProbe mailboxProbe = guiceJamesServer.getProbe(MailboxProbeImpl.class); mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, USER_WITH_DOMAIN, DefaultMailboxes.SENT); mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, USER_WITH_DOMAIN, DefaultMailboxes.INBOX); await(); jmapGuiceProbe = guiceJamesServer.getProbe(JmapGuiceProbe.class); }
public InMemoryDNSService registerMxRecord(String hostname, String ip) throws UnknownHostException { InetAddress containerIp = InetAddress.getByName(ip); registerRecord(hostname, containerIp, hostname); return this; }
@Before public void setup() throws Exception { DNSService dnsServer = new InMemoryDNSService() .registerMxRecord("192.168.0.1", "192.168.0.1") .registerMxRecord("192.168.200.1", "192.168.200.1") .registerMxRecord("192.168.200.0", "192.168.200.0") .registerMxRecord("255.255.255.0", "255.255.255.0"); matcherConfig = FakeMatcherConfig.builder() .matcherName("AllowedNetworkIs") .condition("192.168.200.0/24") .build(); matcher = new RemoteAddrNotInNetwork(); matcher.setDNSService(dnsServer); matcher.init(matcherConfig); testRecipient = new MailAddress("test@james.apache.org"); }
public InMemoryDNSService registerRecord(String hostname, InetAddress address, String mxRecord) { Collection<String> emptyTxtRecords = ImmutableList.of(); registerRecord(hostname, ImmutableList.of(address), ImmutableList.of(mxRecord), emptyTxtRecords); return this; }
@Before public void setup() throws Exception { DNSService dnsServer = new InMemoryDNSService() .registerMxRecord("192.168.0.1", "192.168.0.1") .registerMxRecord("192.168.200.1", "192.168.200.1") .registerMxRecord("192.168.200.0", "192.168.200.0") .registerMxRecord("255.255.255.0", "255.255.255.0"); FakeMatcherConfig matcherConfig = FakeMatcherConfig.builder() .matcherName("AllowedNetworkIs") .condition("192.168.200.0/24") .build(); matcher = new RemoteAddrInNetwork(); matcher.setDNSService(dnsServer); matcher.init(matcherConfig); testRecipient = new MailAddress("test@james.apache.org"); }
@Override public Collection<String> findMXRecords(String hostname) throws TemporaryResolutionException { try { return hostRecord(hostname).mxRecords; } catch (UnknownHostException e) { throw new RuntimeException(e); } }
private DNSRecord dnsRecordFor(InetAddress addresses) { Collection<String> emptyList = ImmutableList.of(); return dnsRecordFor(emptyList, emptyList, ImmutableList.of(addresses)); }
@Override public String getHostName(final InetAddress addr) { Predicate<? super Entry<String, DNSRecord>> filterByValue = entry -> entry.getValue().contains(addr); try { return getDNSEntry(filterByValue).getKey(); } catch (UnknownHostException e) { throw new RuntimeException(e); } }
@Test public void testRejectLoopbackMX() throws Exception { String bannedAddress = "172.53.64.2"; DNSService dns = new InMemoryDNSService() .registerMxRecord(INVALID_HOST, bannedAddress) .registerMxRecord("255.255.255.255", "255.255.255.255") .registerMxRecord(bannedAddress, bannedAddress); MailAddress mailAddress = new MailAddress("test@" + INVALID_HOST); SMTPSession session = setupMockedSMTPSession(mailAddress); ValidRcptMX handler = new ValidRcptMX(); handler.setDNSService(dns); handler.setBannedNetworks(ImmutableList.of(bannedAddress), dns); HookReturnCode rCode = handler.doRcpt(session, null, mailAddress).getResult(); assertThat(HookReturnCode.deny()).describedAs("Reject").isEqualTo(rCode); } }
@Override public Collection<String> findTXTRecords(String hostname) { try { return hostRecord(hostname).txtRecords; } catch (UnknownHostException e) { throw new RuntimeException(e); } }
public InMemoryDNSService() { records = Maps.newHashMap(); records.put("0.0.0.0", dnsRecordFor(InetAddresses.forString("0.0.0.0"))); records.put("127.0.0.1", dnsRecordFor(InetAddresses.forString("127.0.0.1"))); }
@Override public InetAddress getByName(String host) throws UnknownHostException { return hostRecord(host).addresses.get(0); }