Search in sources :

Example 16 with DNSMessage

use of org.minidns.dnsmessage.DNSMessage 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 17 with DNSMessage

use of org.minidns.dnsmessage.DNSMessage 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 18 with DNSMessage

use of org.minidns.dnsmessage.DNSMessage in project minidns by MiniDNS.

the class MiniDNSStats method gatherStatsFor.

public static StringBuilder gatherStatsFor(DNSSECClient client, String testName, String name, TYPE type) throws IOException {
    DNSMessage response;
    long start, stop;
    start = System.currentTimeMillis();
    response = client.query(name, type);
    stop = System.currentTimeMillis();
    StringBuilder sb = new StringBuilder();
    sb.append(testName).append('\n');
    char[] headline = new char[testName.length()];
    Arrays.fill(headline, '#');
    sb.append(headline).append('\n');
    sb.append(response).append('\n');
    sb.append("Took ").append(stop - start).append("ms").append('\n');
    sb.append(getStats(client)).append('\n');
    sb.append('\n');
    return sb;
}
Also used : DNSMessage(org.minidns.dnsmessage.DNSMessage)

Example 19 with DNSMessage

use of org.minidns.dnsmessage.DNSMessage in project minidns by MiniDNS.

the class DNSSECClientTest method testSingleZSK.

@SuppressWarnings("unchecked")
@Test
public void testSingleZSK() throws IOException {
    applyZones(client, signedRootZone(sign(rootKSK, "", rootPrivateKSK, algorithm, record("", rootKSK), record("", rootZSK)), sign(rootZSK, "", rootPrivateZSK, algorithm, record("com", ds("com", digestType, comKSK))), sign(rootZSK, "", rootPrivateZSK, algorithm, record("com", ns("ns.com"))), sign(rootZSK, "", rootPrivateZSK, algorithm, record("ns.com", a("1.1.1.1")))), signedZone("com", "ns.com", "1.1.1.1", sign(comKSK, "com", comPrivateKSK, algorithm, record("com", comKSK)), sign(comKSK, "com", comPrivateKSK, algorithm, record("example.com", a("1.1.1.2")))));
    DNSMessage message = client.query("example.com", Record.TYPE.A);
    assertNotNull(message);
    assertTrue(message.authenticData);
    checkCorrectExampleMessage(message);
}
Also used : DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 20 with DNSMessage

use of org.minidns.dnsmessage.DNSMessage in project minidns by MiniDNS.

the class DNSSECClientTest method testUnknownDelegationDigestType.

@SuppressWarnings("unchecked")
@Test
public void testUnknownDelegationDigestType() throws IOException {
    applyZones(client, signedRootZone(sign(rootKSK, "", rootPrivateKSK, algorithm, record("", rootKSK), record("", rootZSK)), sign(rootZSK, "", rootPrivateZSK, algorithm, record("com", ds(comKSK.getKeyTag(), algorithm, (byte) 213, new byte[0]))), sign(rootZSK, "", rootPrivateZSK, algorithm, record("com", ns("ns.com"))), sign(rootZSK, "", rootPrivateZSK, algorithm, record("ns.com", a("1.1.1.1")))), signedZone("com", "ns.com", "1.1.1.1", sign(comKSK, "com", comPrivateKSK, algorithm, record("com", comKSK), record("com", comZSK)), sign(comZSK, "com", comPrivateZSK, algorithm, record("example.com", a("1.1.1.2")))));
    DNSMessage message = client.query("example.com", Record.TYPE.A);
    assertNotNull(message);
    assertFalse(message.authenticData);
    checkCorrectExampleMessage(message);
}
Also used : DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Aggregations

DNSMessage (org.minidns.dnsmessage.DNSMessage)67 Test (org.junit.Test)35 Data (org.minidns.record.Data)16 Record (org.minidns.record.Record)16 IOException (java.io.IOException)15 Question (org.minidns.dnsmessage.Question)14 InetAddress (java.net.InetAddress)6 LRUCache (org.minidns.cache.LRUCache)6 ArrayList (java.util.ArrayList)5 DNSClient (org.minidns.DNSClient)5 LinkedList (java.util.LinkedList)4 EDNS (org.minidns.edns.EDNS)4 RRSIG (org.minidns.record.RRSIG)4 Date (java.util.Date)3 Level (java.util.logging.Level)3 InternalMiniDnsFuture (org.minidns.MiniDnsFuture.InternalMiniDnsFuture)3 DNSName (org.minidns.dnsname.DNSName)3 DNSKEY (org.minidns.record.DNSKEY)3 DatagramSocket (java.net.DatagramSocket)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2