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());
}
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);
}
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);
}
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);
}
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());
}
Aggregations