Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
surykatka
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Romain Courteaud
surykatka
Commits
19d1bbb3
Commit
19d1bbb3
authored
Nov 22, 2021
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change dns import declaration
Python seems confused with the local dns.py conflict
parent
3e29a335
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
36 deletions
+42
-36
src/surykatka/dns.py
src/surykatka/dns.py
+15
-9
tests/test_bot.py
tests/test_bot.py
+12
-12
tests/test_dns.py
tests/test_dns.py
+15
-15
No files found.
src/surykatka/dns.py
View file @
19d1bbb3
...
...
@@ -17,7 +17,11 @@
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
import
dns
from
dns
import
(
resolver
as
dns_resolver
,
name
as
dns_name
,
exception
as
dns_exception
,
)
from
.network
import
logNetwork
from
peewee
import
fn
...
...
@@ -90,7 +94,7 @@ def logDnsQuery(db, status_id, resolver_ip, domain_text, rdtype, answer_list):
def
buildResolver
(
resolver_ip
,
timeout
):
resolver
=
dns
.
resolver
.
Resolver
(
configure
=
False
)
resolver
=
dns
_
resolver
.
Resolver
(
configure
=
False
)
resolver
.
nameservers
.
append
(
resolver_ip
)
resolver
.
timeout
=
timeout
resolver
.
lifetime
=
timeout
...
...
@@ -111,10 +115,10 @@ def queryDNS(db, status_id, resolver_ip, domain_text, rdtype, timeout=TIMEOUT):
)
]
except
(
dns
.
resolver
.
NXDOMAIN
,
dns
.
resolver
.
NoAnswer
,
dns
.
exception
.
Timeout
,
dns
.
resolver
.
NoNameservers
,
dns
_
resolver
.
NXDOMAIN
,
dns
_
resolver
.
NoAnswer
,
dns
_
exception
.
Timeout
,
dns
_
resolver
.
NoNameservers
,
):
answer_list
=
[]
...
...
@@ -148,10 +152,12 @@ def getReachableResolverList(db, status_id, resolver_ip_list, timeout=TIMEOUT):
def
expandDomainList
(
domain_list
,
public_suffix_list
=
None
):
for
domain_text
in
domain_list
:
dns_name
=
dns
.
name
.
from_text
(
domain_text
)
if
(
len
(
dns_name
.
labels
)
-
1
)
>
2
:
dns_name
_value
=
dns_
name
.
from_text
(
domain_text
)
if
(
len
(
dns_name
_value
.
labels
)
-
1
)
>
2
:
# https://publicsuffix.org/list/public_suffix_list.dat
parent_domain_text
=
dns_name
.
parent
().
to_text
(
omit_final_dot
=
True
)
parent_domain_text
=
dns_name_value
.
parent
().
to_text
(
omit_final_dot
=
True
)
if
(
public_suffix_list
is
None
)
or
(
parent_domain_text
not
in
public_suffix_list
):
...
...
tests/test_bot.py
View file @
19d1bbb3
...
...
@@ -84,13 +84,13 @@ class SurykatkaBotTestCase(unittest.TestCase):
def
test_emptyConfiguration
(
self
):
resolver_ip
=
"192.168.0.254"
resolver
=
surykatka
.
dns
.
dns
.
resolver
.
Resolver
(
configure
=
False
)
resolver
=
surykatka
.
dns
.
dns
_
resolver
.
Resolver
(
configure
=
False
)
resolver
.
nameservers
.
append
(
resolver_ip
)
with
mock
.
patch
(
"surykatka.configuration.get_default_resolver"
)
as
mock_get_default_resolver
,
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
:
mock_get_default_resolver
.
return_value
=
resolver
...
...
@@ -117,7 +117,7 @@ class SurykatkaBotTestCase(unittest.TestCase):
def
test_oneNameserverOneDomainOneIp
(
self
):
resolver_ip
=
"127.0.0.1"
resolver
=
surykatka
.
dns
.
dns
.
resolver
.
Resolver
(
configure
=
False
)
resolver
=
surykatka
.
dns
.
dns
_
resolver
.
Resolver
(
configure
=
False
)
resolver
.
nameservers
.
append
(
resolver_ip
)
with
mock
.
patch
(
...
...
@@ -125,7 +125,7 @@ class SurykatkaBotTestCase(unittest.TestCase):
)
as
mock_whois
,
mock
.
patch
(
"surykatka.configuration.get_default_resolver"
)
as
mock_get_default_resolver
,
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
,
mock
.
patch
(
"surykatka.network.socket.socket"
)
as
mock_socket
,
mock
.
patch
(
...
...
@@ -212,7 +212,7 @@ class SurykatkaBotTestCase(unittest.TestCase):
with
mock
.
patch
(
"surykatka.domain.whois.whois"
)
as
mock_whois
,
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
,
mock
.
patch
(
"surykatka.network.socket.socket"
)
as
mock_socket
,
mock
.
patch
(
...
...
@@ -302,7 +302,7 @@ class SurykatkaBotTestCase(unittest.TestCase):
with
mock
.
patch
(
"surykatka.domain.whois.whois"
)
as
mock_whois
,
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
,
mock
.
patch
(
"surykatka.network.socket.socket"
)
as
mock_socket
,
mock
.
patch
(
...
...
@@ -394,7 +394,7 @@ class SurykatkaBotTestCase(unittest.TestCase):
with
mock
.
patch
(
"surykatka.domain.whois.whois"
)
as
mock_whois
,
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
,
mock
.
patch
(
"surykatka.network.socket.socket"
)
as
mock_socket
,
mock
.
patch
(
...
...
@@ -498,7 +498,7 @@ class SurykatkaBotTestCase(unittest.TestCase):
with
mock
.
patch
(
"surykatka.domain.whois.whois"
)
as
mock_whois
,
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
,
mock
.
patch
(
"surykatka.network.socket.socket"
)
as
mock_socket
,
mock
.
patch
(
...
...
@@ -592,7 +592,7 @@ class SurykatkaBotTestCase(unittest.TestCase):
with
mock
.
patch
(
"surykatka.domain.whois.whois"
)
as
mock_whois
,
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
,
mock
.
patch
(
"surykatka.network.socket.socket"
)
as
mock_socket
,
mock
.
patch
(
...
...
@@ -675,7 +675,7 @@ class SurykatkaBotTestCase(unittest.TestCase):
with
mock
.
patch
(
"surykatka.domain.whois.whois"
)
as
mock_whois
,
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
,
mock
.
patch
(
"surykatka.network.socket.socket"
)
as
mock_socket
,
mock
.
patch
(
...
...
@@ -756,7 +756,7 @@ class SurykatkaBotTestCase(unittest.TestCase):
with
mock
.
patch
(
"surykatka.domain.whois.whois"
)
as
mock_whois
,
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
,
mock
.
patch
(
"surykatka.network.socket.socket"
)
as
mock_socket
,
mock
.
patch
(
...
...
@@ -805,7 +805,7 @@ class SurykatkaBotStatusTestCase(unittest.TestCase):
def
test_status_emptyConfiguration
(
self
):
resolver_ip
=
"192.168.0.254"
resolver
=
surykatka
.
dns
.
dns
.
resolver
.
Resolver
(
configure
=
False
)
resolver
=
surykatka
.
dns
.
dns
_
resolver
.
Resolver
(
configure
=
False
)
resolver
.
nameservers
.
append
(
resolver_ip
)
with
mock
.
patch
(
...
...
tests/test_dns.py
View file @
19d1bbb3
...
...
@@ -260,7 +260,7 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
:
mock_query
.
return_value
=
[
MockAnswer
(
"4.3.2.1"
),
...
...
@@ -301,11 +301,11 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
:
def
sideEffect
(
*
args
,
**
kw
):
raise
surykatka
.
dns
.
dns
.
resolver
.
NXDOMAIN
()
raise
surykatka
.
dns
.
dns
_
resolver
.
NXDOMAIN
()
mock_query
.
side_effect
=
sideEffect
result
=
queryDNS
(
self
.
db
,
status_id
,
resolver_ip
,
domain
,
rdtype
)
...
...
@@ -330,11 +330,11 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
:
def
sideEffect
(
*
args
,
**
kw
):
raise
surykatka
.
dns
.
dns
.
resolver
.
NoAnswer
()
raise
surykatka
.
dns
.
dns
_
resolver
.
NoAnswer
()
mock_query
.
side_effect
=
sideEffect
result
=
queryDNS
(
self
.
db
,
status_id
,
resolver_ip
,
domain
,
rdtype
)
...
...
@@ -359,11 +359,11 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
:
def
sideEffect
(
*
args
,
**
kw
):
raise
surykatka
.
dns
.
dns
.
exception
.
Timeout
()
raise
surykatka
.
dns
.
dns
_
exception
.
Timeout
()
mock_query
.
side_effect
=
sideEffect
result
=
queryDNS
(
self
.
db
,
status_id
,
resolver_ip
,
domain
,
rdtype
)
...
...
@@ -388,11 +388,11 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
:
def
sideEffect
(
*
args
,
**
kw
):
raise
surykatka
.
dns
.
dns
.
resolver
.
NoNameservers
()
raise
surykatka
.
dns
.
dns
_
resolver
.
NoNameservers
()
mock_query
.
side_effect
=
sideEffect
result
=
queryDNS
(
self
.
db
,
status_id
,
resolver_ip
,
domain
,
rdtype
)
...
...
@@ -420,7 +420,7 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
:
mock_query
.
return_value
=
[
MockAnswer
(
"4.3.2.1"
),
...
...
@@ -457,11 +457,11 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
:
def
sideEffect
(
*
args
,
**
kw
):
raise
surykatka
.
dns
.
dns
.
exception
.
Timeout
()
raise
surykatka
.
dns
.
dns
_
exception
.
Timeout
()
mock_query
.
side_effect
=
sideEffect
...
...
@@ -499,7 +499,7 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
:
mock_query
.
return_value
=
[
MockAnswer
(
"4.3.2.1"
),
...
...
@@ -528,7 +528,7 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
:
mock_query
.
side_effect
=
[
[
MockAnswer
(
"4.3.2.1"
),
MockAnswer
(
"1.2.3.4"
)],
...
...
@@ -561,7 +561,7 @@ class SurykatkaDNSTestCase(unittest.TestCase):
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"surykatka.dns.dns
.
resolver.Resolver.query"
"surykatka.dns.dns
_
resolver.Resolver.query"
)
as
mock_query
:
mock_query
.
side_effect
=
[
[
MockAnswer
(
"4.3.2.1"
),
MockAnswer
(
"1.2.3.4"
)],
...
...
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