aboutsummaryrefslogtreecommitdiff
path: root/tests/unit_tests/dns_resolver.cpp
blob: fe8fe602b524f1b286a5db4ee770fb50178a1f56 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "gtest/gtest.h"

#include "common/dns_utils.h"

TEST(DNSResolver, IPv4Success)
{
  tools::DNSResolver resolver;

  auto ips = resolver.get_ipv4("example.com");

  ASSERT_EQ(1, ips.size());

  ASSERT_STREQ("93.184.216.119", ips[0].c_str());

  ips = tools::DNSResolver::instance().get_ipv4("example.com");

  ASSERT_EQ(1, ips.size());

  ASSERT_STREQ("93.184.216.119", ips[0].c_str());
}

TEST(DNSResolver, IPv4Failure)
{
  // guaranteed by IANA/ICANN/RFC to be invalid
  tools::DNSResolver resolver;

  auto ips = resolver.get_ipv4("example.invalid");

  ASSERT_EQ(0, ips.size());

  ips = tools::DNSResolver::instance().get_ipv4("example.invalid");

  ASSERT_EQ(0, ips.size());
}

TEST(DNSResolver, IPv6Success)
{
  tools::DNSResolver resolver;

  auto ips = resolver.get_ipv6("example.com");

  ASSERT_EQ(1, ips.size());

  ASSERT_STREQ("2606:2800:220:6d:26bf:1447:1097:aa7", ips[0].c_str());

  ips = tools::DNSResolver::instance().get_ipv6("example.com");

  ASSERT_EQ(1, ips.size());

  ASSERT_STREQ("2606:2800:220:6d:26bf:1447:1097:aa7", ips[0].c_str());
}

TEST(DNSResolver, IPv6Failure)
{
  // guaranteed by IANA/ICANN/RFC to be invalid
  tools::DNSResolver resolver;

  auto ips = resolver.get_ipv6("example.invalid");

  ASSERT_EQ(0, ips.size());

  ips = tools::DNSResolver::instance().get_ipv6("example.invalid");

  ASSERT_EQ(0, ips.size());
}