Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apachedex
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
Jérome Perrin
apachedex
Commits
10d91ee0
Commit
10d91ee0
authored
Mar 18, 2019
by
Jérome Perrin
Committed by
Vincent Pelletier
Mar 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: check for zlib/bz2 encoded logs
parent
128167a3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
0 deletions
+29
-0
apachedex/tests.py
apachedex/tests.py
+29
-0
No files found.
apachedex/tests.py
View file @
10d91ee0
import
unittest
import
unittest
import
sys
import
sys
import
json
import
json
import
bz2
import
gzip
from
StringIO
import
StringIO
from
StringIO
import
StringIO
import
tempfile
import
tempfile
import
apachedex
import
apachedex
...
@@ -60,3 +62,30 @@ class TestCharacterEncoding(ApacheDEXTestCase):
...
@@ -60,3 +62,30 @@ class TestCharacterEncoding(ApacheDEXTestCase):
apachedex
.
main
()
apachedex
.
main
()
with
open
(
fout
.
name
)
as
f
:
with
open
(
fout
.
name
)
as
f
:
self
.
assertTrue
(
json
.
load
(
f
))
self
.
assertTrue
(
json
.
load
(
f
))
class
EncodedInputTestMixin
:
DEFAULT_LINE
=
b'127.0.0.1 - - [14/Jul/2017:09:41:41 +0200] "GET / HTTP/1.1" 200 7499 "https://example.org/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" 1754'
def
test
(
self
):
with
tempfile
.
NamedTemporaryFile
()
as
fin
,
tempfile
.
NamedTemporaryFile
()
as
fout
:
fin
.
write
(
self
.
_getInputData
())
fin
.
flush
()
sys
.
argv
=
[
'apachedex'
,
'--base=/'
,
fin
.
name
,
'-f'
,
'json'
,
'-o'
,
fout
.
name
]
apachedex
.
main
()
self
.
assertNotIn
(
'Malformed line'
,
sys
.
stderr
.
getvalue
())
with
open
(
fout
.
name
)
as
f
:
self
.
assertTrue
(
json
.
load
(
f
))
class
TestBzip2Encoding
(
ApacheDEXTestCase
,
EncodedInputTestMixin
):
def
_getInputData
(
self
):
return
bz2
.
compress
(
self
.
DEFAULT_LINE
)
class
TestZlibEncoding
(
ApacheDEXTestCase
,
EncodedInputTestMixin
):
def
_getInputData
(
self
):
f
=
StringIO
()
with
gzip
.
GzipFile
(
mode
=
"w"
,
fileobj
=
f
)
as
gzfile
:
gzfile
.
write
(
self
.
DEFAULT_LINE
)
return
f
.
getvalue
()
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