Search in sources :

Example 6 with DnsClient

use of org.minidns.DnsClient in project Smack by igniterealtime.

the class DnsOverXmppMiniDnsResolverTest method dnsOverXmppMiniDnsResolverTest.

@Test
public void dnsOverXmppMiniDnsResolverTest() throws IOException {
    TestDnsDataSource dnsSource = new TestDnsDataSource();
    TestDnsDataSource dnssecSource = new TestDnsDataSource();
    DnsClient dnsClient = new DnsClient(NoopDnsCache.INSTANCE);
    dnsClient.setDataSource(dnsSource);
    DnssecClient dnssecClient = new DnssecClient(NoopDnsCache.INSTANCE);
    dnssecClient.setDataSource(dnssecSource);
    DnsOverXmppMiniDnsResolver doxResolver = new DnsOverXmppMiniDnsResolver(dnsClient, dnssecClient);
    Question question = new Question("example.org", TYPE.A);
    {
        DnsMessage nondnssecQuery = question.asQueryMessage();
        doxResolver.resolve(nondnssecQuery);
        assertTrue(dnsSource.getAndResetWasQueried());
        assertFalse(dnssecSource.getAndResetWasQueried());
    }
    {
        DnsMessage.Builder dnssecQueryBuilder = question.asMessageBuilder();
        dnssecQueryBuilder.getEdnsBuilder().setDnssecOk();
        DnsMessage dnssecQuery = dnssecQueryBuilder.build();
        DnssecValidationFailedException dnssecValidationFailedException = null;
        try {
            doxResolver.resolve(dnssecQuery);
        } catch (DnssecValidationFailedException e) {
            dnssecValidationFailedException = e;
        }
        // This exception is expected since we don't have a realy DNS source.
        assertNotNull(dnssecValidationFailedException);
        assertFalse(dnsSource.getAndResetWasQueried());
        assertTrue(dnssecSource.getAndResetWasQueried());
    }
}
Also used : DnssecClient(org.minidns.dnssec.DnssecClient) DnssecValidationFailedException(org.minidns.dnssec.DnssecValidationFailedException) DnsClient(org.minidns.DnsClient) Question(org.minidns.dnsmessage.Question) DnsMessage(org.minidns.dnsmessage.DnsMessage) Test(org.junit.jupiter.api.Test)

Aggregations

DNSClient (org.minidns.DNSClient)5 DNSMessage (org.minidns.dnsmessage.DNSMessage)5 IOException (java.io.IOException)3 LRUCache (org.minidns.cache.LRUCache)2 Question (org.minidns.dnsmessage.Question)2 AsyncNetworkDataSource (org.minidns.source.async.AsyncNetworkDataSource)2 InetAddress (java.net.InetAddress)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 DnsClient (org.minidns.DnsClient)1 Builder (org.minidns.dnsmessage.DNSMessage.Builder)1 DnsMessage (org.minidns.dnsmessage.DnsMessage)1 DnssecClient (org.minidns.dnssec.DnssecClient)1 DnssecValidationFailedException (org.minidns.dnssec.DnssecValidationFailedException)1 NSID (org.minidns.edns.NSID)1 IterativeDNSClient (org.minidns.iterative.IterativeDNSClient)1 DNSDataSource (org.minidns.source.DNSDataSource)1