Commit 090b55e0 by fwkz

Adding tests for 'exploit' and 'widgets' module.

parent 3862604e
from __future__ import print_function
from __future__ import absolute_import
try:
import unittest.mock as mock
except ImportError:
import mock
from . import RoutersploitTestCase
from ..exploits import Exploit, Option
def suffix(x):
return "{}_suffix".format(x)
def SUFFIX(x):
return "{}_SUFFIX".format(x)
class TestExploitFoo(Exploit):
doo = Option(default=1, description="description_one")
paa = Option(default=2, description="description_two")
class TestExploitBar(Exploit):
doo = Option(default=3, description="description_three")
paa = Option(default=4, description="description_four")
class TestExploitWithWidgets(Exploit):
doo = Option(default="default_value", description="description_three", widgets=suffix)
paa = Option(default="default_value", description="description_three", widgets=(suffix, SUFFIX))
class OptionTest(RoutersploitTestCase):
def setUp(self):
self.exploit_foo = TestExploitFoo()
self.exploit_bar = TestExploitBar()
self.exploit_with_widgets = TestExploitWithWidgets()
def test_default_value(self):
""" Test if default value is properly set. """
self.assertEqual(self.exploit_foo.doo, 1)
self.assertEqual(self.exploit_foo.paa, 2)
self.assertEqual(self.exploit_bar.doo, 3)
self.assertEqual(self.exploit_bar.paa, 4)
def test_set_value(self):
""" Test if descriptors are properly set. """
self.exploit_foo.doo = "doopaa"
self.exploit_foo.paa = "kajak"
self.assertEqual(self.exploit_foo.doo, "doopaa")
self.assertEqual(self.exploit_foo.paa, "kajak")
self.assertEqual(self.exploit_bar.doo, 3)
self.assertEqual(self.exploit_bar.paa, 4)
def test_if_widget_is_applied_on_default_value(self):
self.assertEqual(self.exploit_with_widgets.doo, "default_value_suffix")
def test_if_widget_is_applied_after_setting_value(self):
self.exploit_with_widgets.doo = "new_value"
self.assertEqual(self.exploit_with_widgets.doo, "new_value_suffix")
def test_if_widget_is_applied_in_specific_order(self):
self.exploit_with_widgets.paa = "new_value"
self.assertEqual(self.exploit_with_widgets.paa, "new_value_suffix_SUFFIX")
from __future__ import print_function
from __future__ import absolute_import
try:
import unittest.mock as mock
except ImportError:
import mock
from . import RoutersploitTestCase
from .. import widgets
class WidgetsTest(RoutersploitTestCase):
def test_url_adding_http_prefix(self):
self.assertEqual(widgets.url("127.0.0.1"), "http://127.0.0.1")
def test_url_already_with_http_prefix(self):
self.assertEqual(widgets.url("http://127.0.0.1"), "http://127.0.0.1")
def test_url_already_with_https_prefix(self):
self.assertEqual(widgets.url("https://127.0.0.1"), "https://127.0.0.1")
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