Commit bd731f2d by fwkz

Renaming widgets to validators

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