Commit f57c9494 by fwkz

Adding string representation of Exploit()

parent ae5d4eaa
......@@ -2,6 +2,7 @@ from weakref import WeakKeyDictionary
from itertools import chain
import threading
import time
import os
from routersploit.utils import print_status, NonStringIterable
......@@ -117,3 +118,7 @@ class Exploit(object):
for worker in workers:
worker.join()
print_status('Elapsed time: ', time.time() - start, 'seconds')
def __str__(self):
return self.__module__.split('.', 2).pop().replace('.', os.sep)
import unittest
import os
try:
import unittest.mock as mock
except ImportError:
import mock
from routersploit.test import RoutersploitTestCase
from routersploit.exploits import Exploit, Option, GLOBAL_OPTS
......@@ -78,6 +84,11 @@ class OptionTest(RoutersploitTestCase):
GLOBAL_OPTS['doo'] = 'global_doo'
self.assertEqual(self.exploit_with_validators.doo, 'global_doo_suffix')
def test_str_representation(self):
with mock.patch.object(TestExploitFoo, "__module__", new_callable=mock.PropertyMock) as mock_module:
mock_module.return_value = "routersploit.modules.exploits.foo.bar"
self.assertEqual(str(TestExploitFoo()), os.path.join('exploits', 'foo', 'bar'))
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment