| 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 java.io.IOException; |
| 14 |
import java.net.InetAddress; |
| 15 |
|
| 16 |
import org.minidns.DnsClient; |
| 17 |
import org.minidns.dnsmessage.Question; |
| 18 |
import org.minidns.dnsqueryresult.DnsQueryResult; |
| 19 |
import org.minidns.dnsmessage.DnsMessage; |
| 20 |
import org.minidns.edns.Nsid; |
| 21 |
import org.minidns.edns.Edns.OptionCode; |
| 22 |
import org.minidns.iterative.IterativeDnsClient; |
| 23 |
import org.minidns.record.Record.TYPE; |
| 24 |
|
| 25 |
import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 26 |
|
| 27 |
public class NsidTest { |
| 28 |
|
| 29 |
@IntegrationTest |
| 30 |
public static Nsid testNsidLRoot() { |
| 31 |
DnsClient client = new DnsClient(null) { |
| 32 |
@Override |
| 33 |
protected DnsMessage.Builder newQuestion(DnsMessage.Builder message) { |
| 34 |
message.getEdnsBuilder().addEdnsOption(Nsid.REQUEST); |
| 35 |
return super.newQuestion(message); |
| 36 |
} |
| 37 |
}; |
| 38 |
DnsQueryResult result = null; |
| 39 |
Question q = new Question("de", TYPE.NS); |
| 40 |
for (InetAddress lRoot : IterativeDnsClient.getRootServer('l')) { |
| 41 |
try { |
| 42 |
result = client.query(q, lRoot); |
| 43 |
} catch (IOException e) { |
| 44 |
continue; |
| 45 |
} |
| 46 |
break; |
| 47 |
} |
| 48 |
Nsid nsid = result.response.getEdns().getEdnsOption(OptionCode.NSID); |
| 49 |
assertNotNull(nsid); |
| 50 |
return nsid; |
| 51 |
} |
| 52 |
} |