FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
node/test/disabled/test-dns.js at writev · sgithens/node · GitHub
sgithens
node
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
node
/
test
/
disabled
/
test-dns.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
151 lines (128 loc) · 4.3 KB
Breadcrumbs
node
/
test
/
disabled
/
test-dns.js
Copy path
File metadata and controls
151 lines (128 loc) · 4.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
common
=
require
(
"../common"
)
;
assert
=
common
.
assert
;
var
dns
=
require
(
"dns"
)
,
child_process
=
require
(
"child_process"
)
;
// Try resolution without callback
assert
.
throws
(
function
(
)
{
dns
.
resolve
(
'google.com'
,
'A'
)
;
}
)
;
assert
.
throws
(
function
(
)
{
dns
.
resolve
(
'127.0.0.1'
,
'PTR'
)
;
}
)
;
var
hosts
=
[
'example.com'
,
'example.org'
,
'ietf.org'
,
// AAAA
'google.com'
,
// MX, multiple A records
'_xmpp-client._tcp.google.com'
,
// SRV
'oakalynhall.co.uk'
// Multiple PTR replies
]
;
var
records
=
[
'A'
,
'AAAA'
,
'MX'
,
'TXT'
,
'SRV'
]
;
var
i
=
hosts
.
length
;
while
(
i
--
)
{
var
j
=
records
.
length
;
while
(
j
--
)
{
var
hostCmd
=
"dig -t "
+
records
[
j
]
+
" "
+
hosts
[
i
]
+
"| grep '^"
+
hosts
[
i
]
+
"\\.\\W.*IN.*"
+
records
[
j
]
+
"'"
+
"| sed -E 's/[[:space:]]+/ /g' | cut -d ' ' -f 5- "
+
"| sed -e 's/\\.$//'"
;
child_process
.
exec
(
hostCmd
,
checkDnsRecord
(
hosts
[
i
]
,
records
[
j
]
)
)
;
}
}
// CNAME should resolve
dns
.
resolve
(
'labs.nrcmedia.nl'
,
'CNAME'
,
function
(
err
,
result
)
{
assert
.
deepEqual
(
result
,
[
'nrcmedia.nl'
]
)
;
}
)
;
// CNAME should not resolve
dns
.
resolve
(
'nrcmedia.nl'
,
'CNAME'
,
function
(
err
,
result
)
{
assert
.
ok
(
err
.
errno
,
dns
.
NODATA
)
;
}
)
;
function
checkDnsRecord
(
host
,
record
)
{
var
myHost
=
host
,
myRecord
=
record
;
return
function
(
err
,
stdout
)
{
var
expected
=
[
]
;
if
(
stdout
.
length
)
expected
=
stdout
.
substr
(
0
,
stdout
.
length
-
1
)
.
split
(
"\n"
)
;
switch
(
myRecord
)
{
case
"A"
:
case
"AAAA"
:
dns
.
resolve
(
myHost
,
myRecord
,
function
(
error
,
result
,
ttl
,
cname
)
{
if
(
error
)
result
=
[
]
;
cmpResults
(
expected
,
result
,
ttl
,
cname
)
;
// do reverse lookup check
var
ll
=
result
.
length
;
while
(
ll
--
)
{
var
ip
=
result
[
ll
]
;
var
reverseCmd
=
"host "
+
ip
+
"| cut -d \" \" -f 5-"
+
"| sed -e 's/\\.$//'"
;
child_process
.
exec
(
reverseCmd
,
checkReverse
(
ip
)
)
;
}
}
)
;
break
;
case
"MX"
:
dns
.
resolve
(
myHost
,
myRecord
,
function
(
error
,
result
,
ttl
,
cname
)
{
if
(
error
)
result
=
[
]
;
var
strResult
=
[
]
;
var
ll
=
result
.
length
;
while
(
ll
--
)
{
strResult
.
push
(
result
[
ll
]
.
priority
+
" "
+
result
[
ll
]
.
exchange
)
;
}
cmpResults
(
expected
,
strResult
,
ttl
,
cname
)
;
}
)
;
break
;
case
"TXT"
:
dns
.
resolve
(
myHost
,
myRecord
,
function
(
error
,
result
,
ttl
,
cname
)
{
if
(
error
)
result
=
[
]
;
var
strResult
=
[
]
;
var
ll
=
result
.
length
;
while
(
ll
--
)
{
strResult
.
push
(
'"'
+
result
[
ll
]
+
'"'
)
;
}
cmpResults
(
expected
,
strResult
,
ttl
,
cname
)
;
}
)
;
break
;
case
"SRV"
:
dns
.
resolve
(
myHost
,
myRecord
,
function
(
error
,
result
,
ttl
,
cname
)
{
if
(
error
)
result
=
[
]
;
var
strResult
=
[
]
;
var
ll
=
result
.
length
;
while
(
ll
--
)
{
strResult
.
push
(
result
[
ll
]
.
priority
+
" "
+
result
[
ll
]
.
weight
+
" "
+
result
[
ll
]
.
port
+
" "
+
result
[
ll
]
.
name
)
;
}
cmpResults
(
expected
,
strResult
,
ttl
,
cname
)
;
}
)
;
break
;
}
}
}
function
checkReverse
(
ip
)
{
var
myIp
=
ip
;
return
function
(
errr
,
stdout
)
{
var
expected
=
stdout
.
substr
(
0
,
stdout
.
length
-
1
)
.
split
(
"\n"
)
;
reversing
=
dns
.
reverse
(
myIp
,
function
(
error
,
domains
,
ttl
,
cname
)
{
if
(
error
)
domains
=
[
]
;
cmpResults
(
expected
,
domains
,
ttl
,
cname
)
;
}
)
;
}
}
function
cmpResults
(
expected
,
result
,
ttl
,
cname
)
{
if
(
expected
.
length
!=
result
.
length
)
{
if
(
expected
.
length
==
1
&&
expected
[
0
]
==
'3(NXDOMAIN)'
&&
result
.
length
==
0
)
{
// it's ok, dig returns NXDOMAIN, while dns module returns nothing
}
else
{
console
.
log
(
'---WARNING---\nexpected '
+
expected
+
'\nresult '
+
result
+
'\n-------------'
)
;
}
return
;
}
expected
.
sort
(
)
;
result
.
sort
(
)
;
ll
=
expected
.
length
;
while
(
ll
--
)
{
assert
.
equal
(
result
[
ll
]
,
expected
[
ll
]
)
;
console
.
log
(
"Result "
+
result
[
ll
]
+
" was equal to expected "
+
expected
[
ll
]
)
;
}
}
Back
|
FazBrowse Home
|
New Git URL