Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
url-checker
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Romain Courteaud
url-checker
Commits
b1989d93
Commit
b1989d93
authored
Dec 02, 2019
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MORE TESTS
parent
da87eced
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
102 additions
and
3 deletions
+102
-3
test_urlchecker_dns.py
test_urlchecker_dns.py
+99
-0
urlchecker_bot.py
urlchecker_bot.py
+2
-2
urlchecker_dns.py
urlchecker_dns.py
+1
-1
No files found.
test_urlchecker_dns.py
View file @
b1989d93
...
@@ -8,6 +8,7 @@ from urlchecker_dns import (
...
@@ -8,6 +8,7 @@ from urlchecker_dns import (
buildResolver
,
buildResolver
,
queryDNS
,
queryDNS
,
getReachableResolverList
,
getReachableResolverList
,
getDomainIpDict
,
)
)
from
urlchecker_status
import
logStatus
from
urlchecker_status
import
logStatus
import
mock
import
mock
...
@@ -499,6 +500,104 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
...
@@ -499,6 +500,104 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
assert
self
.
db
.
NetworkChange
.
get
().
state
==
"open"
assert
self
.
db
.
NetworkChange
.
get
().
state
==
"open"
assert
self
.
db
.
NetworkChange
.
get
().
status_id
==
status_id
assert
self
.
db
.
NetworkChange
.
get
().
status_id
==
status_id
################################################
# getDomainIpDict
################################################
def
test_getDomainIpDict_mutipleDomainIp
(
self
):
resolver_ip_list
=
[
"127.0.0.1"
]
domain_list
=
[
"example.org"
]
rdtype
=
"A"
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"urlchecker_dns.dns.resolver.Resolver.query"
)
as
mock_query
:
mock_query
.
return_value
=
[
MockAnswer
(
"4.3.2.1"
),
MockAnswer
(
"1.2.3.4"
),
]
result
=
getDomainIpDict
(
self
.
db
,
status_id
,
resolver_ip_list
,
domain_list
,
rdtype
)
assert
mock_query
.
call_count
==
1
mock_query
.
assert_called_with
(
domain_list
[
0
],
rdtype
,
raise_on_no_answer
=
False
)
assert
result
==
{
"1.2.3.4"
:
[
"example.org"
],
"4.3.2.1"
:
[
"example.org"
],
}
assert
self
.
db
.
DnsChange
.
select
().
count
()
==
1
assert
self
.
db
.
NetworkChange
.
select
().
count
()
==
0
def
test_getDomainIpDict_mutipleDNSIp
(
self
):
resolver_ip_list
=
[
"127.0.0.1"
,
"127.0.0.2"
]
domain_list
=
[
"example.org"
]
rdtype
=
"A"
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"urlchecker_dns.dns.resolver.Resolver.query"
)
as
mock_query
:
mock_query
.
side_effect
=
[
[
MockAnswer
(
"4.3.2.1"
),
MockAnswer
(
"1.2.3.4"
)],
[
MockAnswer
(
"4.3.2.1"
),
MockAnswer
(
"1.2.3.5"
)],
]
result
=
getDomainIpDict
(
self
.
db
,
status_id
,
resolver_ip_list
,
domain_list
,
rdtype
)
assert
mock_query
.
call_count
==
2
assert
mock_query
.
call_args_list
[
0
]
==
mock
.
call
(
domain_list
[
0
],
rdtype
,
raise_on_no_answer
=
False
)
assert
mock_query
.
call_args_list
[
1
]
==
mock
.
call
(
domain_list
[
0
],
rdtype
,
raise_on_no_answer
=
False
)
assert
result
==
{
"1.2.3.4"
:
[
"example.org"
],
"4.3.2.1"
:
[
"example.org"
],
"1.2.3.5"
:
[
"example.org"
],
}
assert
self
.
db
.
DnsChange
.
select
().
count
()
==
2
assert
self
.
db
.
NetworkChange
.
select
().
count
()
==
0
def
test_getDomainIpDict_mutipleDomain
(
self
):
resolver_ip_list
=
[
"127.0.0.1"
]
domain_list
=
[
"example.org"
,
"foo.example.org"
]
rdtype
=
"A"
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"urlchecker_dns.dns.resolver.Resolver.query"
)
as
mock_query
:
mock_query
.
side_effect
=
[
[
MockAnswer
(
"4.3.2.1"
),
MockAnswer
(
"1.2.3.4"
)],
[
MockAnswer
(
"4.3.2.1"
),
MockAnswer
(
"1.2.3.5"
)],
]
result
=
getDomainIpDict
(
self
.
db
,
status_id
,
resolver_ip_list
,
domain_list
,
rdtype
)
assert
mock_query
.
call_count
==
2
assert
mock_query
.
call_args_list
[
0
]
==
mock
.
call
(
domain_list
[
0
],
rdtype
,
raise_on_no_answer
=
False
)
assert
mock_query
.
call_args_list
[
1
]
==
mock
.
call
(
domain_list
[
1
],
rdtype
,
raise_on_no_answer
=
False
)
assert
result
==
{
"1.2.3.4"
:
[
"example.org"
],
"4.3.2.1"
:
[
"example.org"
,
"foo.example.org"
],
"1.2.3.5"
:
[
"foo.example.org"
],
}
assert
self
.
db
.
DnsChange
.
select
().
count
()
==
2
assert
self
.
db
.
NetworkChange
.
select
().
count
()
==
0
def
suite
():
def
suite
():
suite
=
unittest
.
TestSuite
()
suite
=
unittest
.
TestSuite
()
...
...
urlchecker_bot.py
View file @
b1989d93
...
@@ -6,7 +6,7 @@ from urlchecker_status import logStatus
...
@@ -6,7 +6,7 @@ from urlchecker_status import logStatus
from
urlchecker_dns
import
(
from
urlchecker_dns
import
(
getReachableResolverList
,
getReachableResolverList
,
expandDomainList
,
expandDomainList
,
get
Server
IpDict
,
get
Domain
IpDict
,
)
)
from
urlchecker_http
import
getUrlHostname
,
checkHttpStatus
from
urlchecker_http
import
getUrlHostname
,
checkHttpStatus
from
urlchecker_network
import
isTcpPortOpen
from
urlchecker_network
import
isTcpPortOpen
...
@@ -52,7 +52,7 @@ class WebBot:
...
@@ -52,7 +52,7 @@ class WebBot:
# Get the list of server to check
# Get the list of server to check
# XXX Check DNS expiration
# XXX Check DNS expiration
server_ip_dict
=
get
Server
IpDict
(
server_ip_dict
=
get
Domain
IpDict
(
self
.
_db
,
status_id
,
resolver_ip_list
,
domain_list
,
"A"
self
.
_db
,
status_id
,
resolver_ip_list
,
domain_list
,
"A"
)
)
...
...
urlchecker_dns.py
View file @
b1989d93
...
@@ -107,7 +107,7 @@ def expandDomainList(domain_list):
...
@@ -107,7 +107,7 @@ def expandDomainList(domain_list):
return
domain_list
return
domain_list
def
get
Server
IpDict
(
db
,
status_id
,
resolver_ip_list
,
domain_list
,
rdtype
):
def
get
Domain
IpDict
(
db
,
status_id
,
resolver_ip_list
,
domain_list
,
rdtype
):
server_ip_dict
=
{}
server_ip_dict
=
{}
for
domain_text
in
domain_list
:
for
domain_text
in
domain_list
:
for
resolver_ip
in
resolver_ip_list
:
for
resolver_ip
in
resolver_ip_list
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment