Skip to content

Commit

Permalink
tests: Test error output from msodde
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-intra2net committed Apr 24, 2019
1 parent 2ce4c01 commit 5e1667e
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion tests/msodde/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@

import unittest
from oletools import msodde
from tests.test_utils import DATA_BASE_DIR as BASE_DIR
from tests.test_utils import SOURCE_BASE_DIR, DATA_BASE_DIR as BASE_DIR
import os
from os.path import join
from traceback import print_exc
from subprocess import check_output, CalledProcessError
import sys
import json
from collections import OrderedDict


class TestReturnCode(unittest.TestCase):
Expand Down Expand Up @@ -88,6 +92,36 @@ def do_test_validity(self, args, expect_error=False):
.format(args, expect_error, have_exception))


class TestErrorOutput(unittest.TestCase):
"""msodde does not specify error by return code but text output."""

def test_crypt_output(self):
"""Check for helpful error message when failing to decrypt."""
env = os.environ
try:
env['PYTHONPATH'] = SOURCE_BASE_DIR + os.pathsep + \
os.environ['PYTHONPATH']
except KeyError:
env['PYTHONPATH'] = SOURCE_BASE_DIR

for suffix in 'doc', 'docm', 'docx', 'ppt', 'pptm', 'pptx', 'xls', \
'xlsb', 'xlsm', 'xlsx':
example_file = join(BASE_DIR, 'encrypted', 'encrypted.' + suffix)
try:
output = check_output([sys.executable, '-m', 'msodde', '-j',
example_file],
universal_newlines=True, env=env)
self.fail('Should have returned non-zero exit code!')
except CalledProcessError as err:
output = err.output
data = json.loads(output, object_pairs_hook=OrderedDict)
# debug: json.dump(data, sys.stdout, indent=4)
self.assertTrue(all(part['type'] == 'msg' for part in data))
self.assertTrue(any(part['level'] == 'ERROR' and
'passwords could not decrypt' in part['msg']
for part in data))


class TestDdeLinks(unittest.TestCase):
""" capture output of msodde and check dde-links are found correctly """

Expand Down

0 comments on commit 5e1667e

Please sign in to comment.