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
4e315e81
Commit
4e315e81
authored
Dec 02, 2019
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lint
parent
b8bd2d34
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
15 additions
and
30 deletions
+15
-30
test_urlchecker_db.py
test_urlchecker_db.py
+0
-1
test_urlchecker_dns.py
test_urlchecker_dns.py
+2
-2
test_urlchecker_http.py
test_urlchecker_http.py
+8
-21
test_urlchecker_network.py
test_urlchecker_network.py
+2
-1
urlchecker_dns.py
urlchecker_dns.py
+1
-1
urlchecker_http.py
urlchecker_http.py
+1
-3
urlchecker_network.py
urlchecker_network.py
+1
-1
No files found.
test_urlchecker_db.py
View file @
4e315e81
import
unittest
import
unittest
from
urlchecker_db
import
LogDB
from
urlchecker_db
import
LogDB
import
peewee
class
UrlCheckerDBTestCase
(
unittest
.
TestCase
):
class
UrlCheckerDBTestCase
(
unittest
.
TestCase
):
...
...
test_urlchecker_dns.py
View file @
4e315e81
...
@@ -43,7 +43,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
...
@@ -43,7 +43,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
rdtype
=
"foo"
rdtype
=
"foo"
answer_list
=
[
"4.3.2.1"
,
"1.2.3.4"
]
answer_list
=
[
"4.3.2.1"
,
"1.2.3.4"
]
status_id
=
logStatus
(
self
.
db
,
"foo"
)
status_id
=
logStatus
(
self
.
db
,
"foo"
)
result
=
logDnsQuery
(
logDnsQuery
(
self
.
db
,
status_id
,
resolver_ip
,
domain
,
rdtype
,
answer_list
self
.
db
,
status_id
,
resolver_ip
,
domain
,
rdtype
,
answer_list
)
)
answer_list
.
extend
(
"127.0.0.1"
)
answer_list
.
extend
(
"127.0.0.1"
)
...
@@ -165,7 +165,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
...
@@ -165,7 +165,7 @@ class UrlCheckerDNSTestCase(unittest.TestCase):
rdtype_2
=
rdtype
+
"bar"
rdtype_2
=
rdtype
+
"bar"
answer_list
=
[
"4.3.2.1"
,
"1.2.3.4"
]
answer_list
=
[
"4.3.2.1"
,
"1.2.3.4"
]
status_id
=
logStatus
(
self
.
db
,
"foo"
)
status_id
=
logStatus
(
self
.
db
,
"foo"
)
result
=
logDnsQuery
(
logDnsQuery
(
self
.
db
,
status_id
,
resolver_ip
,
domain
,
rdtype
,
answer_list
self
.
db
,
status_id
,
resolver_ip
,
domain
,
rdtype
,
answer_list
)
)
logDnsQuery
(
logDnsQuery
(
...
...
test_urlchecker_http.py
View file @
4e315e81
...
@@ -29,21 +29,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
...
@@ -29,21 +29,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
################################################
################################################
# getUserAgent
# getUserAgent
################################################
################################################
def
test_getUserAgent_default
(
self
):
def
test_getUserAgent_version
(
self
):
result
=
getUserAgent
()
assert
(
result
==
"URLCHECKER/0 (+https://lab.nexedi.com/romain/url-checker)"
)
def
test_getUserAgent_default
(
self
):
result
=
getUserAgent
(
None
)
assert
(
result
==
"URLCHECKER/0 (+https://lab.nexedi.com/romain/url-checker)"
)
def
test_getUserAgent_default
(
self
):
result
=
getUserAgent
(
"0.0.3"
)
result
=
getUserAgent
(
"0.0.3"
)
assert
(
assert
(
result
result
...
@@ -56,7 +42,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
...
@@ -56,7 +42,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
def
test_request_arguments
(
self
):
def
test_request_arguments
(
self
):
url_to_proxy
=
"http://example.org/"
url_to_proxy
=
"http://example.org/"
with
mock
.
patch
(
"urlchecker_http.requests.request"
)
as
mock_request
:
with
mock
.
patch
(
"urlchecker_http.requests.request"
)
as
mock_request
:
re
sponse
=
re
quest
(
url_to_proxy
)
request
(
url_to_proxy
)
assert
mock_request
.
call_count
==
1
assert
mock_request
.
call_count
==
1
mock_request
.
assert_called_with
(
mock_request
.
assert_called_with
(
"GET"
,
"GET"
,
...
@@ -178,6 +164,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
...
@@ -178,6 +164,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
assert
self
.
db
.
HttpCodeChange
.
get
().
url
==
url
assert
self
.
db
.
HttpCodeChange
.
get
().
url
==
url
assert
self
.
db
.
HttpCodeChange
.
get
().
status_code
==
status_code
assert
self
.
db
.
HttpCodeChange
.
get
().
status_code
==
status_code
assert
self
.
db
.
HttpCodeChange
.
get
().
status_id
==
status_id
assert
self
.
db
.
HttpCodeChange
.
get
().
status_id
==
status_id
assert
result
==
status_id
def
test_logHttpStatus_insertOnlyOnePerStatusIdIPUrl
(
self
):
def
test_logHttpStatus_insertOnlyOnePerStatusIdIPUrl
(
self
):
ip
=
"127.0.0.1"
ip
=
"127.0.0.1"
...
@@ -189,7 +176,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
...
@@ -189,7 +176,7 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
logHttpStatus
(
self
.
db
,
ip
,
url
,
status_code
+
1
,
status_id
)
logHttpStatus
(
self
.
db
,
ip
,
url
,
status_code
+
1
,
status_id
)
except
peewee
.
IntegrityError
:
except
peewee
.
IntegrityError
:
assert
self
.
db
.
HttpCodeChange
.
select
().
count
()
==
1
assert
self
.
db
.
HttpCodeChange
.
select
().
count
()
==
1
assert
self
.
db
.
HttpCodeChange
.
get
().
status
==
result
assert
self
.
db
.
HttpCodeChange
.
get
().
status
_id
==
result
else
:
else
:
raise
NotImplementedError
(
"Expected IntegrityError"
)
raise
NotImplementedError
(
"Expected IntegrityError"
)
...
@@ -263,10 +250,10 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
...
@@ -263,10 +250,10 @@ class UrlCheckerHttpTestCase(unittest.TestCase):
url_2
=
url
+
"2"
url_2
=
url
+
"2"
status_code
=
200
status_code
=
200
status_id
=
logStatus
(
self
.
db
,
"foo"
)
status_id
=
logStatus
(
self
.
db
,
"foo"
)
result
=
logHttpStatus
(
self
.
db
,
ip
,
url
,
status_code
,
status_id
)
logHttpStatus
(
self
.
db
,
ip
,
url
,
status_code
,
status_id
)
result_2
=
logHttpStatus
(
self
.
db
,
ip_2
,
url
,
status_code
,
status_id
)
logHttpStatus
(
self
.
db
,
ip_2
,
url
,
status_code
,
status_id
)
result_3
=
logHttpStatus
(
self
.
db
,
ip
,
url_2
,
status_code
,
status_id
)
logHttpStatus
(
self
.
db
,
ip
,
url_2
,
status_code
,
status_id
)
result_4
=
logHttpStatus
(
self
.
db
,
ip_2
,
url_2
,
status_code
,
status_id
)
logHttpStatus
(
self
.
db
,
ip_2
,
url_2
,
status_code
,
status_id
)
assert
self
.
db
.
HttpCodeChange
.
select
().
count
()
==
4
assert
self
.
db
.
HttpCodeChange
.
select
().
count
()
==
4
################################################
################################################
...
...
test_urlchecker_network.py
View file @
4e315e81
...
@@ -29,6 +29,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
...
@@ -29,6 +29,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
assert
self
.
db
.
NetworkChange
.
get
().
transport
==
transport
assert
self
.
db
.
NetworkChange
.
get
().
transport
==
transport
assert
self
.
db
.
NetworkChange
.
get
().
state
==
state
assert
self
.
db
.
NetworkChange
.
get
().
state
==
state
assert
self
.
db
.
NetworkChange
.
get
().
status_id
==
status_id
assert
self
.
db
.
NetworkChange
.
get
().
status_id
==
status_id
assert
result
==
status_id
def
test_logNetwork_insertOnlyOnePerStatusIdIPPortTransport
(
self
):
def
test_logNetwork_insertOnlyOnePerStatusIdIPPortTransport
(
self
):
ip
=
"127.0.0.1"
ip
=
"127.0.0.1"
...
@@ -37,7 +38,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
...
@@ -37,7 +38,7 @@ class UrlCheckerNetworkTestCase(unittest.TestCase):
state
=
"bar"
state
=
"bar"
status_id
=
logStatus
(
self
.
db
,
"foo"
)
status_id
=
logStatus
(
self
.
db
,
"foo"
)
result
=
logNetwork
(
self
.
db
,
ip
,
transport
,
port
,
state
,
status_id
)
logNetwork
(
self
.
db
,
ip
,
transport
,
port
,
state
,
status_id
)
try
:
try
:
logNetwork
(
self
.
db
,
ip
,
transport
,
port
,
state
+
"."
,
status_id
)
logNetwork
(
self
.
db
,
ip
,
transport
,
port
,
state
+
"."
,
status_id
)
except
peewee
.
IntegrityError
:
except
peewee
.
IntegrityError
:
...
...
urlchecker_dns.py
View file @
4e315e81
...
@@ -58,7 +58,7 @@ def queryDNS(db, status_id, resolver_ip, resolver, domain_text, rdtype):
...
@@ -58,7 +58,7 @@ def queryDNS(db, status_id, resolver_ip, resolver, domain_text, rdtype):
):
):
answer_list
=
[]
answer_list
=
[]
logD
NS
Query
(
db
,
status_id
,
resolver_ip
,
domain_text
,
rdtype
,
answer_list
)
logD
ns
Query
(
db
,
status_id
,
resolver_ip
,
domain_text
,
rdtype
,
answer_list
)
return
answer_list
return
answer_list
...
...
urlchecker_http.py
View file @
4e315e81
import
requests
import
requests
from
urllib.parse
import
urlparse
,
urlunsplit
from
urllib.parse
import
urlparse
,
urlunsplit
import
sys
import
traceback
from
forcediphttpsadapter.adapters
import
ForcedIPHTTPSAdapter
from
forcediphttpsadapter.adapters
import
ForcedIPHTTPSAdapter
...
@@ -79,7 +77,7 @@ def logHttpStatus(db, ip, url, code, status_id):
...
@@ -79,7 +77,7 @@ def logHttpStatus(db, ip, url, code, status_id):
previous_entry
=
db
.
HttpCodeChange
.
create
(
previous_entry
=
db
.
HttpCodeChange
.
create
(
status
=
status_id
,
ip
=
ip
,
url
=
url
,
status_code
=
code
status
=
status_id
,
ip
=
ip
,
url
=
url
,
status_code
=
code
)
)
return
previous_entry
.
status
return
previous_entry
.
status
_id
def
checkHttpStatus
(
db
,
status_id
,
url
,
ip
,
bot_version
):
def
checkHttpStatus
(
db
,
status_id
,
url
,
ip
,
bot_version
):
...
...
urlchecker_network.py
View file @
4e315e81
...
@@ -30,7 +30,7 @@ def logNetwork(db, ip, transport, port, state, status_id):
...
@@ -30,7 +30,7 @@ def logNetwork(db, ip, transport, port, state, status_id):
port
=
port
,
port
=
port
,
state
=
state
,
state
=
state
,
)
)
return
previous_entry
.
status
return
previous_entry
.
status
_id
def
isTcpPortOpen
(
db
,
ip
,
port
,
status_id
):
def
isTcpPortOpen
(
db
,
ip
,
port
,
status_id
):
...
...
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