Search in sources :

Example 41 with DNSMessage

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

the class DNSMessageTest method testMessageSelfComplexReconstruction.

@Test
public void testMessageSelfComplexReconstruction() throws Exception {
    DNSMessage.Builder dmb = DNSMessage.builder();
    dmb.addQuestion(new Question("www.example.com", TYPE.NS));
    dmb.addAnswer(record("www.example.com", ns("ns.example.com")));
    dmb.addAdditionalResourceRecord(record("ns.example.com", a("127.0.0.1")));
    dmb.addNameserverRecords(record("ns.example.com", aaaa("2001::1")));
    dmb.setOpcode(DNSMessage.OPCODE.QUERY);
    dmb.setResponseCode(DNSMessage.RESPONSE_CODE.NO_ERROR);
    dmb.setRecursionAvailable(false);
    dmb.setAuthoritativeAnswer(true);
    dmb.setAuthenticData(true);
    dmb.setQrFlag(false);
    dmb.setId(43);
    DNSMessage message = new DNSMessage(dmb.build().toArray());
    assertEquals(1, message.questions.size());
    assertEquals(1, message.answerSection.size());
    assertEquals(1, message.additionalSection.size());
    assertEquals(1, message.authoritySection.size());
    assertFalse(message.recursionAvailable);
    assertTrue(message.authenticData);
    assertFalse(message.checkingDisabled);
    assertFalse(message.qr);
    assertTrue(message.authoritativeAnswer);
    assertEquals(43, message.id);
    assertEquals(DNSMessage.OPCODE.QUERY, message.opcode);
    assertEquals(DNSMessage.RESPONSE_CODE.NO_ERROR, message.responseCode);
    assertCsEquals("www.example.com", message.questions.get(0).name);
    assertEquals(TYPE.NS, message.questions.get(0).type);
    assertCsEquals("www.example.com", message.answerSection.get(0).name);
    assertEquals(TYPE.NS, message.answerSection.get(0).type);
    assertCsEquals("ns.example.com.", message.answerSection.get(0).payloadData.toString());
    assertCsEquals("ns.example.com", message.additionalSection.get(0).name);
    assertEquals(TYPE.A, message.additionalSection.get(0).type);
    assertCsEquals("127.0.0.1", message.additionalSection.get(0).payloadData.toString());
    assertCsEquals("ns.example.com", message.authoritySection.get(0).name);
    assertEquals(TYPE.AAAA, message.authoritySection.get(0).type);
    assertCsEquals("2001:0:0:0:0:0:0:1", message.authoritySection.get(0).payloadData.toString());
}
Also used : Question(org.minidns.dnsmessage.Question) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 42 with DNSMessage

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

the class DNSMessageTest method testMessageSelfTruncatedReconstruction.

@Test
public void testMessageSelfTruncatedReconstruction() throws Exception {
    DNSMessage.Builder dmb = DNSMessage.builder();
    dmb.setTruncated(true);
    dmb.setQrFlag(false);
    dmb.setId(44);
    DNSMessage message = new DNSMessage(dmb.build().toArray());
    assertEquals(44, message.id);
    assertFalse(message.qr);
    assertTrue(message.truncated);
}
Also used : DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 43 with DNSMessage

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

the class DNSMessageTest method testComNsLookup.

@Test
public void testComNsLookup() throws Exception {
    DNSMessage m = getMessageFromResource("com-ns");
    assertFalse(m.authoritativeAnswer);
    assertFalse(m.authenticData);
    assertTrue(m.recursionDesired);
    assertTrue(m.recursionAvailable);
    assertTrue(m.qr);
    List<Record<? extends Data>> answers = m.answerSection;
    assertEquals(13, answers.size());
    for (Record<? extends Data> answer : answers) {
        assertCsEquals("com", answer.name);
        assertEquals(Record.CLASS.IN, answer.clazz);
        assertEquals(TYPE.NS, answer.type);
        assertEquals(112028, answer.ttl);
        assertTrue(((NS) answer.payloadData).target.ace.endsWith(".gtld-servers.net"));
    }
    List<Record<? extends Data>> arr = m.additionalSection;
    assertEquals(1, arr.size());
    EDNS edns = EDNS.fromRecord(arr.get(0));
    assertEquals(4096, edns.udpPayloadSize);
    assertEquals(0, edns.version);
}
Also used : EDNS(org.minidns.edns.EDNS) Record(org.minidns.record.Record) Data(org.minidns.record.Data) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 44 with DNSMessage

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

the class DNSMessageTest method testSRVLookup.

@Test
public void testSRVLookup() throws Exception {
    DNSMessage m = getMessageFromResource("gpn-srv");
    assertFalse(m.authoritativeAnswer);
    List<Record<? extends Data>> answers = m.answerSection;
    assertEquals(1, answers.size());
    Record<? extends Data> answer = answers.get(0);
    assertTrue(answer.getPayload() instanceof SRV);
    assertEquals(TYPE.SRV, answer.getPayload().getType());
    SRV r = (SRV) (answer.getPayload());
    assertCsEquals("raven.toroid.org", r.target);
    assertEquals(5222, r.port);
    assertEquals(0, r.priority);
}
Also used : SRV(org.minidns.record.SRV) Record(org.minidns.record.Record) Data(org.minidns.record.Data) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Example 45 with DNSMessage

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

the class DNSMessageTest method testMessageSelfOptRecordReconstructione.

@SuppressWarnings("unchecked")
@Test
public void testMessageSelfOptRecordReconstructione() throws Exception {
    DNSMessage.Builder m = DNSMessage.builder();
    m.addAdditionalResourceRecord(record("www.example.com", a("127.0.0.1")));
    m.getEdnsBuilder().setUdpPayloadSize(512).setDnssecOk();
    DNSMessage message = new DNSMessage(m.build().toArray());
    assertEquals(2, message.additionalSection.size());
    assertCsEquals("www.example.com", message.additionalSection.get(0).name);
    assertEquals(TYPE.A, message.additionalSection.get(0).type);
    assertCsEquals("127.0.0.1", message.additionalSection.get(0).payloadData.toString());
    assertCsEquals("EDNS: version: 0, flags: do; udp: 512", new EDNS((Record<OPT>) message.additionalSection.get(1)).toString());
}
Also used : OPT(org.minidns.record.OPT) EDNS(org.minidns.edns.EDNS) 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