Debian Codegraph @

minidns-integration-test/src/main/java/org/minidns/integrationtest/CoreTest.java

raw
1 /*
2 * Copyright 2015-2020 the original author or authors
3 *
4 * This software is licensed under the Apache License, Version 2.0,
5 * the GNU Lesser General Public License version 2 or later ("LGPL")
6 * and the WTFPL.
7 * You may choose either license to govern your use of this software only
8 * upon the condition that you accept all of the terms of either
9 * the Apache License 2.0, the LGPL 2.1+ or the WTFPL.
10 */
11 package org.minidns.integrationtest;
12
13 import org.minidns.DnsClient;
14 import org.minidns.cache.LruCache;
15 import org.minidns.dnsqueryresult.DnsQueryResult;
16 import org.minidns.record.Data;
17 import org.minidns.record.Record;
18
19 import java.io.IOException;
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.List;
23
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertNotNull;
26 import static org.junit.jupiter.api.Assertions.assertTrue;
27
28 public class CoreTest {
29 @IntegrationTest
30 public static void testExampleCom() throws IOException {
31 DnsClient client = new DnsClient(new LruCache(1024));
32 String exampleIp4 = "93.184.216.34"; // stable?
33 String exampleIp6 = "2606:2800:220:1:248:1893:25c8:1946"; // stable?
34 assertEquals(client.query("example.com", Record.TYPE.A).response.answerSection.get(0).payloadData.toString(), exampleIp4);
35 assertEquals(client.query("www.example.com", Record.TYPE.A).response.answerSection.get(0).payloadData.toString(), exampleIp4);
36 assertEquals(client.query("example.com", Record.TYPE.AAAA).response.answerSection.get(0).payloadData.toString(), exampleIp6);
37 assertEquals(client.query("www.example.com", Record.TYPE.AAAA).response.answerSection.get(0).payloadData.toString(), exampleIp6);
38
39 DnsQueryResult nsResult = client.query("example.com", Record.TYPE.NS);
40 List<String> values = new ArrayList<>();
41 for (Record<? extends Data> record : nsResult.response.answerSection) {
42 values.add(record.payloadData.toString());
43 }
44 Collections.sort(values);
45 assertEquals(values.get(0), "a.iana-servers.net.");
46 assertEquals(values.get(1), "b.iana-servers.net.");
47 }
48
49 @IntegrationTest
50 public static void testTcpAnswer() throws IOException {
51 DnsClient client = new DnsClient(new LruCache(1024));
52 client.setAskForDnssec(true);
53 client.setDisableResultFilter(true);
54 DnsQueryResult result = client.query("www-nsec.example.com", Record.TYPE.A);
55 assertNotNull(result);
56 assertTrue(result.response.toArray().length > 512);
57 }
58 }