Search in sources :

Example 1 with LRUCache

use of org.minidns.cache.LRUCache in project minidns by MiniDNS.

the class DNSClientTest method testSingleRecordQuery.

@SuppressWarnings("unchecked")
@Test
public void testSingleRecordQuery() throws IOException {
    DNSClient client = new DNSClient(new LRUCache(0));
    applyStubRecords(client, record("www.example.com", a("127.0.0.1")));
    DNSMessage response = client.query("www.example.com", TYPE.A);
    assertNotNull(response);
    assertEquals(1, response.answerSection.size());
    assertEquals(TYPE.A, response.answerSection.get(0).type);
    assertArrayEquals(new byte[] { 127, 0, 0, 1 }, ((A) response.answerSection.get(0).payloadData).getIp());
    response = client.query("www2.example.com", TYPE.A);
    assertNull(response);
    response = client.query("www.example.com", TYPE.CNAME);
    assertNull(response);
}
Also used : LRUCache(org.minidns.cache.LRUCache) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 2 with LRUCache

use of org.minidns.cache.LRUCache in project minidns by MiniDNS.

the class DNSClientTest method testReturnNullSource.

@Test
public void testReturnNullSource() throws IOException {
    class NullSource extends DNSDataSource {

        boolean queried = false;

        @Override
        public DNSMessage query(DNSMessage message, InetAddress address, int port) {
            queried = true;
            return null;
        }
    }
    DNSClient client = new DNSClient(new LRUCache(0));
    NullSource source = new NullSource();
    client.setDataSource(source);
    DNSMessage message = client.query("www.example.com", TYPE.A);
    assertNull(message);
    assertTrue(source.queried);
}
Also used : DNSDataSource(org.minidns.source.DNSDataSource) LRUCache(org.minidns.cache.LRUCache) InetAddress(java.net.InetAddress) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 3 with LRUCache

use of org.minidns.cache.LRUCache in project minidns by MiniDNS.

the class IterativeDNSClientTest method notGluedNsTest.

@SuppressWarnings("unchecked")
@Test
public void notGluedNsTest() throws IOException {
    IterativeDNSClient client = new IterativeDNSClient(new LRUCache(0));
    applyZones(client, rootZone(record("com", ns("ns.com")), record("net", ns("ns.net")), record("ns.com", a("1.1.1.1")), record("ns.net", a("1.1.2.1"))), zone("com", "ns.com", "1.1.1.1", record("example.com", ns("example.ns.net"))), zone("net", "ns.net", "1.1.2.1", record("example.ns.net", a("1.1.2.2"))), zone("example.com", "example.ns.net", "1.1.2.2", record("www.example.com", a("1.1.1.3"))));
    DNSMessage message = client.query("www.example.com", TYPE.A);
    assertNotNull(message);
    List<Record<? extends Data>> answers = message.answerSection;
    assertEquals(1, answers.size());
    assertEquals(TYPE.A, answers.get(0).type);
    assertArrayEquals(new byte[] { 1, 1, 1, 3 }, ((A) answers.get(0).payloadData).getIp());
}
Also used : LRUCache(org.minidns.cache.LRUCache) Record(org.minidns.record.Record) Data(org.minidns.record.Data) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 4 with LRUCache

use of org.minidns.cache.LRUCache in project minidns by MiniDNS.

the class IterativeDNSClientTest method basicIterativeTest.

@SuppressWarnings("unchecked")
@Test
public void basicIterativeTest() throws IOException {
    IterativeDNSClient client = new IterativeDNSClient(new LRUCache(0));
    applyZones(client, rootZone(record("com", ns("ns.com")), record("ns.com", a("1.1.1.1"))), zone("com", "ns.com", "1.1.1.1", record("example.com", ns("ns.example.com")), record("ns.example.com", a("1.1.1.2"))), zone("example.com", "ns.example.com", "1.1.1.2", record("www.example.com", a("1.1.1.3"))));
    DNSMessage message = client.query("www.example.com", TYPE.A);
    assertNotNull(message);
    List<Record<? extends Data>> answers = message.answerSection;
    assertEquals(1, answers.size());
    assertEquals(TYPE.A, answers.get(0).type);
    assertArrayEquals(new byte[] { 1, 1, 1, 3 }, ((A) answers.get(0).payloadData).getIp());
}
Also used : LRUCache(org.minidns.cache.LRUCache) Record(org.minidns.record.Record) Data(org.minidns.record.Data) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 5 with LRUCache

use of org.minidns.cache.LRUCache in project minidns by MiniDNS.

the class DNSSECTest method testOarcDaneBadSig.

@Ignore
@IntegrationTest
public static void testOarcDaneBadSig() throws Exception {
    DNSSECClient client = new DNSSECClient(new LRUCache(1024));
    assertFalse(client.query("_443._tcp.bad-sig.dane.dns-oarc.net", Record.TYPE.TLSA).authenticData);
}
Also used : LRUCache(org.minidns.cache.LRUCache) DNSSECClient(org.minidns.dnssec.DNSSECClient) Ignore(org.junit.Ignore)

Aggregations

LRUCache (org.minidns.cache.LRUCache)12 DNSMessage (org.minidns.dnsmessage.DNSMessage)6 Test (org.junit.Test)5 DNSSECClient (org.minidns.dnssec.DNSSECClient)5 DNSClient (org.minidns.DNSClient)2 Data (org.minidns.record.Data)2 Record (org.minidns.record.Record)2 InetAddress (java.net.InetAddress)1 ArrayList (java.util.ArrayList)1 Ignore (org.junit.Ignore)1 DNSCache (org.minidns.DNSCache)1 ExtendedLRUCache (org.minidns.cache.ExtendedLRUCache)1 FullLRUCache (org.minidns.cache.FullLRUCache)1 DNSDataSource (org.minidns.source.DNSDataSource)1 NetworkDataSourceWithAccounting (org.minidns.source.NetworkDataSourceWithAccounting)1