001/*
002 * Copyright 2015-2020 the original author or authors
003 *
004 * This software is licensed under the Apache License, Version 2.0,
005 * the GNU Lesser General Public License version 2 or later ("LGPL")
006 * and the WTFPL.
007 * You may choose either license to govern your use of this software only
008 * upon the condition that you accept all of the terms of either
009 * the Apache License 2.0, the LGPL 2.1+ or the WTFPL.
010 */
011package org.minidns.integrationtest;
012
013import java.io.IOException;
014import java.net.InetAddress;
015
016import org.minidns.DnsClient;
017import org.minidns.dnsmessage.Question;
018import org.minidns.dnsqueryresult.DnsQueryResult;
019import org.minidns.dnsmessage.DnsMessage;
020import org.minidns.edns.Nsid;
021import org.minidns.edns.Edns.OptionCode;
022import org.minidns.iterative.IterativeDnsClient;
023import org.minidns.record.Record.TYPE;
024
025import static org.junit.jupiter.api.Assertions.assertNotNull;
026
027public class NsidTest {
028
029    @IntegrationTest
030    public static Nsid testNsidLRoot() {
031        DnsClient client = new DnsClient(null) {
032            @Override
033            protected DnsMessage.Builder newQuestion(DnsMessage.Builder message) {
034                message.getEdnsBuilder().addEdnsOption(Nsid.REQUEST);
035                return super.newQuestion(message);
036            }
037        };
038        DnsQueryResult result = null;
039        Question q = new Question("de", TYPE.NS);
040        for (InetAddress lRoot : IterativeDnsClient.getRootServer('l')) {
041            try {
042                result = client.query(q, lRoot);
043            } catch (IOException e) {
044                continue;
045            }
046            break;
047        }
048        Nsid nsid = result.response.getEdns().getEdnsOption(OptionCode.NSID);
049        assertNotNull(nsid);
050        return nsid;
051    }
052}