Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
mat2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tails
mat2
Commits
8c7979aa
Commit
8c7979aa
authored
6 years ago
by
Julien (jvoisin) Voisin
Browse files
Options
Downloads
Patches
Plain Diff
Add some tests for non-supported embedded fileformats
parent
b310a18e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
libmat2/office.py
+10
-4
10 additions, 4 deletions
libmat2/office.py
tests/data/embedded.docx
+0
-0
0 additions, 0 deletions
tests/data/embedded.docx
tests/data/embedded.odt
+0
-0
0 additions, 0 deletions
tests/data/embedded.odt
tests/test_libmat2.py
+13
-0
13 additions, 0 deletions
tests/test_libmat2.py
with
23 additions
and
4 deletions
libmat2/office.py
+
10
−
4
View file @
8c7979aa
...
...
@@ -40,7 +40,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser):
def
_clean_internal_file
(
self
,
item
:
zipfile
.
ZipInfo
,
temp_folder
:
str
,
zin
:
zipfile
.
ZipFile
,
zout
:
zipfile
.
ZipFile
):
zin
:
zipfile
.
ZipFile
,
zout
:
zipfile
.
ZipFile
)
->
bool
:
output
=
''
zin
.
extract
(
member
=
item
,
path
=
temp_folder
)
if
item
.
filename
not
in
self
.
whitelist
:
...
...
@@ -48,7 +48,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser):
tmp_parser
,
mtype
=
parser_factory
.
get_parser
(
full_path
)
# type: ignore
if
not
tmp_parser
:
print
(
"
%s
'
s format (%s) isn
'
t supported
"
%
(
item
.
filename
,
mtype
))
return
return
False
tmp_parser
.
remove_all
()
output
=
tmp_parser
.
output_filename
else
:
...
...
@@ -57,6 +57,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser):
clean_zinfo
=
self
.
_clean_zipinfo
(
zinfo
)
with
open
(
output
,
'
rb
'
)
as
f
:
zout
.
writestr
(
clean_zinfo
,
f
.
read
())
return
True
class
MSOfficeParser
(
ArchiveBasedAbstractParser
):
...
...
@@ -104,7 +105,10 @@ class MSOfficeParser(ArchiveBasedAbstractParser):
zout
.
writestr
(
item
,
zin
.
read
(
item
))
continue
self
.
_clean_internal_file
(
item
,
temp_folder
,
zin
,
zout
)
if
self
.
_clean_internal_file
(
item
,
temp_folder
,
zin
,
zout
)
is
False
:
zout
.
close
()
os
.
remove
(
self
.
output_filename
)
return
False
shutil
.
rmtree
(
temp_folder
)
zout
.
close
()
...
...
@@ -156,7 +160,9 @@ class LibreOfficeParser(ArchiveBasedAbstractParser):
elif
item
.
filename
==
'
meta.xml
'
:
continue
# don't keep metadata files
self
.
_clean_internal_file
(
item
,
temp_folder
,
zin
,
zout
)
if
self
.
_clean_internal_file
(
item
,
temp_folder
,
zin
,
zout
)
is
False
:
os
.
remove
(
self
.
output_filename
)
return
False
shutil
.
rmtree
(
temp_folder
)
zout
.
close
()
...
...
This diff is collapsed.
Click to expand it.
tests/data/embedded.docx
0 → 100644
+
0
−
0
View file @
8c7979aa
File added
This diff is collapsed.
Click to expand it.
tests/data/embedded.odt
0 → 100644
+
0
−
0
View file @
8c7979aa
File added
This diff is collapsed.
Click to expand it.
tests/test_libmat2.py
+
13
−
0
View file @
8c7979aa
...
...
@@ -27,6 +27,19 @@ class TestParameterInjection(unittest.TestCase):
os
.
remove
(
'
-ver
'
)
class
TestUnsupportedEmbeddedFiles
(
unittest
.
TestCase
):
def
test_odt_with_svg
(
self
):
shutil
.
copy
(
'
./tests/data/embedded.odt
'
,
'
./tests/data/clean.odt
'
)
p
=
office
.
LibreOfficeParser
(
'
./tests/data/clean.odt
'
)
self
.
assertFalse
(
p
.
remove_all
())
os
.
remove
(
'
./tests/data/clean.odt
'
)
def
test_docx_with_svg
(
self
):
shutil
.
copy
(
'
./tests/data/embedded.docx
'
,
'
./tests/data/clean.docx
'
)
p
=
office
.
MSOfficeParser
(
'
./tests/data/clean.docx
'
)
self
.
assertFalse
(
p
.
remove_all
())
os
.
remove
(
'
./tests/data/clean.docx
'
)
class
TestUnsupportedFiles
(
unittest
.
TestCase
):
def
test_pdf
(
self
):
shutil
.
copy
(
'
./tests/test_libmat2.py
'
,
'
./tests/clean.py
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment