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
00fe334b
Commit
00fe334b
authored
Dec 04, 2019
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move default DNS on configuration level
parent
4dfd8e48
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
74 deletions
+24
-74
test_urlchecker_bot.py
test_urlchecker_bot.py
+15
-15
test_urlchecker_dns.py
test_urlchecker_dns.py
+0
-45
urlchecker_cli.py
urlchecker_cli.py
+1
-3
urlchecker_configuration.py
urlchecker_configuration.py
+8
-7
urlchecker_dns.py
urlchecker_dns.py
+0
-4
No files found.
test_urlchecker_bot.py
View file @
00fe334b
...
...
@@ -39,24 +39,22 @@ class UrlCheckerBotTestCase(unittest.TestCase):
def
test_emptyConfiguration
(
self
):
resolver_ip
=
"192.168.0.254"
bot
=
WebBot
(
mapping
=
{
"SQLITE"
:
":memory:"
})
bot
.
initDB
()
resolver
=
urlchecker_dns
.
dns
.
resolver
.
Resolver
(
configure
=
False
)
resolver
.
nameservers
.
append
(
resolver_ip
)
with
mock
.
patch
(
"urlchecker_dns.get_default_resolver"
)
as
mock_get_default_resolver
:
"urlchecker_configuration.get_default_resolver"
)
as
mock_get_default_resolver
,
mock
.
patch
(
"urlchecker_dns.dns.resolver.Resolver.query"
)
as
mock_query
:
mock_get_default_resolver
.
return_value
=
resolver
with
mock
.
patch
(
"urlchecker_dns.dns.resolver.Resolver.query"
)
as
mock_query
:
mock_query
.
return_value
=
[
MockAnswer
(
"1.2.3.4"
)]
bot
.
iterateLoop
()
mock_query
.
return_value
=
[
MockAnswer
(
"1.2.3.4"
)]
bot
=
WebBot
(
mapping
=
{
"SQLITE"
:
":memory:"
})
bot
.
initDB
()
bot
.
iterateLoop
()
assert
mock_query
.
call_count
==
1
assert
mock_query
.
call_count
==
1
assert
bot
.
_db
.
Status
.
select
().
count
()
==
1
assert
bot
.
_db
.
Status
.
get
().
text
==
"loop"
...
...
@@ -70,14 +68,11 @@ class UrlCheckerBotTestCase(unittest.TestCase):
def
test_oneNameserverOneDomainOneIp
(
self
):
resolver_ip
=
"127.0.0.1"
bot
=
WebBot
(
mapping
=
{
"SQLITE"
:
":memory:"
,
"DOMAIN"
:
"example.org"
})
bot
.
initDB
()
resolver
=
urlchecker_dns
.
dns
.
resolver
.
Resolver
(
configure
=
False
)
resolver
.
nameservers
.
append
(
resolver_ip
)
with
mock
.
patch
(
"urlchecker_
dns
.get_default_resolver"
"urlchecker_
configuration
.get_default_resolver"
)
as
mock_get_default_resolver
,
mock
.
patch
(
"urlchecker_dns.dns.resolver.Resolver.query"
)
as
mock_query
,
mock
.
patch
(
...
...
@@ -89,6 +84,11 @@ class UrlCheckerBotTestCase(unittest.TestCase):
mock_get_default_resolver
.
return_value
=
resolver
mock_query
.
return_value
=
[
MockAnswer
(
"1.2.3.4"
)]
bot
=
WebBot
(
mapping
=
{
"SQLITE"
:
":memory:"
,
"DOMAIN"
:
"example.org"
}
)
bot
.
initDB
()
bot
.
iterateLoop
()
assert
mock_query
.
call_count
==
2
...
...
test_urlchecker_dns.py
View file @
00fe334b
...
...
@@ -455,51 +455,6 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
assert
self
.
db
.
NetworkChange
.
get
().
state
==
"closed"
assert
self
.
db
.
NetworkChange
.
get
().
status_id
==
status_id
def
test_getReachableResolverList_noiplist
(
self
):
resolver_ip
=
"127.0.0.1"
domain
=
"example.org"
rdtype
=
"A"
status_id
=
logStatus
(
self
.
db
,
"foo"
)
resolver
=
urlchecker_dns
.
dns
.
resolver
.
Resolver
(
configure
=
False
)
resolver
.
nameservers
.
append
(
resolver_ip
)
with
mock
.
patch
(
"urlchecker_dns.get_default_resolver"
)
as
mock_get_default_resolver
:
mock_get_default_resolver
.
return_value
=
resolver
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
=
getReachableResolverList
(
self
.
db
,
status_id
,
[])
assert
mock_get_default_resolver
.
call_count
==
1
assert
mock_query
.
call_count
==
1
mock_query
.
assert_called_with
(
domain
,
rdtype
,
raise_on_no_answer
=
False
)
assert
self
.
db
.
DnsChange
.
select
().
count
()
==
1
assert
self
.
db
.
DnsChange
.
get
().
resolver_ip
==
resolver_ip
assert
self
.
db
.
DnsChange
.
get
().
domain
==
domain
assert
self
.
db
.
DnsChange
.
get
().
rdtype
==
rdtype
assert
self
.
db
.
DnsChange
.
get
().
response
==
"1.2.3.4, 4.3.2.1"
assert
self
.
db
.
DnsChange
.
get
().
status_id
==
status_id
assert
result
==
[
"127.0.0.1"
]
assert
self
.
db
.
NetworkChange
.
select
().
count
()
==
1
assert
self
.
db
.
NetworkChange
.
get
().
ip
==
resolver_ip
assert
self
.
db
.
NetworkChange
.
get
().
port
==
53
assert
self
.
db
.
NetworkChange
.
get
().
transport
==
"UDP"
assert
self
.
db
.
NetworkChange
.
get
().
state
==
"open"
assert
self
.
db
.
NetworkChange
.
get
().
status_id
==
status_id
################################################
# getDomainIpDict
################################################
...
...
urlchecker_cli.py
View file @
00fe334b
...
...
@@ -10,9 +10,7 @@ def runUrlChecker():
@
runUrlChecker
.
command
(
"bot"
,
short_help
=
"Runs url checker bot."
)
@
click
.
option
(
"--sqlite"
,
"-s"
,
help
=
"The path of the sqlite DB. (default: :memory:)"
"--sqlite"
,
"-s"
,
help
=
"The path of the sqlite DB. (default: :memory:)"
)
@
click
.
option
(
"--dns"
,
"-d"
,
help
=
"The IP of the DNS server."
)
@
click
.
option
(
"--url"
,
"-u"
,
help
=
"The url to check."
)
...
...
urlchecker_configuration.py
View file @
00fe334b
import
configparser
import
os
from
dns.resolver
import
get_default_resolver
CONFIG_SECTION
=
"URLCHECKER"
...
...
@@ -9,12 +11,7 @@ def createConfiguration(
):
config
=
configparser
.
ConfigParser
(
empty_lines_in_values
=
False
)
# Default values
config
[
CONFIG_SECTION
]
=
{
"INTERVAL"
:
-
1
,
"DOMAIN"
:
""
,
"URL"
:
""
,
"DNS"
:
""
,
}
config
[
CONFIG_SECTION
]
=
{
"INTERVAL"
:
-
1
,
"DOMAIN"
:
""
,
"URL"
:
""
}
# User defined values
if
(
envvar
is
not
None
)
and
(
envvar
in
os
.
environ
):
...
...
@@ -26,7 +23,11 @@ def createConfiguration(
# Required values
if
"SQLITE"
not
in
config
[
CONFIG_SECTION
]:
config
[
CONFIG_SECTION
][
"SQLITE"
]
=
":memory:"
config
[
CONFIG_SECTION
][
"SQLITE"
]
=
":memory:"
if
"DNS"
not
in
config
[
CONFIG_SECTION
]:
config
[
CONFIG_SECTION
][
"DNS"
]
=
"
\
n
"
.
join
(
get_default_resolver
().
nameservers
)
return
config
[
CONFIG_SECTION
]
...
...
urlchecker_dns.py
View file @
00fe334b
from
dns.resolver
import
get_default_resolver
import
dns
from
urlchecker_network
import
logNetwork
...
...
@@ -73,9 +72,6 @@ def queryDNS(db, status_id, resolver_ip, domain_text, rdtype):
def
getReachableResolverList
(
db
,
status_id
,
resolver_ip_list
):
# Create a list of resolver object
if
len
(
resolver_ip_list
)
==
0
:
resolver_ip_list
=
get_default_resolver
().
nameservers
result_ip_list
=
[]
# Check the DNS server availability once
# to prevent using it later if it is down
...
...
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