Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dhondta committed Oct 13, 2023
1 parent 574d40f commit 2a73755
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 260 deletions.
File renamed without changes.
110 changes: 55 additions & 55 deletions tests/test_base.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""Core entity assets' tests.
"""
from utils import *


class TestBase(TestCase):
def test_general_commands(self):
self.assertRaises(SystemExit, Entity.get_subclass(Command, "Back")().run)
self.assertRaises(SystemExit, Entity.get_subclass(Command, "Exit")().run)
for Help in Entity.get_subclass(Command, "Help"):
if Help.level == "general":
self.assertIsNone(Help().run())
search = Entity.get_subclass(Command, "Search")()
self.assertIsNone(search.run("does_not_exist"))
self.assertIsNone(search.run("first"))
for Show in Entity.get_subclass(Command, "Show"):
if Show.level == "root":
Show.keys += ["issues"]
Show().set_keys()
for k in Show.keys + ["issues"]:
self.assertIsNotNone(Show().complete_values(k))
self.assertIsNone(Show().run(k))
if k == "options":
self.assertIsNone(Show().run(k, "DEBUG"))
break
Set = Entity.get_subclass(Command, "Set")
keys = list(Set().complete_keys())
self.assertTrue(len(keys) > 0)
self.assertIsNotNone(Set().complete_values(keys[0]))
self.assertIsNotNone(Set().complete_values("WORKSPACE"))
self.assertRaises(ValueError, Set().validate, "BAD", "whatever")
self.assertRaises(ValueError, Set().validate, "WORKSPACE", None)
self.assertRaises(ValueError, Set().validate, "DEBUG", "whatever")
self.assertIsNone(Set().run("DEBUG", "false"))
Unset = Entity.get_subclass(Command, "Unset")
self.assertTrue(len(list(Unset().complete_values())) > 0)
self.assertRaises(ValueError, Unset().validate, "BAD")
self.assertRaises(ValueError, Unset().validate, "WORKSPACE")
self.assertRaises(ValueError, Unset().run, "DEBUG")
self.assertIsNone(Set().run("DEBUG", "false"))

def test_root_commands(self):
for Help in Entity.get_subclass(Command, "Help"):
if Help.level == "root":
self.assertIsNone(Help().validate())
self.assertRaises(ValueError, Help().validate, "BAD")
self.assertIsNone(Help().run())
for k in Help().keys:
for v in Help().complete_values(k):
self.assertIsNone(Help().run(k, v))
break

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""Core entity assets' tests.
"""
from __utils__ import *


class TestBase(TestCase):
def test_general_commands(self):
self.assertRaises(SystemExit, Entity.get_subclass(Command, "Back")().run)
self.assertRaises(SystemExit, Entity.get_subclass(Command, "Exit")().run)
for Help in Entity.get_subclass(Command, "Help"):
if Help.level == "general":
self.assertIsNone(Help().run())
search = Entity.get_subclass(Command, "Search")()
self.assertIsNone(search.run("does_not_exist"))
self.assertIsNone(search.run("first"))
for Show in Entity.get_subclass(Command, "Show"):
if Show.level == "root":
Show.keys += ["issues"]
Show().set_keys()
for k in Show.keys + ["issues"]:
self.assertIsNotNone(Show().complete_values(k))
self.assertIsNone(Show().run(k))
if k == "options":
self.assertIsNone(Show().run(k, "DEBUG"))
break
Set = Entity.get_subclass(Command, "Set")
keys = list(Set().complete_keys())
self.assertTrue(len(keys) > 0)
self.assertIsNotNone(Set().complete_values(keys[0]))
self.assertIsNotNone(Set().complete_values("WORKSPACE"))
self.assertRaises(ValueError, Set().validate, "BAD", "whatever")
self.assertRaises(ValueError, Set().validate, "WORKSPACE", None)
self.assertRaises(ValueError, Set().validate, "DEBUG", "whatever")
self.assertIsNone(Set().run("DEBUG", "false"))
Unset = Entity.get_subclass(Command, "Unset")
self.assertTrue(len(list(Unset().complete_values())) > 0)
self.assertRaises(ValueError, Unset().validate, "BAD")
self.assertRaises(ValueError, Unset().validate, "WORKSPACE")
self.assertRaises(ValueError, Unset().run, "DEBUG")
self.assertIsNone(Set().run("DEBUG", "false"))

def test_root_commands(self):
for Help in Entity.get_subclass(Command, "Help"):
if Help.level == "root":
self.assertIsNone(Help().validate())
self.assertRaises(ValueError, Help().validate, "BAD")
self.assertIsNone(Help().run())
for k in Help().keys:
for v in Help().complete_values(k):
self.assertIsNone(Help().run(k, v))
break
58 changes: 29 additions & 29 deletions tests/test_components.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""Core entity assets' tests.
"""
from sploitkit.core.components import *

from utils import *


class TestComponents(TestCase):
def test_store(self):
s = CONSOLE._storage
self.assertTrue(isinstance(s.extensions, list))
s = CONSOLE.store
self.assertTrue(isinstance(s.basemodels, list))
self.assertTrue(isinstance(s.models, list))
self.assertFalse(s.volatile)
try:
s.get_user(username="test")
except DoesNotExist:
s.set_user(username="test")
self.assertEqual(s._last_snapshot, 0)
self.assertIsNone(s.snapshot())
self.assertEqual(s._last_snapshot, 1)
self.assertIsNone(s.snapshot(False))
self.assertEqual(s._last_snapshot, 0)
self.assertIsNone(s.snapshot(False))

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""Core entity assets' tests.
"""
from sploitkit.core.components import *

from __utils__ import *


class TestComponents(TestCase):
def test_store(self):
s = CONSOLE._storage
self.assertTrue(isinstance(s.extensions, list))
s = CONSOLE.store
self.assertTrue(isinstance(s.basemodels, list))
self.assertTrue(isinstance(s.models, list))
self.assertFalse(s.volatile)
try:
s.get_user(username="test")
except DoesNotExist:
s.set_user(username="test")
self.assertEqual(s._last_snapshot, 0)
self.assertIsNone(s.snapshot())
self.assertEqual(s._last_snapshot, 1)
self.assertIsNone(s.snapshot(False))
self.assertEqual(s._last_snapshot, 0)
self.assertIsNone(s.snapshot(False))
44 changes: 22 additions & 22 deletions tests/test_console.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""Core entity assets' tests.
"""
from sploitkit.core.components import *

from utils import *


class TestConsole(TestCase):
def test_console(self):
self.assertIsNotNone(CONSOLE._get_tokens("help"))
self.assertIsNone(CONSOLE.play("help"))
r = CONSOLE.play("help", "show modules", capture=True)
# check the presence of some commands from the base
for cmd in ["?", "exit", "quit", "unset", "use", "record", "replay", "help", "show", "select"]:
self.assertIn(" " + cmd + " ", r[0][1])
# check that some particular commands are missing
for cmd in ["pydbg", "memory", "dict"]:
self.assertNotIn(" " + cmd + " ", r[0][1])

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""Core entity assets' tests.
"""
from sploitkit.core.components import *

from __utils__ import *


class TestConsole(TestCase):
def test_console(self):
self.assertIsNotNone(CONSOLE._get_tokens("help"))
self.assertIsNone(CONSOLE.play("help"))
r = CONSOLE.play("help", "show modules", capture=True)
# check the presence of some commands from the base
for cmd in ["?", "exit", "quit", "unset", "use", "record", "replay", "help", "show", "select"]:
self.assertIn(" " + cmd + " ", r[0][1])
# check that some particular commands are missing
for cmd in ["pydbg", "memory", "dict"]:
self.assertNotIn(" " + cmd + " ", r[0][1])
96 changes: 48 additions & 48 deletions tests/test_entity.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""Core entity assets' tests.
"""
from sploitkit.core.entity import load_entities, set_metadata
from tinyscript.helpers import parse_docstring

from utils import *


class TestEntity(TestCase):
def test_load_entities(self):
self.assertIn(Command, list(Entity._subclasses.keys()))
self.assertIn(Model, list(Entity._subclasses.keys()))
self.assertIn(Module, list(Entity._subclasses.keys()))
self.assertTrue(len(Command.subclasses) > 0)
self.assertTrue(len(Model.subclasses) > 0)
l = len(Module.subclasses)
self.assertTrue(l > 0)
M = Module.subclasses[0]
del Entity._subclasses[Module]
load_entities([Module], CONSOLE._root.dirname.joinpath("modules"), exclude={'module': [M]})
self.assertTrue(len(Module.subclasses) > 0)
self.assertRaises(ValueError, Entity._subclasses.__getitem__, (Module, M.__name__))
del Entity._subclasses[Module]
load_entities([Module], CONSOLE._root.dirname.joinpath("modules"))
self.assertTrue(len(Module.subclasses) > 0)
self.assertIn(Entity._subclasses[Module, M.__name__], Module.subclasses)
load_entities([Console], CONSOLE._root, backref={'command': ["console"]})

def test_set_metadata(self):
# check that every subclass has its own description, and not the one of its entity class
for cls in Entity._subclasses.keys():
for subcls in cls.subclasses:
self.assertNotEqual(subcls.__doc__, cls.__doc__)
# now, alter a Command subclass to test for set_metadata
C = Command.subclasses[0]
C.meta = {'options': ["BAD_OPTION"]}
self.assertRaises(ValueError, set_metadata, C, parse_docstring)
C.meta = {'options': [("test", "default", False, "description")]}
set_metadata(C, parse_docstring)
M = Module.subclasses[0]
B = M.__base__
B.meta = {'test': "test"}
M._inherit_metadata = True
set_metadata(M, parse_docstring)

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""Core entity assets' tests.
"""
from sploitkit.core.entity import load_entities, set_metadata
from tinyscript.helpers import parse_docstring

from __utils__ import *


class TestEntity(TestCase):
def test_load_entities(self):
self.assertIn(Command, list(Entity._subclasses.keys()))
self.assertIn(Model, list(Entity._subclasses.keys()))
self.assertIn(Module, list(Entity._subclasses.keys()))
self.assertTrue(len(Command.subclasses) > 0)
self.assertTrue(len(Model.subclasses) > 0)
l = len(Module.subclasses)
self.assertTrue(l > 0)
M = Module.subclasses[0]
del Entity._subclasses[Module]
load_entities([Module], CONSOLE._root.dirname.joinpath("modules"), exclude={'module': [M]})
self.assertTrue(len(Module.subclasses) > 0)
self.assertRaises(ValueError, Entity._subclasses.__getitem__, (Module, M.__name__))
del Entity._subclasses[Module]
load_entities([Module], CONSOLE._root.dirname.joinpath("modules"))
self.assertTrue(len(Module.subclasses) > 0)
self.assertIn(Entity._subclasses[Module, M.__name__], Module.subclasses)
load_entities([Console], CONSOLE._root, backref={'command': ["console"]})

def test_set_metadata(self):
# check that every subclass has its own description, and not the one of its entity class
for cls in Entity._subclasses.keys():
for subcls in cls.subclasses:
self.assertNotEqual(subcls.__doc__, cls.__doc__)
# now, alter a Command subclass to test for set_metadata
C = Command.subclasses[0]
C.meta = {'options': ["BAD_OPTION"]}
self.assertRaises(ValueError, set_metadata, C, parse_docstring)
C.meta = {'options': [("test", "default", False, "description")]}
set_metadata(C, parse_docstring)
M = Module.subclasses[0]
B = M.__base__
B.meta = {'test': "test"}
M._inherit_metadata = True
set_metadata(M, parse_docstring)
28 changes: 14 additions & 14 deletions tests/test_model.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""Model entity tests.
"""
from utils import *


class TestModule(TestCase):
def test_model(self):
self.assertTrue(len(Model.subclasses) > 0)
self.assertTrue(len(StoreExtension.subclasses) == 0) # sploitkit's base has no StoreExtension at this moment
self.assertIsNotNone(repr(Model.subclasses[0]))

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""Model entity tests.
"""
from __utils__ import *


class TestModule(TestCase):
def test_model(self):
self.assertTrue(len(Model.subclasses) > 0)
self.assertTrue(len(StoreExtension.subclasses) == 0) # sploitkit's base has no StoreExtension at this moment
self.assertIsNotNone(repr(Model.subclasses[0]))
Loading

0 comments on commit 2a73755

Please sign in to comment.