From 0eb0d7947faada0a83ed54a5d35d0a680c9b2b5a Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Thu, 23 Nov 2017 09:19:22 +0100 Subject: [PATCH] unittest: remove file type from test module names and data dirs --- tests/msodde/__init__.py | 0 tests/msodde/test_basic.py | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/msodde/test_blacklist.py | 249 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/msodde_doc/__init__.py | 0 tests/msodde_doc/test_basic.py | 121 ------------------------------------------------------------------------------------------------------------------------- tests/msodde_docx/__init__.py | 0 tests/msodde_docx/test_blacklist.py | 249 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- tests/test-data/msodde-doc/dde-test-from-office2003.doc | Bin 24576 -> 0 bytes tests/test-data/msodde-doc/dde-test-from-office2013-utf_16le-korean.doc | Bin 27648 -> 0 bytes tests/test-data/msodde-doc/dde-test-from-office2016.doc | Bin 23552 -> 0 bytes tests/test-data/msodde-doc/dde-test.docm | Bin 11820 -> 0 bytes tests/test-data/msodde-doc/dde-test.docx | Bin 11802 -> 0 bytes tests/test-data/msodde-doc/harmless-clean-2003.xml | 3 --- tests/test-data/msodde-doc/harmless-clean.doc | Bin 23040 -> 0 bytes tests/test-data/msodde-doc/harmless-clean.docm | Bin 12580 -> 0 bytes tests/test-data/msodde-doc/harmless-clean.docx | Bin 12594 -> 0 bytes tests/test-data/msodde-doc/harmless-clean.xml | 3 --- tests/test-data/msodde/dde-test-from-office2003.doc | Bin 0 -> 24576 bytes tests/test-data/msodde/dde-test-from-office2013-utf_16le-korean.doc | Bin 0 -> 27648 bytes tests/test-data/msodde/dde-test-from-office2016.doc | Bin 0 -> 23552 bytes tests/test-data/msodde/dde-test.docm | Bin 0 -> 11820 bytes tests/test-data/msodde/dde-test.docx | Bin 0 -> 11802 bytes tests/test-data/msodde/harmless-clean-2003.xml | 3 +++ tests/test-data/msodde/harmless-clean.doc | Bin 0 -> 23040 bytes tests/test-data/msodde/harmless-clean.docm | Bin 0 -> 12580 bytes tests/test-data/msodde/harmless-clean.docx | Bin 0 -> 12594 bytes tests/test-data/msodde/harmless-clean.xml | 3 +++ 27 files changed, 376 insertions(+), 376 deletions(-) create mode 100644 tests/msodde/__init__.py create mode 100644 tests/msodde/test_basic.py create mode 100644 tests/msodde/test_blacklist.py delete mode 100644 tests/msodde_doc/__init__.py delete mode 100644 tests/msodde_doc/test_basic.py delete mode 100644 tests/msodde_docx/__init__.py delete mode 100644 tests/msodde_docx/test_blacklist.py delete mode 100644 tests/test-data/msodde-doc/dde-test-from-office2003.doc delete mode 100644 tests/test-data/msodde-doc/dde-test-from-office2013-utf_16le-korean.doc delete mode 100644 tests/test-data/msodde-doc/dde-test-from-office2016.doc delete mode 100644 tests/test-data/msodde-doc/dde-test.docm delete mode 100644 tests/test-data/msodde-doc/dde-test.docx delete mode 100644 tests/test-data/msodde-doc/harmless-clean-2003.xml delete mode 100644 tests/test-data/msodde-doc/harmless-clean.doc delete mode 100644 tests/test-data/msodde-doc/harmless-clean.docm delete mode 100644 tests/test-data/msodde-doc/harmless-clean.docx delete mode 100644 tests/test-data/msodde-doc/harmless-clean.xml create mode 100644 tests/test-data/msodde/dde-test-from-office2003.doc create mode 100644 tests/test-data/msodde/dde-test-from-office2013-utf_16le-korean.doc create mode 100644 tests/test-data/msodde/dde-test-from-office2016.doc create mode 100644 tests/test-data/msodde/dde-test.docm create mode 100644 tests/test-data/msodde/dde-test.docx create mode 100644 tests/test-data/msodde/harmless-clean-2003.xml create mode 100644 tests/test-data/msodde/harmless-clean.doc create mode 100644 tests/test-data/msodde/harmless-clean.docm create mode 100644 tests/test-data/msodde/harmless-clean.docx create mode 100644 tests/test-data/msodde/harmless-clean.xml diff --git a/tests/msodde/__init__.py b/tests/msodde/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/msodde/__init__.py diff --git a/tests/msodde/test_basic.py b/tests/msodde/test_basic.py new file mode 100644 index 0000000..dfc44ca --- /dev/null +++ b/tests/msodde/test_basic.py @@ -0,0 +1,121 @@ +""" Test some basic behaviour of msodde.py + +Ensure that +- doc and docx are read without error +- garbage returns error return status +- dde-links are found where appropriate +""" + +from __future__ import print_function + +import unittest +from oletools import msodde +from tests.test_utils import OutputCapture, DATA_BASE_DIR as BASE_DIR +import shlex +from os.path import join +from traceback import print_exc + + +class TestReturnCode(unittest.TestCase): + + def test_valid_doc(self): + """ check that a valid doc file leads to 0 exit status """ + for filename in ('dde-test-from-office2003', 'dde-test-from-office2016', + 'harmless-clean', 'dde-test-from-office2013-utf_16le-korean'): + self.do_test_validity(join(BASE_DIR, 'msodde', + filename + '.doc')) + + def test_valid_docx(self): + """ check that a valid docx file leads to 0 exit status """ + for filename in 'dde-test', 'harmless-clean': + self.do_test_validity(join(BASE_DIR, 'msodde', + filename + '.docx')) + + def test_valid_docm(self): + """ check that a valid docm file leads to 0 exit status """ + for filename in 'dde-test', 'harmless-clean': + self.do_test_validity(join(BASE_DIR, 'msodde', + filename + '.docm')) + + def test_invalid_other(self): + """ check that xml do not work yet """ + for extn in '-2003.xml', '.xml': + self.do_test_validity(join(BASE_DIR, 'msodde', + 'harmless-clean' + extn), True) + + def test_invalid_none(self): + """ check that no file argument leads to non-zero exit status """ + self.do_test_validity('', True) + + def test_invalid_empty(self): + """ check that empty file argument leads to non-zero exit status """ + self.do_test_validity(join(BASE_DIR, 'basic/empty'), True) + + def test_invalid_text(self): + """ check that text file argument leads to non-zero exit status """ + self.do_test_validity(join(BASE_DIR, 'basic/text'), True) + + def do_test_validity(self, args, expect_error=False): + """ helper for test_valid_doc[x] """ + args = shlex.split(args) + return_code = -1 + have_exception = False + try: + return_code = msodde.main(args) + except Exception: + have_exception = True + print_exc() + except SystemExit as se: # sys.exit() was called + return_code = se.code + if se.code is None: + return_code = 0 + + self.assertEqual(expect_error, have_exception or (return_code != 0), + msg='Args={0}, expect={1}, exc={2}, return={3}' + .format(args, expect_error, have_exception, + return_code)) + + +class TestDdeInDoc(unittest.TestCase): + + def get_dde_from_output(self, capturer): + """ helper to read dde links from captured output """ + have_start_line = False + result = [] + for line in capturer: + if not line.strip(): + continue # skip empty lines + if have_start_line: + result.append(line) + elif line == 'DDE Links:': + have_start_line = True + + self.assertTrue(have_start_line) # ensure output was complete + return result + + def test_with_dde(self): + """ check that dde links appear on stdout """ + with OutputCapture() as capturer: + msodde.main([join(BASE_DIR, 'msodde', + 'dde-test-from-office2003.doc')]) + self.assertNotEqual(len(self.get_dde_from_output(capturer)), 0, + msg='Found no dde links in output for doc file') + + def test_no_dde(self): + """ check that no dde links appear on stdout """ + with OutputCapture() as capturer: + msodde.main([join(BASE_DIR, 'msodde', 'harmless-clean.doc')]) + self.assertEqual(len(self.get_dde_from_output(capturer)), 0, + msg='Found dde links in output for doc file') + + def test_with_dde_utf16le(self): + """ check that dde links appear on stdout """ + with OutputCapture() as capturer: + msodde.main([join(BASE_DIR, 'msodde', + 'dde-test-from-office2013-utf_16le-korean.doc')]) + self.assertNotEqual(len(self.get_dde_from_output(capturer)), 0, + msg='Found no dde links in output for doc file') + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/msodde/test_blacklist.py b/tests/msodde/test_blacklist.py new file mode 100644 index 0000000..babea81 --- /dev/null +++ b/tests/msodde/test_blacklist.py @@ -0,0 +1,249 @@ +""" Test the msodde blacklist feature + +Take a few examples from the standard (iso29500-1:2016) and see that they match +""" + +import unittest +from oletools.msodde import field_is_blacklisted + +EXAMPLES_MATCH = ( + r'DATE', + r'DATE \@ "dddd, MMMM dd, yyyy"', + r'DATE \@ "dddd, MMMM dd, yyyy" \h', + r'DATE \@ "M/d/yyyy"', + r'DATE \@ "dddd, MMMM dd, yyyy"', + r'DATE \@ "MMMM d, yyyy"', + r'DATE \@ "M/d/yy"', + r'DATE \@ "yyyy-MM-dd"', + r'DATE \@ "d-MMM-yy"', + r'DATE \@ "M.d.yyyy"', + r'DATE \@ "MMM. d, yy"', + r'DATE \@ "d MMMM yyyy"', + r'DATE \@ "MMMM yy"', + r'DATE \@ "MMM-yy"', + r'DATE \@ "M/d/yyyy h:mm am/pm"', + r'DATE \@ "M/d/yyyy h:mm:ss am/pm"', + r'DATE \@ "h:mm am/pm"', + r'DATE \@ "h:mm:ss am/pm"', + r'DATE \@ "HH:mm"', + r'DATE \@ "\'Today is \'HH:mm:ss"', + r'USERNAME "mary smith" \* Caps', + r'USERNAME "mary smith" \* FirstCap', + r'USERNAME "Mary Smith" \* Lower', + r'USERNAME "Mary Smith" \* Upper', + r'DATE \* CHARFORMAT', + r'TIME \@ "HH:mm:ss" \* MERGEFORMAT', + r'ADVANCE \u 6', + r'ADVANCE \d 12', + r'ADVANCE \l 20', + r'ADVANCE \x 150', + r'AUTHOR', + r'AUTHOR "Tony Caruso"', + r'BIBLIOGRAPHY \l 1033', # note: the original example has "/l 1033" + r'CITATION Ecma01 \l 1033', # note: this also. Hope this is just a typo + r'COMMENTS', + r'COMMENTS "I came, I saw, I was not impressed."', + r'CREATEDATE', + r'CREATEDATE \@ "dddd, MMMM dd, yyyy HH:mm:ss"', + r'CREATEDATE \@ "dddd, MMMM dd, yyyy HH:mm:ss" \h', + r'CREATEDATE \@ "dddd, MMMM dd, yyyy HH:mm:ss" \s', + r'DATE', + r'DATE \@ "dddd, MMMM dd, yyyy HH:mm:ss"', + r'DATE \@ "dddd, MMMM dd, yyyy HH:mm:ss" \h', + r'DATE \@ "dddd, MMMM dd, yyyy HH:mm:ss" \s', + r'EDITTIME', + r'EDITTIME \* OrdText', + r'FILENAME \* Upper', + r'FILENAME \p', + r'FILESIZE \# #,##0', + r'FILESIZE \k', + r'FILESIZE \m', + r'FORMCHECKBOX', + r'FORMDROPDOWN', + r'FORMTEXT', + r'INDEX \c "1" \e "tab" \g " to " \h "A" \z "1033"', + r'KEYWORDS', + r'KEYWORDS "field, formatting, switch, syntax"', + r'LASTSAVEDBY \* Upper', + r'LISTNUM NumberDefault \l 3 \s 1', + r'LISTNUM', + r'LISTNUM NumberDefault', + r'LISTNUM NumberDefault \s 3', + r'LISTNUM NumberDefault \l 1', + r'LISTNUM NumberDefault \l 1 \s 1', + r'LISTNUM LegalDefault \l 1 \s 1', # note: original example uses '\1' + r'NOTEREF F10', + r'NUMCHARS', + r'NUMCHARS \# #,##0', + r'NUMPAGES \# #,##0', + r'NUMPAGES \* OrdText', + r'NUMWORDS', + r'NUMWORDS \# #,##0', + r'PAGE', + r'PAGE \* ArabicDash', + r'PAGE \* ALPHABETIC', + r'PAGE \* roman', + r'PAGEREF Worldpop1990 \p', + r'PRINTDATE', + r'PRINTDATE \@ "dddd, MMMM dd, yyyy HH:mm:ss"', + r'REVNUM', + r'SAVEDATE', + r'SAVEDATE \@ "dddd, MMMM dd, yyyy HH:mm:ss"', + r'SECTION', + r'SECTION \* ArabicDash', + r'SECTION \* ALPHABETIC', + r'SECTION \* roman', + r'SECTIONPAGES', + r'SECTIONPAGES \* ArabicDash', + r'SECTIONPAGES \* ALPHABETIC', + r'SECTIONPAGES \* roman', + r'SEQ Figure', + r'SEQ Figure \* roman', + r'SEQ Figure \n', + r'SEQ Figure \c', + r'SEQ Figure \h', + r'SEQ Figure', + r'SEQ Figure \r 1', + r'SEQ Figure', + r'STYLEREF "Heading 3"', + r'STYLEREF "Last Name"', + r'STYLEREF "Last Name" \l', + r'SUBJECT', + r'SUBJECT "A specification for WordprocessingML Fields"', + r'SYMBOL 65', + r'SYMBOL 66 \a', + r'SYMBOL 67 \u', + r'SYMBOL 0x20ac \u', + r'SYMBOL 68', + r'SYMBOL 68 \f Symbol', + r'SYMBOL 40 \f Wingdings \s 24', + r'TA \l "Hotels v. Leisure Time" \c 2', + r'TA \l "Baldwin v. Alberti, 58 Wn. 2d 243 (1961)" \s "Baldwin v. Alberti"' + r'\c 1 \b', + r'INDEX \e "tab" \c "1" \z "1033"', + r'TEMPLATE \* Upper', + r'TEMPLATE \p', + r'TIME', + r'TIME \@ "dddd, MMMM dd, yyyy HH:mm:ss"', + r'TITLE "My Life, the Fantasy" \* Upper', + r'TITLE', + r'TOC \o "3-3" \h \z \t "Heading 1,1,Heading 2,2,Appendix 1,1,' + r'Appendix 2,2,Unnumbered Heading,1"', + r'USERADDRESS', + r'USERADDRESS "10 Top Secret Lane, Chiswick" \* Upper', + r'USERINITIALS \* Lower', + r'USERINITIALS "JaJ"', + r'USERINITIALS "jaj" \* Upper', + r'XE "Office Open XML" \b', + r'XE "syntax" \f "Introduction"', + r'XE "behavior:implementation-defined" \b', + r'XE "Office Open XML" \i', + r'XE "behavior:implementation-defined:documenting" \b', + r'XE "grammar" \f "Introduction" \b', + r'XE "Office Open XML"', + r'XE "item: package-relationship" \t "See package-relationship item"', + r'XE "XML" \r OOXMLPageRange', + r'XE "grammar" \f "Introduction"', + r'XE "production" \f "Introduction"' + ) + +# not (yet) covered +# (because it should be handled as bad or because our parser does not cover it) +EXAMPLES_NOMATCH = ( + r'INCLUDETEXT "E:\\ReadMe.txt"', + r'IF DATE \@ "M-d"<>"1-1" "not " new year\'s day.', + r'=X + Y', + r'=Result * 10', + r'=((-1 + X^2) * 3 - Y)/2', + r'=COUNT(BELOW)', + r'=SUM(LEFT)', + r'=AVERAGE(ABOVE)', + r'=4+5 \# 00.00', + r'=9+6 \# $###', + r'=111053+111439 \# x##', + r'=1/8 \# 0.00x', + r'=3/4 \# .x', + r'=95.4 \# $###.00', + r'=2456800 \# $#,###,###', + r'=80-90 \# -##', + r'=90-80 \# -##', + r'=90-80 \# +##', + r'=33 \# ##%', + r'=Price*15% \# "##0.00 \'is the sales tax\'"', + r'=SUM(A1:D4) \# "##0.00 \'is the total of Table\' `table`"', + r'=Sales95 \# $#,##0.00;-$#,##0.00', + r'=Sales95 \# $#,##0.00;-$#,##0.00;$0', + r'1 \* AIUEO', + r'=54 \* ALPHABETIC', + r'=52 \* alphabetic', + r'AUTOTEXT "- PAGE -"', + r'AUTOTEXT "Yours truly,"', + r'AUTOTEXT Confidential', + r'AUTOTEXTLIST "List of salutations" \s Salutation ' + r'\t "Choose a salutation"', + r'ADDRESSBLOCK \f "<<_TITLE0_ >><<_FIRST0_>><< _LAST0_>><< _SUFFIX0_>>\n' + r'<<_COMPANY_>>\n<<_STREET1_>>\n' + r'<<_STREET2_>>\n' + r'<<_CITY_>><<, _STATE_>><< _POSTAL_>><<_COUNTRY_>>"', + r'ASK AskResponse "What is your first name?"', + r'REF AskResponse', + r'{ IF { = OR ( { COMPARE { MERGEFIELD CustomerNumber } >= 4 },', + r'{ COMPARE { MERGEFIELD CustomerRating } <= 9 } ) } = 1 ' + r'"Credit not acceptable" "Credit acceptable"}', + r'{ COMPARE "{ MERGEFIELD PostalCode }" = "985*" }', + r'{ DATABASE \d "C:\\Data\\Sales93.mdb" \c "DSN=MS Access Database;', + r'DBQ=C:\\Data\\Sales93.mdb; FIL=RedISAM" ' + r'\s "select * from \"Customer List\"" \f "2445" \t "2486" \l "2"', + r' FILLIN "Please enter the appointment time for ' + r'MERGEFIELD PatientName :"', + r'GOTOBUTTON MyBookmark Dest', + r'GOTOBUTTON p3 Page', + r'GOTOBUTTON "f 2" Footnote', + r'HYPERLINK http://www.example.com/', + r'HYPERLINK "E:\\ReadMe.txt"', + r'{IF order >= 100 "Thanks" "The minimum order is 100 units" }', + r'INCLUDEPICTURE "file:///g:/photos/Ellen%20in%20Oslo.jpg"', + r'INCLUDETEXT "file:///C:/Winword/Port Development RFP" Summary', + r'INCLUDETEXT "file:///C:/Resume.xml" \n xmlns:a=\"resume-schema\" ' + r'\t "file:///C:/display.xsl" \x a:Resume/a:Name', + r'{ LINK Excel.Sheet.8 "C:\\My Documents\\Profits.xls"', + r'"Sheet1!R1C1:R4C4" \a \p }', + r'MERGEFIELD CoutesyTitle \f " "', + r'MERGEFIELD FirstName \f " "', + r'MERGEFIELD LastName', + r'= { PRINTDATE \@ "MMddyyyyHHmm" + MERGEREC }', + r'MERGEFIELD Name MERGEFIELD Phone', + r'NEXT MERGEFIELD Name MERGEFIELD Phone', + r'NEXT MERGEFIELD Name MERGEFIELD Phone', + r' QUOTE IF DATE \@ "M" = 1 "12" "= DATE \@ "M" - 1"/1/2000 \@', + r'"MMMM"', + r'RD C:\\Manual\\Chapters\\Chapter1.doc', + r'REF _Ref116788778 \r \h', + r'SET EnteredBy "Paul Smith"', + r'SET UnitCost 25.00', + r'SET Quantity FILLIN "Enter number of items ordered:"', + r'SET SalesTax 10%', + r'SET TotalCost = (UnitCost * Quantity) + ((UnitCost * Quantity) * ' + r'SalesTax)', + r'SKIPIF MERGEFIELD Order < 100', + ) + +class TestBlacklist(unittest.TestCase): + """ Tests msodde blacklist feature """ + + def test_matches(self): + """ check a long list of examples that should match the blacklist """ + for example in EXAMPLES_MATCH: + self.assertTrue(field_is_blacklisted(example), + msg="Failed to match: '{0}'".format(example)) + + def test_nomatches(self): + """ check a long list of examples that should match the blacklist """ + for example in EXAMPLES_NOMATCH: + self.assertFalse(field_is_blacklisted(example), + msg="Accidentally matched: '{0}'".format(example)) + + +# just in case somebody calls this file as a script +if __name__ == '__main__': + unittest.main() diff --git a/tests/msodde_doc/__init__.py b/tests/msodde_doc/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/tests/msodde_doc/__init__.py +++ /dev/null diff --git a/tests/msodde_doc/test_basic.py b/tests/msodde_doc/test_basic.py deleted file mode 100644 index 33da7dd..0000000 --- a/tests/msodde_doc/test_basic.py +++ /dev/null @@ -1,121 +0,0 @@ -""" Test some basic behaviour of msodde.py - -Ensure that -- doc and docx are read without error -- garbage returns error return status -- dde-links are found where appropriate -""" - -from __future__ import print_function - -import unittest -from oletools import msodde -from tests.test_utils import OutputCapture, DATA_BASE_DIR as BASE_DIR -import shlex -from os.path import join -from traceback import print_exc - - -class TestReturnCode(unittest.TestCase): - - def test_valid_doc(self): - """ check that a valid doc file leads to 0 exit status """ - for filename in ('dde-test-from-office2003', 'dde-test-from-office2016', - 'harmless-clean', 'dde-test-from-office2013-utf_16le-korean'): - self.do_test_validity(join(BASE_DIR, 'msodde-doc', - filename + '.doc')) - - def test_valid_docx(self): - """ check that a valid docx file leads to 0 exit status """ - for filename in 'dde-test', 'harmless-clean': - self.do_test_validity(join(BASE_DIR, 'msodde-doc', - filename + '.docx')) - - def test_valid_docm(self): - """ check that a valid docm file leads to 0 exit status """ - for filename in 'dde-test', 'harmless-clean': - self.do_test_validity(join(BASE_DIR, 'msodde-doc', - filename + '.docm')) - - def test_invalid_other(self): - """ check that xml do not work yet """ - for extn in '-2003.xml', '.xml': - self.do_test_validity(join(BASE_DIR, 'msodde-doc', - 'harmless-clean' + extn), True) - - def test_invalid_none(self): - """ check that no file argument leads to non-zero exit status """ - self.do_test_validity('', True) - - def test_invalid_empty(self): - """ check that empty file argument leads to non-zero exit status """ - self.do_test_validity(join(BASE_DIR, 'basic/empty'), True) - - def test_invalid_text(self): - """ check that text file argument leads to non-zero exit status """ - self.do_test_validity(join(BASE_DIR, 'basic/text'), True) - - def do_test_validity(self, args, expect_error=False): - """ helper for test_valid_doc[x] """ - args = shlex.split(args) - return_code = -1 - have_exception = False - try: - return_code = msodde.main(args) - except Exception: - have_exception = True - print_exc() - except SystemExit as se: # sys.exit() was called - return_code = se.code - if se.code is None: - return_code = 0 - - self.assertEqual(expect_error, have_exception or (return_code != 0), - msg='Args={0}, expect={1}, exc={2}, return={3}' - .format(args, expect_error, have_exception, - return_code)) - - -class TestDdeInDoc(unittest.TestCase): - - def get_dde_from_output(self, capturer): - """ helper to read dde links from captured output """ - have_start_line = False - result = [] - for line in capturer: - if not line.strip(): - continue # skip empty lines - if have_start_line: - result.append(line) - elif line == 'DDE Links:': - have_start_line = True - - self.assertTrue(have_start_line) # ensure output was complete - return result - - def test_with_dde(self): - """ check that dde links appear on stdout """ - with OutputCapture() as capturer: - msodde.main([join(BASE_DIR, 'msodde-doc', - 'dde-test-from-office2003.doc')]) - self.assertNotEqual(len(self.get_dde_from_output(capturer)), 0, - msg='Found no dde links in output for doc file') - - def test_no_dde(self): - """ check that no dde links appear on stdout """ - with OutputCapture() as capturer: - msodde.main([join(BASE_DIR, 'msodde-doc', 'harmless-clean.doc')]) - self.assertEqual(len(self.get_dde_from_output(capturer)), 0, - msg='Found dde links in output for doc file') - - def test_with_dde_utf16le(self): - """ check that dde links appear on stdout """ - with OutputCapture() as capturer: - msodde.main([join(BASE_DIR, 'msodde-doc', - 'dde-test-from-office2013-utf_16le-korean.doc')]) - self.assertNotEqual(len(self.get_dde_from_output(capturer)), 0, - msg='Found no dde links in output for doc file') - - -if __name__ == '__main__': - unittest.main() diff --git a/tests/msodde_docx/__init__.py b/tests/msodde_docx/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/tests/msodde_docx/__init__.py +++ /dev/null diff --git a/tests/msodde_docx/test_blacklist.py b/tests/msodde_docx/test_blacklist.py deleted file mode 100644 index babea81..0000000 --- a/tests/msodde_docx/test_blacklist.py +++ /dev/null @@ -1,249 +0,0 @@ -""" Test the msodde blacklist feature - -Take a few examples from the standard (iso29500-1:2016) and see that they match -""" - -import unittest -from oletools.msodde import field_is_blacklisted - -EXAMPLES_MATCH = ( - r'DATE', - r'DATE \@ "dddd, MMMM dd, yyyy"', - r'DATE \@ "dddd, MMMM dd, yyyy" \h', - r'DATE \@ "M/d/yyyy"', - r'DATE \@ "dddd, MMMM dd, yyyy"', - r'DATE \@ "MMMM d, yyyy"', - r'DATE \@ "M/d/yy"', - r'DATE \@ "yyyy-MM-dd"', - r'DATE \@ "d-MMM-yy"', - r'DATE \@ "M.d.yyyy"', - r'DATE \@ "MMM. d, yy"', - r'DATE \@ "d MMMM yyyy"', - r'DATE \@ "MMMM yy"', - r'DATE \@ "MMM-yy"', - r'DATE \@ "M/d/yyyy h:mm am/pm"', - r'DATE \@ "M/d/yyyy h:mm:ss am/pm"', - r'DATE \@ "h:mm am/pm"', - r'DATE \@ "h:mm:ss am/pm"', - r'DATE \@ "HH:mm"', - r'DATE \@ "\'Today is \'HH:mm:ss"', - r'USERNAME "mary smith" \* Caps', - r'USERNAME "mary smith" \* FirstCap', - r'USERNAME "Mary Smith" \* Lower', - r'USERNAME "Mary Smith" \* Upper', - r'DATE \* CHARFORMAT', - r'TIME \@ "HH:mm:ss" \* MERGEFORMAT', - r'ADVANCE \u 6', - r'ADVANCE \d 12', - r'ADVANCE \l 20', - r'ADVANCE \x 150', - r'AUTHOR', - r'AUTHOR "Tony Caruso"', - r'BIBLIOGRAPHY \l 1033', # note: the original example has "/l 1033" - r'CITATION Ecma01 \l 1033', # note: this also. Hope this is just a typo - r'COMMENTS', - r'COMMENTS "I came, I saw, I was not impressed."', - r'CREATEDATE', - r'CREATEDATE \@ "dddd, MMMM dd, yyyy HH:mm:ss"', - r'CREATEDATE \@ "dddd, MMMM dd, yyyy HH:mm:ss" \h', - r'CREATEDATE \@ "dddd, MMMM dd, yyyy HH:mm:ss" \s', - r'DATE', - r'DATE \@ "dddd, MMMM dd, yyyy HH:mm:ss"', - r'DATE \@ "dddd, MMMM dd, yyyy HH:mm:ss" \h', - r'DATE \@ "dddd, MMMM dd, yyyy HH:mm:ss" \s', - r'EDITTIME', - r'EDITTIME \* OrdText', - r'FILENAME \* Upper', - r'FILENAME \p', - r'FILESIZE \# #,##0', - r'FILESIZE \k', - r'FILESIZE \m', - r'FORMCHECKBOX', - r'FORMDROPDOWN', - r'FORMTEXT', - r'INDEX \c "1" \e "tab" \g " to " \h "A" \z "1033"', - r'KEYWORDS', - r'KEYWORDS "field, formatting, switch, syntax"', - r'LASTSAVEDBY \* Upper', - r'LISTNUM NumberDefault \l 3 \s 1', - r'LISTNUM', - r'LISTNUM NumberDefault', - r'LISTNUM NumberDefault \s 3', - r'LISTNUM NumberDefault \l 1', - r'LISTNUM NumberDefault \l 1 \s 1', - r'LISTNUM LegalDefault \l 1 \s 1', # note: original example uses '\1' - r'NOTEREF F10', - r'NUMCHARS', - r'NUMCHARS \# #,##0', - r'NUMPAGES \# #,##0', - r'NUMPAGES \* OrdText', - r'NUMWORDS', - r'NUMWORDS \# #,##0', - r'PAGE', - r'PAGE \* ArabicDash', - r'PAGE \* ALPHABETIC', - r'PAGE \* roman', - r'PAGEREF Worldpop1990 \p', - r'PRINTDATE', - r'PRINTDATE \@ "dddd, MMMM dd, yyyy HH:mm:ss"', - r'REVNUM', - r'SAVEDATE', - r'SAVEDATE \@ "dddd, MMMM dd, yyyy HH:mm:ss"', - r'SECTION', - r'SECTION \* ArabicDash', - r'SECTION \* ALPHABETIC', - r'SECTION \* roman', - r'SECTIONPAGES', - r'SECTIONPAGES \* ArabicDash', - r'SECTIONPAGES \* ALPHABETIC', - r'SECTIONPAGES \* roman', - r'SEQ Figure', - r'SEQ Figure \* roman', - r'SEQ Figure \n', - r'SEQ Figure \c', - r'SEQ Figure \h', - r'SEQ Figure', - r'SEQ Figure \r 1', - r'SEQ Figure', - r'STYLEREF "Heading 3"', - r'STYLEREF "Last Name"', - r'STYLEREF "Last Name" \l', - r'SUBJECT', - r'SUBJECT "A specification for WordprocessingML Fields"', - r'SYMBOL 65', - r'SYMBOL 66 \a', - r'SYMBOL 67 \u', - r'SYMBOL 0x20ac \u', - r'SYMBOL 68', - r'SYMBOL 68 \f Symbol', - r'SYMBOL 40 \f Wingdings \s 24', - r'TA \l "Hotels v. Leisure Time" \c 2', - r'TA \l "Baldwin v. Alberti, 58 Wn. 2d 243 (1961)" \s "Baldwin v. Alberti"' - r'\c 1 \b', - r'INDEX \e "tab" \c "1" \z "1033"', - r'TEMPLATE \* Upper', - r'TEMPLATE \p', - r'TIME', - r'TIME \@ "dddd, MMMM dd, yyyy HH:mm:ss"', - r'TITLE "My Life, the Fantasy" \* Upper', - r'TITLE', - r'TOC \o "3-3" \h \z \t "Heading 1,1,Heading 2,2,Appendix 1,1,' - r'Appendix 2,2,Unnumbered Heading,1"', - r'USERADDRESS', - r'USERADDRESS "10 Top Secret Lane, Chiswick" \* Upper', - r'USERINITIALS \* Lower', - r'USERINITIALS "JaJ"', - r'USERINITIALS "jaj" \* Upper', - r'XE "Office Open XML" \b', - r'XE "syntax" \f "Introduction"', - r'XE "behavior:implementation-defined" \b', - r'XE "Office Open XML" \i', - r'XE "behavior:implementation-defined:documenting" \b', - r'XE "grammar" \f "Introduction" \b', - r'XE "Office Open XML"', - r'XE "item: package-relationship" \t "See package-relationship item"', - r'XE "XML" \r OOXMLPageRange', - r'XE "grammar" \f "Introduction"', - r'XE "production" \f "Introduction"' - ) - -# not (yet) covered -# (because it should be handled as bad or because our parser does not cover it) -EXAMPLES_NOMATCH = ( - r'INCLUDETEXT "E:\\ReadMe.txt"', - r'IF DATE \@ "M-d"<>"1-1" "not " new year\'s day.', - r'=X + Y', - r'=Result * 10', - r'=((-1 + X^2) * 3 - Y)/2', - r'=COUNT(BELOW)', - r'=SUM(LEFT)', - r'=AVERAGE(ABOVE)', - r'=4+5 \# 00.00', - r'=9+6 \# $###', - r'=111053+111439 \# x##', - r'=1/8 \# 0.00x', - r'=3/4 \# .x', - r'=95.4 \# $###.00', - r'=2456800 \# $#,###,###', - r'=80-90 \# -##', - r'=90-80 \# -##', - r'=90-80 \# +##', - r'=33 \# ##%', - r'=Price*15% \# "##0.00 \'is the sales tax\'"', - r'=SUM(A1:D4) \# "##0.00 \'is the total of Table\' `table`"', - r'=Sales95 \# $#,##0.00;-$#,##0.00', - r'=Sales95 \# $#,##0.00;-$#,##0.00;$0', - r'1 \* AIUEO', - r'=54 \* ALPHABETIC', - r'=52 \* alphabetic', - r'AUTOTEXT "- PAGE -"', - r'AUTOTEXT "Yours truly,"', - r'AUTOTEXT Confidential', - r'AUTOTEXTLIST "List of salutations" \s Salutation ' - r'\t "Choose a salutation"', - r'ADDRESSBLOCK \f "<<_TITLE0_ >><<_FIRST0_>><< _LAST0_>><< _SUFFIX0_>>\n' - r'<<_COMPANY_>>\n<<_STREET1_>>\n' - r'<<_STREET2_>>\n' - r'<<_CITY_>><<, _STATE_>><< _POSTAL_>><<_COUNTRY_>>"', - r'ASK AskResponse "What is your first name?"', - r'REF AskResponse', - r'{ IF { = OR ( { COMPARE { MERGEFIELD CustomerNumber } >= 4 },', - r'{ COMPARE { MERGEFIELD CustomerRating } <= 9 } ) } = 1 ' - r'"Credit not acceptable" "Credit acceptable"}', - r'{ COMPARE "{ MERGEFIELD PostalCode }" = "985*" }', - r'{ DATABASE \d "C:\\Data\\Sales93.mdb" \c "DSN=MS Access Database;', - r'DBQ=C:\\Data\\Sales93.mdb; FIL=RedISAM" ' - r'\s "select * from \"Customer List\"" \f "2445" \t "2486" \l "2"', - r' FILLIN "Please enter the appointment time for ' - r'MERGEFIELD PatientName :"', - r'GOTOBUTTON MyBookmark Dest', - r'GOTOBUTTON p3 Page', - r'GOTOBUTTON "f 2" Footnote', - r'HYPERLINK http://www.example.com/', - r'HYPERLINK "E:\\ReadMe.txt"', - r'{IF order >= 100 "Thanks" "The minimum order is 100 units" }', - r'INCLUDEPICTURE "file:///g:/photos/Ellen%20in%20Oslo.jpg"', - r'INCLUDETEXT "file:///C:/Winword/Port Development RFP" Summary', - r'INCLUDETEXT "file:///C:/Resume.xml" \n xmlns:a=\"resume-schema\" ' - r'\t "file:///C:/display.xsl" \x a:Resume/a:Name', - r'{ LINK Excel.Sheet.8 "C:\\My Documents\\Profits.xls"', - r'"Sheet1!R1C1:R4C4" \a \p }', - r'MERGEFIELD CoutesyTitle \f " "', - r'MERGEFIELD FirstName \f " "', - r'MERGEFIELD LastName', - r'= { PRINTDATE \@ "MMddyyyyHHmm" + MERGEREC }', - r'MERGEFIELD Name MERGEFIELD Phone', - r'NEXT MERGEFIELD Name MERGEFIELD Phone', - r'NEXT MERGEFIELD Name MERGEFIELD Phone', - r' QUOTE IF DATE \@ "M" = 1 "12" "= DATE \@ "M" - 1"/1/2000 \@', - r'"MMMM"', - r'RD C:\\Manual\\Chapters\\Chapter1.doc', - r'REF _Ref116788778 \r \h', - r'SET EnteredBy "Paul Smith"', - r'SET UnitCost 25.00', - r'SET Quantity FILLIN "Enter number of items ordered:"', - r'SET SalesTax 10%', - r'SET TotalCost = (UnitCost * Quantity) + ((UnitCost * Quantity) * ' - r'SalesTax)', - r'SKIPIF MERGEFIELD Order < 100', - ) - -class TestBlacklist(unittest.TestCase): - """ Tests msodde blacklist feature """ - - def test_matches(self): - """ check a long list of examples that should match the blacklist """ - for example in EXAMPLES_MATCH: - self.assertTrue(field_is_blacklisted(example), - msg="Failed to match: '{0}'".format(example)) - - def test_nomatches(self): - """ check a long list of examples that should match the blacklist """ - for example in EXAMPLES_NOMATCH: - self.assertFalse(field_is_blacklisted(example), - msg="Accidentally matched: '{0}'".format(example)) - - -# just in case somebody calls this file as a script -if __name__ == '__main__': - unittest.main() diff --git a/tests/test-data/msodde-doc/dde-test-from-office2003.doc b/tests/test-data/msodde-doc/dde-test-from-office2003.doc deleted file mode 100644 index da5562c..0000000 Binary files a/tests/test-data/msodde-doc/dde-test-from-office2003.doc and /dev/null differ diff --git a/tests/test-data/msodde-doc/dde-test-from-office2013-utf_16le-korean.doc b/tests/test-data/msodde-doc/dde-test-from-office2013-utf_16le-korean.doc deleted file mode 100644 index 6d0bec8..0000000 Binary files a/tests/test-data/msodde-doc/dde-test-from-office2013-utf_16le-korean.doc and /dev/null differ diff --git a/tests/test-data/msodde-doc/dde-test-from-office2016.doc b/tests/test-data/msodde-doc/dde-test-from-office2016.doc deleted file mode 100644 index 563de19..0000000 Binary files a/tests/test-data/msodde-doc/dde-test-from-office2016.doc and /dev/null differ diff --git a/tests/test-data/msodde-doc/dde-test.docm b/tests/test-data/msodde-doc/dde-test.docm deleted file mode 100644 index ee5362a..0000000 Binary files a/tests/test-data/msodde-doc/dde-test.docm and /dev/null differ diff --git a/tests/test-data/msodde-doc/dde-test.docx b/tests/test-data/msodde-doc/dde-test.docx deleted file mode 100644 index 5fba6b2..0000000 Binary files a/tests/test-data/msodde-doc/dde-test.docx and /dev/null differ diff --git a/tests/test-data/msodde-doc/harmless-clean-2003.xml b/tests/test-data/msodde-doc/harmless-clean-2003.xml deleted file mode 100644 index 477069f..0000000 --- a/tests/test-data/msodde-doc/harmless-clean-2003.xml +++ /dev/null @@ -1,3 +0,0 @@ - - -useruser202017-10-26T09:10:00Z2017-10-26T09:10:00Z1392502128816TestThis is a harmless test document.It contains neither macros nor dde links nor embedded viruses nor links to evil web pages. Not even a single insult. Boring!Just to make things slightly interesting, however, we add some ünicöde-ßtringß and different text sizes, colors and fonts \ No newline at end of file diff --git a/tests/test-data/msodde-doc/harmless-clean.doc b/tests/test-data/msodde-doc/harmless-clean.doc deleted file mode 100644 index 38fcf72..0000000 Binary files a/tests/test-data/msodde-doc/harmless-clean.doc and /dev/null differ diff --git a/tests/test-data/msodde-doc/harmless-clean.docm b/tests/test-data/msodde-doc/harmless-clean.docm deleted file mode 100644 index f234cae..0000000 Binary files a/tests/test-data/msodde-doc/harmless-clean.docm and /dev/null differ diff --git a/tests/test-data/msodde-doc/harmless-clean.docx b/tests/test-data/msodde-doc/harmless-clean.docx deleted file mode 100644 index 59099f3..0000000 Binary files a/tests/test-data/msodde-doc/harmless-clean.docx and /dev/null differ diff --git a/tests/test-data/msodde-doc/harmless-clean.xml b/tests/test-data/msodde-doc/harmless-clean.xml deleted file mode 100644 index cd1e53c..0000000 --- a/tests/test-data/msodde-doc/harmless-clean.xml +++ /dev/null @@ -1,3 +0,0 @@ - - -TestThis is a harmless test document.It contains neither macros nor dde links nor embedded viruses nor links to evil web pages. Not even a single insult. Boring!Just to make things slightly interesting, however, we add some ünicöde-ßtringß and different text sizes, colors and fonts0139250Microsoft Office Word021falseTitel1false288falsefalse16.0000useruser22017-10-26T09:10:00Z2017-10-26T09:10:00Z \ No newline at end of file diff --git a/tests/test-data/msodde/dde-test-from-office2003.doc b/tests/test-data/msodde/dde-test-from-office2003.doc new file mode 100644 index 0000000..da5562c Binary files /dev/null and b/tests/test-data/msodde/dde-test-from-office2003.doc differ diff --git a/tests/test-data/msodde/dde-test-from-office2013-utf_16le-korean.doc b/tests/test-data/msodde/dde-test-from-office2013-utf_16le-korean.doc new file mode 100644 index 0000000..6d0bec8 Binary files /dev/null and b/tests/test-data/msodde/dde-test-from-office2013-utf_16le-korean.doc differ diff --git a/tests/test-data/msodde/dde-test-from-office2016.doc b/tests/test-data/msodde/dde-test-from-office2016.doc new file mode 100644 index 0000000..563de19 Binary files /dev/null and b/tests/test-data/msodde/dde-test-from-office2016.doc differ diff --git a/tests/test-data/msodde/dde-test.docm b/tests/test-data/msodde/dde-test.docm new file mode 100644 index 0000000..ee5362a Binary files /dev/null and b/tests/test-data/msodde/dde-test.docm differ diff --git a/tests/test-data/msodde/dde-test.docx b/tests/test-data/msodde/dde-test.docx new file mode 100644 index 0000000..5fba6b2 Binary files /dev/null and b/tests/test-data/msodde/dde-test.docx differ diff --git a/tests/test-data/msodde/harmless-clean-2003.xml b/tests/test-data/msodde/harmless-clean-2003.xml new file mode 100644 index 0000000..477069f --- /dev/null +++ b/tests/test-data/msodde/harmless-clean-2003.xml @@ -0,0 +1,3 @@ + + +useruser202017-10-26T09:10:00Z2017-10-26T09:10:00Z1392502128816TestThis is a harmless test document.It contains neither macros nor dde links nor embedded viruses nor links to evil web pages. Not even a single insult. Boring!Just to make things slightly interesting, however, we add some ünicöde-ßtringß and different text sizes, colors and fonts \ No newline at end of file diff --git a/tests/test-data/msodde/harmless-clean.doc b/tests/test-data/msodde/harmless-clean.doc new file mode 100644 index 0000000..38fcf72 Binary files /dev/null and b/tests/test-data/msodde/harmless-clean.doc differ diff --git a/tests/test-data/msodde/harmless-clean.docm b/tests/test-data/msodde/harmless-clean.docm new file mode 100644 index 0000000..f234cae Binary files /dev/null and b/tests/test-data/msodde/harmless-clean.docm differ diff --git a/tests/test-data/msodde/harmless-clean.docx b/tests/test-data/msodde/harmless-clean.docx new file mode 100644 index 0000000..59099f3 Binary files /dev/null and b/tests/test-data/msodde/harmless-clean.docx differ diff --git a/tests/test-data/msodde/harmless-clean.xml b/tests/test-data/msodde/harmless-clean.xml new file mode 100644 index 0000000..cd1e53c --- /dev/null +++ b/tests/test-data/msodde/harmless-clean.xml @@ -0,0 +1,3 @@ + + +TestThis is a harmless test document.It contains neither macros nor dde links nor embedded viruses nor links to evil web pages. Not even a single insult. Boring!Just to make things slightly interesting, however, we add some ünicöde-ßtringß and different text sizes, colors and fonts0139250Microsoft Office Word021falseTitel1false288falsefalse16.0000useruser22017-10-26T09:10:00Z2017-10-26T09:10:00Z \ No newline at end of file -- libgit2 0.21.4