aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/dns/ut/dns_ut.cpp
blob: fc5a356b571b5b3483c0ad8e85357a1580d904b1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <library/cpp/testing/unittest/registar.h>
#include <library/cpp/dns/cache.h>
#include <util/network/address.h> 

Y_UNIT_TEST_SUITE(TestDNS) {
    using namespace NDns;

    Y_UNIT_TEST(TestMagic) {
        UNIT_ASSERT_EXCEPTION(CachedThrResolve(TResolveInfo("?", 80)), yexception);
    }
 
    Y_UNIT_TEST(TestAsteriskAlias) {
        AddHostAlias("*", "localhost"); 
        const TResolvedHost* rh = CachedThrResolve(TResolveInfo("yandex.ru", 80)); 
        UNIT_ASSERT(rh != nullptr); 
 
        const TNetworkAddress& addr = rh->Addr;
        for (TNetworkAddress::TIterator ai = addr.Begin(); ai != addr.End(); ai++) { 
            if (ai->ai_family == AF_INET || ai->ai_family == AF_INET6) { 
                NAddr::TAddrInfo info(&*ai); 
                UNIT_ASSERT(IsLoopback(info)); 
            } 
        } 
    } 
}