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
4dc7faf6
Commit
4dc7faf6
authored
Nov 29, 2019
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More tests
parent
11840882
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
376 additions
and
251 deletions
+376
-251
test_urlchecker_db.py
test_urlchecker_db.py
+23
-0
test_urlchecker_http.py
test_urlchecker_http.py
+176
-135
test_urlchecker_network.py
test_urlchecker_network.py
+168
-103
urlchecker_db.py
urlchecker_db.py
+5
-1
urlchecker_http.py
urlchecker_http.py
+4
-12
No files found.
test_urlchecker_db.py
0 → 100644
View file @
4dc7faf6
import
unittest
from
urlchecker_db
import
LogDB
import
peewee
class
UrlCheckerNetworkTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
db
=
LogDB
(
":memory:"
)
def
test_createTable
(
self
):
assert
self
.
db
.
_db
.
pragma
(
"user_version"
)
==
0
self
.
db
.
createTables
()
assert
self
.
db
.
_db
.
pragma
(
"user_version"
)
==
1
def
suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
UrlCheckerDBTestCase
))
return
suite
if
__name__
==
"__main__"
:
unittest
.
main
(
defaultTest
=
"suite"
)
test_urlchecker_http.py
View file @
4dc7faf6
This diff is collapsed.
Click to expand it.
test_urlchecker_network.py
View file @
4dc7faf6
This diff is collapsed.
Click to expand it.
urlchecker_db.py
View file @
4dc7faf6
...
...
@@ -47,8 +47,11 @@ class LogDB:
transport
=
peewee
.
TextField
()
port
=
peewee
.
IntegerField
()
state
=
peewee
.
TextField
()
class
Meta
:
primary_key
=
peewee
.
CompositeKey
(
"status"
,
"ip"
,
"transport"
,
"port"
)
primary_key
=
peewee
.
CompositeKey
(
"status"
,
"ip"
,
"transport"
,
"port"
)
class
DnsChange
(
BaseModel
):
status
=
peewee
.
ForeignKeyField
(
Status
)
...
...
@@ -62,6 +65,7 @@ class LogDB:
ip
=
peewee
.
TextField
()
url
=
peewee
.
TextField
()
status_code
=
peewee
.
IntegerField
()
class
Meta
:
primary_key
=
peewee
.
CompositeKey
(
"status"
,
"ip"
,
"url"
)
...
...
urlchecker_http.py
View file @
4dc7faf6
...
...
@@ -21,12 +21,7 @@ def getUserAgent(version):
)
def
request
(
url
,
headers
=
None
,
session
=
requests
,
version
=
0
):
def
request
(
url
,
headers
=
None
,
session
=
requests
,
version
=
0
):
if
headers
is
None
:
headers
=
{}
...
...
@@ -99,19 +94,16 @@ def checkHttpStatus(db, status_id, url, ip, bot_version):
)
session
=
requests
.
Session
()
session
.
mount
(
base_url
,
ForcedIPHTTPSAdapter
(
dest_ip
=
ip
))
request_kw
[
'session'
]
=
session
request_kw
[
"session"
]
=
session
ip_url
=
url
elif
parsed_url
.
scheme
==
"http"
:
# Force IP location
parsed_url
=
parsed_url
.
_replace
(
netloc
=
ip
)
ip_url
=
parsed_url
.
geturl
()
else
:
raise
NotImplementedError
(
'Unhandled url: %s'
%
url
)
raise
NotImplementedError
(
"Unhandled url: %s"
%
url
)
response
=
request
(
ip_url
,
headers
=
{
"Host"
:
hostname
},
version
=
bot_version
,
**
request_kw
ip_url
,
headers
=
{
"Host"
:
hostname
},
version
=
bot_version
,
**
request_kw
)
logHttpStatus
(
db
,
ip
,
url
,
response
.
status_code
,
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