Skip to content
This repository
branch: tls
Fetching contributors…

Cannot retrieve contributors at this time

file 115 lines (95 sloc) 3.094 kb
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
--[[

Copyright 2012 The Luvit Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS-IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

--]]

require("helper")

local dns = require('dns')

dns.resolve4('www.google.com', function(err, addresses)
  assert(type(err) == 'nil')
  assert(type(addresses) == 'table')
  assert(#addresses > 0)
end)

dns.resolve6('ipv6.google.com', function(err, addresses)
  assert(type(err) == 'nil')
  assert(type(addresses) == 'table')
  assert(#addresses > 0)
end)

dns.lookup('google.com', function(err, addresses)
  assert(type(err) == 'nil')
  assert(type(addresses) == 'string')
end)

dns.reverse('8.8.8.8', function(err, addresses)
  assert(type(err) == 'nil')
  assert(type(addresses) == 'table')
  for i=1,#addresses do
    assert(type(addresses[i]) == 'string')
  end
end)

dns.reverse('2001:4860:4860::8888', function(err, addresses)
  assert(type(err) == 'nil')
  assert(type(addresses) == 'table')
  for i=1,#addresses do
    assert(type(addresses[i]) == 'string')
  end
end)

dns.reverse('bogus ip', function(err, addresses)
  assert(type(err) ~= 'nil')
  assert(type(addresses) == 'nil')
end)

dns.resolveMx('gmail.com', function(err, addresses)
  assert(type(err) == 'nil')
  assert(type(addresses) == 'table')
  for i=1,#addresses do
    assert(addresses[i].priority)
    assert(addresses[i].exchange)
  end
end)

dns.resolveNs('rackspace.com', function(err, addresses)
  assert(type(err) == 'nil')
  assert(type(addresses) == 'table')
  for i=1,#addresses do
    assert(type(addresses[i]) == 'string')
  end
end)

dns.resolveSrv('_jabber._tcp.google.com', function(err, addresses)
  assert(type(err) == 'nil')
  assert(type(addresses) == 'table')
  for i=1,#addresses do
    assert(type(addresses[i].name) == 'string')
    assert(type(addresses[i].port) == 'number')
    assert(type(addresses[i].priority) == 'number')
    assert(type(addresses[i].weight) == 'number')
  end
end)

dns.resolveCname('www.google.com', function(err, names)
  assert(type(err) == 'nil')
  assert(type(names) == 'table')
  assert(#names == 1)
end)

dns.resolveTxt('google.com', function(err, records)
  assert(type(err) == 'nil')
  assert(type(records) == 'table')
  for i=1,#records do
    assert(type(records[i]) == 'string')
  end
end)

dns.lookup('::1', function(err, ip, family)
  assert(type(err) == 'nil')
  assert(type(ip) == 'string')
  assert(type(family) == 'number')
end)

assert(dns.isIp('127.0.0.1') == 4)
assert(dns.isIp('::1') == 6)
assert(dns.isIp('bogus_ip') == 0)
assert(dns.isIpV4('127.0.0.1') == 4)
assert(dns.isIpV4('::1') == 0)
assert(dns.isIpV6('127.0.0.1') == 0)
assert(dns.isIpV6('::1') == 6)
Something went wrong with that request. Please try again.