use of org.minidns.dnsmessage.DnsMessage in project minidns by MiniDNS.
the class DNSMessageTest method testRootDnskeyLookup.
@Test
public void testRootDnskeyLookup() throws Exception {
DNSMessage m = getMessageFromResource("root-dnskey");
assertFalse(m.authoritativeAnswer);
assertTrue(m.recursionDesired);
assertTrue(m.recursionAvailable);
List<Record<? extends Data>> answers = m.answerSection;
assertEquals(3, answers.size());
for (int i = 0; i < answers.size(); i++) {
Record<? extends Data> answer = answers.get(i);
assertCsEquals(".", answer.name);
assertEquals(19593, answer.getTtl());
assertEquals(TYPE.DNSKEY, answer.type);
assertEquals(TYPE.DNSKEY, answer.getPayload().getType());
DNSKEY dnskey = (DNSKEY) answer.getPayload();
assertEquals(3, dnskey.protocol);
assertEquals(SignatureAlgorithm.RSASHA256, dnskey.algorithm);
assertTrue((dnskey.flags & DNSKEY.FLAG_ZONE) > 0);
assertEquals(dnskey.getKeyTag(), dnskey.getKeyTag());
switch(i) {
case 0:
assertTrue((dnskey.flags & DNSKEY.FLAG_SECURE_ENTRY_POINT) > 0);
assertEquals(260, dnskey.getKeyLength());
assertEquals(19036, dnskey.getKeyTag());
break;
case 1:
assertEquals(DNSKEY.FLAG_ZONE, dnskey.flags);
assertEquals(132, dnskey.getKeyLength());
assertEquals(48613, dnskey.getKeyTag());
break;
case 2:
assertEquals(DNSKEY.FLAG_ZONE, dnskey.flags);
assertEquals(132, dnskey.getKeyLength());
assertEquals(1518, dnskey.getKeyTag());
break;
}
}
List<Record<? extends Data>> arr = m.additionalSection;
assertEquals(1, arr.size());
Record<? extends Data> opt = arr.get(0);
EDNS edns = EDNS.fromRecord(opt);
assertEquals(512, edns.udpPayloadSize);
assertEquals(0, edns.version);
}
use of org.minidns.dnsmessage.DnsMessage in project minidns by MiniDNS.
the class DNSMessageTest method testMessageSelfQuestionReconstruction.
@Test
public void testMessageSelfQuestionReconstruction() throws Exception {
DNSMessage.Builder dmb = DNSMessage.builder();
dmb.setQuestion(new Question("www.example.com", TYPE.A));
dmb.setRecursionDesired(true);
dmb.setId(42);
dmb.setQrFlag(true);
DNSMessage message = new DNSMessage(dmb.build().toArray());
assertEquals(1, message.questions.size());
assertEquals(0, message.answerSection.size());
assertEquals(0, message.additionalSection.size());
assertEquals(0, message.authoritySection.size());
assertTrue(message.recursionDesired);
assertTrue(message.qr);
assertEquals(42, message.id);
assertCsEquals("www.example.com", message.questions.get(0).name);
assertEquals(TYPE.A, message.questions.get(0).type);
}
use of org.minidns.dnsmessage.DnsMessage in project minidns by MiniDNS.
the class DNSMessageTest method testMXLookup.
@Test
public void testMXLookup() throws Exception {
DNSMessage m = getMessageFromResource("gmail-mx");
assertFalse(m.authoritativeAnswer);
List<Record<? extends Data>> answers = m.answerSection;
assertEquals(5, answers.size());
Map<Integer, DNSName> mxes = new TreeMap<>();
for (Record<? extends Data> r : answers) {
assertCsEquals("gmail.com", r.name);
Data d = r.getPayload();
assertTrue(d instanceof MX);
assertEquals(TYPE.MX, d.getType());
mxes.put(((MX) d).priority, ((MX) d).target);
}
assertCsEquals("gmail-smtp-in.l.google.com", mxes.get(5));
assertCsEquals("alt1.gmail-smtp-in.l.google.com", mxes.get(10));
assertCsEquals("alt2.gmail-smtp-in.l.google.com", mxes.get(20));
assertCsEquals("alt3.gmail-smtp-in.l.google.com", mxes.get(30));
assertCsEquals("alt4.gmail-smtp-in.l.google.com", mxes.get(40));
}
use of org.minidns.dnsmessage.DnsMessage in project minidns by MiniDNS.
the class DNSMessageTest method testExampleNsecLookup.
@Test
public void testExampleNsecLookup() throws Exception {
DNSMessage m = getMessageFromResource("example-nsec");
List<Record<? extends Data>> answers = m.answerSection;
assertEquals(1, answers.size());
assertEquals(TYPE.NSEC, answers.get(0).type);
assertEquals(TYPE.NSEC, answers.get(0).payloadData.getType());
NSEC nsec = (NSEC) answers.get(0).getPayload();
assertCsEquals("www.example.com", nsec.next);
ArrayList<TYPE> types = new ArrayList<>(Arrays.asList(TYPE.A, TYPE.NS, TYPE.SOA, TYPE.TXT, TYPE.AAAA, TYPE.RRSIG, TYPE.NSEC, TYPE.DNSKEY));
for (TYPE type : nsec.types) {
assertTrue(types.remove(type));
}
assertTrue(types.isEmpty());
}
use of org.minidns.dnsmessage.DnsMessage in project minidns by MiniDNS.
the class NSIDTest method testNsidLRoot.
@IntegrationTest
public static NSID testNsidLRoot() {
DNSClient client = new DNSClient(null) {
@Override
protected Builder newQuestion(Builder message) {
message.getEdnsBuilder().addEdnsOption(NSID.REQUEST);
return super.newQuestion(message);
}
};
DNSMessage response = null;
Question q = new Question("de", TYPE.NS);
for (InetAddress lRoot : IterativeDNSClient.getRootServer('l')) {
try {
response = client.query(q, lRoot);
} catch (IOException e) {
continue;
}
break;
}
NSID nsid = response.getEdns().getEdnsOption(OptionCode.NSID);
assertNotNull(nsid);
return nsid;
}
Aggregations