Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
routersploit
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
czos-dpend
routersploit
Commits
6fc8d05c
Commit
6fc8d05c
authored
May 05, 2016
by
fwkz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring implementation.
parent
4b3231ab
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
35 deletions
+23
-35
test_modules.py
routersploit/test/test_modules.py
+23
-35
No files found.
routersploit/test/test_modules.py
View file @
6fc8d05c
from
inspect
import
getmodule
from
unittest
import
main
,
TestCase
,
TestSuite
import
unittest
from
routersploit.exploits
import
Exploit
from
routersploit.utils
import
iter_modules
class
ModuleTest
(
TestCase
):
class
ModuleTest
(
unittest
.
TestCase
):
"""A test case that every module must pass.
Attributes:
...
...
@@ -13,48 +11,37 @@ class ModuleTest(TestCase):
metadata (Dict): The info associated with the module.
"""
def
test_has_exploit
(
self
):
self
.
assertIsInstance
(
self
.
module
,
Exploit
)
def
__init__
(
self
,
methodName
=
'runTest'
,
module
=
None
):
super
(
ModuleTest
,
self
)
.
__init__
(
methodName
)
self
.
module
=
module
def
test_has_metadata
(
self
):
self
.
assertIsInstance
(
self
.
metadata
,
dict
)
def
__str__
(
self
):
return
" "
.
join
([
super
(
ModuleTest
,
self
)
.
__str__
(),
self
.
module
.
__module__
]
)
def
test_legal_metadata_keys
(
self
):
@property
def
module_metadata
(
self
):
return
getattr
(
self
.
module
,
"_{}__info__"
.
format
(
self
.
module
.
__name__
))
legal_keys
=
set
([
def
test_required_metadata
(
self
):
required_metadata
=
(
"name"
,
"description"
,
"devices"
,
"authors"
,
"references"
])
self
.
assert
True
(
set
(
self
.
metadata
.
keys
())
.
issubset
(
legal_keys
))
"references"
)
self
.
assert
ItemsEqual
(
required_metadata
,
self
.
module_metadata
.
keys
(
))
def
load_tests
(
loader
,
tests
,
pattern
):
"""Map every module to a test case, and group them into a suite."""
suite
=
TestSuite
()
for
m
in
iter_modules
():
class
ParametrizedModuleTest
(
ModuleTest
):
# bind module
module
=
m
()
@property
def
metadata
(
self
):
return
getattr
(
self
.
module
,
"_{}__info__"
.
format
(
self
.
module
.
__class__
.
__name__
))
def
shortDescription
(
self
):
# provide the module name in the test description
return
getmodule
(
self
.
module
)
.
__name__
# add the tests from this test case
suite
.
addTests
(
loader
.
loadTestsFromTestCase
(
ParametrizedModuleTest
))
""" Map every module to a test case, and group them into a suite. """
suite
=
unittest
.
TestSuite
()
test_names
=
loader
.
getTestCaseNames
(
ModuleTest
)
for
module
in
iter_modules
():
suite
.
addTests
([
ModuleTest
(
name
,
module
)
for
name
in
test_names
])
return
suite
if
__name__
==
'__main__'
:
main
()
unittest
.
main
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment