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
2
Merge Requests
2
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
nexedi
surykatka
Commits
77772997
Commit
77772997
authored
Nov 18, 2021
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
report MX conf issue (ie, unexpected open port 25)
parent
19d1bbb3
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
335 additions
and
98 deletions
+335
-98
src/surykatka/bot.py
src/surykatka/bot.py
+127
-40
src/surykatka/dns.py
src/surykatka/dns.py
+7
-2
tests/test_bot.py
tests/test_bot.py
+152
-44
tests/test_dns.py
tests/test_dns.py
+49
-12
No files found.
src/surykatka/bot.py
View file @
77772997
This diff is collapsed.
Click to expand it.
src/surykatka/dns.py
View file @
77772997
...
...
@@ -104,12 +104,16 @@ def buildResolver(resolver_ip, timeout):
def
queryDNS
(
db
,
status_id
,
resolver_ip
,
domain_text
,
rdtype
,
timeout
=
TIMEOUT
):
# only A (and AAAA) has address property
assert
rdtype
==
"A"
assert
rdtype
in
[
"A"
,
"MX"
],
rdtype
resolver
=
buildResolver
(
resolver_ip
,
timeout
)
try
:
answer_list
=
[
(
x
.
address
if
(
rdtype
==
"A"
)
else
x
.
exchange
.
derelativize
(
domain_text
).
to_text
()[:
-
1
]
)
for
x
in
resolver
.
query
(
domain_text
,
rdtype
,
raise_on_no_answer
=
False
)
...
...
@@ -121,6 +125,7 @@ def queryDNS(db, status_id, resolver_ip, domain_text, rdtype, timeout=TIMEOUT):
dns_resolver
.
NoNameservers
,
):
answer_list
=
[]
# how to differentiate no answer from empty answer
logDnsQuery
(
db
,
status_id
,
resolver_ip
,
domain_text
,
rdtype
,
answer_list
)
return
answer_list
...
...
tests/test_bot.py
View file @
77772997
This diff is collapsed.
Click to expand it.
tests/test_dns.py
View file @
77772997
...
...
@@ -32,13 +32,19 @@ from surykatka.dns import (
)
from
surykatka.status
import
logStatus
import
mock
from
dns
import
name
as
dns_name
class
MockAnswer
(
object
):
class
MockAnswer
A
(
object
):
def
__init__
(
self
,
address
):
self
.
address
=
address
class
MockAnswerMX
(
object
):
def
__init__
(
self
,
label
):
self
.
exchange
=
dns_name
.
Name
(
dns_name
.
from_text
(
label
))
class
SurykatkaDNSTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
db
=
LogDB
(
":memory:"
)
...
...
@@ -253,7 +259,7 @@ class SurykatkaDNSTestCase(unittest.TestCase):
################################################
# queryDNS
################################################
def
test_queryDNS_
default
(
self
):
def
test_queryDNS_
A
(
self
):
resolver_ip
=
"127.0.0.1"
domain
=
"example.org"
rdtype
=
"A"
...
...
@@ -263,8 +269,8 @@ class SurykatkaDNSTestCase(unittest.TestCase):
"surykatka.dns.dns_resolver.Resolver.query"
)
as
mock_query
:
mock_query
.
return_value
=
[
MockAnswer
(
"4.3.2.1"
),
MockAnswer
(
"1.2.3.4"
),
MockAnswer
A
(
"4.3.2.1"
),
MockAnswer
A
(
"1.2.3.4"
),
]
result
=
queryDNS
(
self
.
db
,
status_id
,
resolver_ip
,
domain
,
rdtype
)
...
...
@@ -281,6 +287,37 @@ class SurykatkaDNSTestCase(unittest.TestCase):
assert
self
.
db
.
DnsChange
.
get
().
status_id
==
status_id
assert
result
==
[
"1.2.3.4"
,
"4.3.2.1"
]
def
test_queryDNS_MX
(
self
):
resolver_ip
=
"127.0.0.1"
domain
=
"example.org"
rdtype
=
"MX"
status_id
=
logStatus
(
self
.
db
,
"foo"
)
with
mock
.
patch
(
"surykatka.dns.dns_resolver.Resolver.query"
)
as
mock_query
:
mock_query
.
return_value
=
[
MockAnswerMX
(
"mail1.example.org"
),
MockAnswerMX
(
"mail2.example.org"
),
]
result
=
queryDNS
(
self
.
db
,
status_id
,
resolver_ip
,
domain
,
rdtype
)
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
==
"mail1.example.org, mail2.example.org"
)
assert
self
.
db
.
DnsChange
.
get
().
status_id
==
status_id
assert
result
==
[
"mail1.example.org"
,
"mail2.example.org"
]
def
test_queryDNS_rejectRdtype
(
self
):
resolver_ip
=
"127.0.0.1"
domain
=
"example.org"
...
...
@@ -423,8 +460,8 @@ class SurykatkaDNSTestCase(unittest.TestCase):
"surykatka.dns.dns_resolver.Resolver.query"
)
as
mock_query
:
mock_query
.
return_value
=
[
MockAnswer
(
"4.3.2.1"
),
MockAnswer
(
"1.2.3.4"
),
MockAnswer
A
(
"4.3.2.1"
),
MockAnswer
A
(
"1.2.3.4"
),
]
result
=
getReachableResolverList
(
self
.
db
,
status_id
,
[
resolver_ip
]
...
...
@@ -502,8 +539,8 @@ class SurykatkaDNSTestCase(unittest.TestCase):
"surykatka.dns.dns_resolver.Resolver.query"
)
as
mock_query
:
mock_query
.
return_value
=
[
MockAnswer
(
"4.3.2.1"
),
MockAnswer
(
"1.2.3.4"
),
MockAnswer
A
(
"4.3.2.1"
),
MockAnswer
A
(
"1.2.3.4"
),
]
result
=
getDomainIpDict
(
self
.
db
,
status_id
,
resolver_ip_list
,
domain_list
,
rdtype
...
...
@@ -531,8 +568,8 @@ class SurykatkaDNSTestCase(unittest.TestCase):
"surykatka.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"
)],
[
MockAnswer
A
(
"4.3.2.1"
),
MockAnswerA
(
"1.2.3.4"
)],
[
MockAnswer
A
(
"4.3.2.1"
),
MockAnswerA
(
"1.2.3.5"
)],
]
result
=
getDomainIpDict
(
self
.
db
,
status_id
,
resolver_ip_list
,
domain_list
,
rdtype
...
...
@@ -564,8 +601,8 @@ class SurykatkaDNSTestCase(unittest.TestCase):
"surykatka.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"
)],
[
MockAnswer
A
(
"4.3.2.1"
),
MockAnswerA
(
"1.2.3.4"
)],
[
MockAnswer
A
(
"4.3.2.1"
),
MockAnswerA
(
"1.2.3.5"
)],
]
result
=
getDomainIpDict
(
self
.
db
,
status_id
,
resolver_ip_list
,
domain_list
,
rdtype
...
...
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