Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_standard_password(self):
"""Check dde-link is found in xls[mb] sample files."""
for suffix in 'xls', 'xlsx', 'xlsm', 'xlsb':
example_file = pjoin(DATA_BASE_DIR, 'encrypted',
'dde-test-encrypt-standardpassword.' + suffix)
link_text = msodde.process_maybe_encrypted(example_file)
self.assertEqual(link_text, 'cmd /c calc.exe',
msg='Unexpected output {!r} for {}'
.format(link_text, suffix))
def do_test_validity(self, filename, expect_error=None):
""" helper for test_[in]valid_* """
found_error = None
# DEBUG: print('Testing file {}'.format(filename))
try:
msodde.process_maybe_encrypted(filename,
field_filter_mode=msodde.FIELD_FILTER_BLACKLIST)
except Exception as exc:
found_error = exc
# DEBUG: print_exc()
if expect_error and not found_error:
self.fail('Expected {} but msodde finished without errors for {}'
.format(expect_error, filename))
elif not expect_error and found_error:
self.fail('Unexpected error {} from msodde for {}'
.format(found_error, filename))
elif expect_error and not isinstance(found_error, expect_error):
self.fail('Wrong kind of error {} from msodde for {}, expected {}'
.format(type(found_error), filename, expect_error))
def test_excel(self):
""" check that dde links are found in excel 2007+ files """
expect = ['cmd /c calc.exe', ]
for extn in 'xlsx', 'xlsm', 'xlsb':
output = msodde.process_maybe_encrypted(
join(BASE_DIR, 'msodde', 'dde-test.' + extn),
field_filter_mode=msodde.FIELD_FILTER_BLACKLIST)
self.assertEqual(expect, self.get_dde_from_output(output),
msg='unexpected output for dde-test.{0}: {1}'
.format(extn, output))
def test_with_dde_utf16le(self):
""" check that dde links appear on stdout """
filename = 'dde-test-from-office2013-utf_16le-korean.doc'
output = msodde.process_maybe_encrypted(
join(BASE_DIR, 'msodde', filename),
field_filter_mode=msodde.FIELD_FILTER_BLACKLIST)
self.assertNotEqual(len(self.get_dde_from_output(output)), 0,
msg='Found no dde links in output of ' + filename)
def test_clean_rtf_ddeonly(self):
""" find no dde links in rtf spec """
filename = 'RTF-Spec-1.7.rtf'
output = msodde.process_maybe_encrypted(
join(BASE_DIR, 'msodde', filename),
field_filter_mode=msodde.FIELD_FILTER_DDE)
self.assertEqual(len(self.get_dde_from_output(output)), 0,
msg='Found dde links in output of ' + filename)
def test_no_dde(self):
""" check that no dde links appear on stdout """
filename = 'harmless-clean.doc'
output = msodde.process_maybe_encrypted(
join(BASE_DIR, 'msodde', filename),
field_filter_mode=msodde.FIELD_FILTER_BLACKLIST)
self.assertEqual(len(self.get_dde_from_output(output)), 0,
msg='Found dde links in output of ' + filename)
def test_with_dde(self):
""" check that dde links appear on stdout """
filename = 'dde-test-from-office2003.doc'
output = msodde.process_maybe_encrypted(
join(BASE_DIR, 'msodde', filename),
field_filter_mode=msodde.FIELD_FILTER_BLACKLIST)
self.assertNotEqual(len(self.get_dde_from_output(output)), 0,
msg='Found no dde links in output of ' + filename)