Commit bd731f2d by fwkz

Renaming widgets to validators

parent f427143c
......@@ -16,5 +16,5 @@ from routersploit.utils import (
from routersploit import exploits
from routersploit import wordlists
from routersploit import widgets
from routersploit import validators
......@@ -9,11 +9,11 @@ from routersploit.utils import print_status, NonStringIterable
class Option(object):
""" Exploit attribute that is set by the end user. """
def __init__(self, default, description="", widgets=()):
if isinstance(widgets, NonStringIterable):
self.widgets = widgets
def __init__(self, default, description="", validators=()):
if isinstance(validators, NonStringIterable):
self.validators = validators
else:
self.widgets = (widgets,)
self.validators = (validators,)
self.default = self._apply_widgets(default)
self.description = description
......@@ -26,8 +26,8 @@ class Option(object):
self.data[instance] = self._apply_widgets(value)
def _apply_widgets(self, value):
for widget in self.widgets:
value = widget(value)
for validator in self.validators:
value = validator(value)
return value
......
......@@ -5,7 +5,7 @@ from routersploit import (
print_info,
http_request,
mute,
widgets,
validators,
)
......@@ -32,7 +32,7 @@ class Exploit(exploits.Exploit):
],
}
target = exploits.Option('', 'Target address e.g. http://192.168.1.1', widgets=widgets.url) # target address
target = exploits.Option('', 'Target address e.g. http://192.168.1.1', validators=validators.url) # target address
port = exploits.Option(80, 'Target port') # default port
def run(self):
......
......@@ -8,7 +8,7 @@ from routersploit import (
http_request,
random_text,
mute,
widgets,
validators,
)
......@@ -34,7 +34,7 @@ class Exploit(exploits.Exploit):
],
}
target = exploits.Option('', 'Target address e.g. http://192.168.1.1', widgets=widgets.url)
target = exploits.Option('', 'Target address e.g. http://192.168.1.1', validators=validators.url)
port = exploits.Option(80, 'Target Port')
def run(self):
......
......@@ -27,16 +27,16 @@ class TestExploitBar(Exploit):
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 TestExploitWithValidators(Exploit):
doo = Option(default="default_value", description="description_three", validators=suffix)
paa = Option(default="default_value", description="description_three", validators=(suffix, SUFFIX))
class OptionTest(RoutersploitTestCase):
def setUp(self):
self.exploit_foo = TestExploitFoo()
self.exploit_bar = TestExploitBar()
self.exploit_with_widgets = TestExploitWithWidgets()
self.exploit_with_validators = TestExploitWithValidators()
def test_default_value(self):
""" Test if default value is properly set. """
......@@ -55,16 +55,16 @@ class OptionTest(RoutersploitTestCase):
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_validator_is_applied_on_default_value(self):
self.assertEqual(self.exploit_with_validators.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_validator_is_applied_after_setting_value(self):
self.exploit_with_validators.doo = "new_value"
self.assertEqual(self.exploit_with_validators.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")
def test_if_validator_is_applied_in_specific_order(self):
self.exploit_with_validators.paa = "new_value"
self.assertEqual(self.exploit_with_validators.paa, "new_value_suffix_SUFFIX")
if __name__ == '__main__':
unittest.main()
......
......@@ -6,18 +6,18 @@ except ImportError:
import mock
from routersploit.test import RoutersploitTestCase
from routersploit import widgets
from routersploit import validators
class WidgetsTest(RoutersploitTestCase):
class ValidatorsTest(RoutersploitTestCase):
def test_url_adding_http_prefix(self):
self.assertEqual(widgets.url("127.0.0.1"), "http://127.0.0.1")
self.assertEqual(validators.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")
self.assertEqual(validators.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")
self.assertEqual(validators.url("https://127.0.0.1"), "https://127.0.0.1")
if __name__ == '__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