-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57cc285
commit 6834c98
Showing
11 changed files
with
1,130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright (c) 2023. Carnegie Mellon University | ||
# | ||
# See LICENSE for details | ||
|
||
import unittest | ||
from enum import Enum | ||
|
||
import vultron.cvd_states.patterns.cvss31 as cvss | ||
from vultron.cvd_states.hypercube import CVDmodel | ||
|
||
|
||
class MyTestCase(unittest.TestCase): | ||
def setUp(self): | ||
self.model = CVDmodel() | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_cvss_31_e(self): | ||
for state in self.model.states: | ||
result = cvss.cvss_31_e(state) | ||
# result should always be a list of non-zero length of strings of non-zero length | ||
self.assertIsInstance(result, list) | ||
for item in result: | ||
self.assertIsInstance(item, Enum) | ||
|
||
def test_cvss_31_rl(self): | ||
for state in self.model.states: | ||
result = cvss.cvss_31_rl(state) | ||
# result should always be a list of non-zero length of strings of non-zero length | ||
self.assertIsInstance(result, list) | ||
for item in result: | ||
self.assertIsInstance(item, Enum) | ||
|
||
def test_cvss_31(self): | ||
for state in self.model.states: | ||
result = cvss.cvss_31(state) | ||
# result should always be a list of non-zero length of strings of non-zero length | ||
self.assertIsInstance(result, list) | ||
for item in result: | ||
self.assertIsInstance(item, Enum) | ||
|
||
def test_cvss_exploitation_state(self): | ||
for state in self.model.states: | ||
result = cvss.cvss_31_e(state) | ||
# if A in state, then Exploitation: Active should be in result | ||
if "A" in state: | ||
self.assertIn(cvss.CVSS_31_E.HIGH, result) | ||
self.assertIn(cvss.CVSS_31_E.FUNCTIONAL, result) | ||
elif "X" in state: | ||
self.assertIn(cvss.CVSS_31_E.HIGH, result) | ||
self.assertIn(cvss.CVSS_31_E.FUNCTIONAL, result) | ||
self.assertIn(cvss.CVSS_31_E.PROOF_OF_CONCEPT, result) | ||
else: | ||
self.assertIn(cvss.CVSS_31_E.UNPROVEN, result) | ||
self.assertIn(cvss.CVSS_31_E.NOT_DEFINED, result) | ||
|
||
self.assertNotIn(cvss.CVSS_31_E.PROOF_OF_CONCEPT, result) | ||
self.assertNotIn(cvss.CVSS_31_E.FUNCTIONAL, result) | ||
self.assertNotIn(cvss.CVSS_31_E.HIGH, result) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright (c) 2023. Carnegie Mellon University | ||
# | ||
# See LICENSE for details | ||
|
||
import unittest | ||
|
||
import vultron.cvd_states.hypercube as sg | ||
import vultron.cvd_states.patterns.embargo as mb | ||
from vultron.cvd_states.errors import StateValidationError | ||
|
||
|
||
class MyTestCase(unittest.TestCase): | ||
def setUp(self): | ||
self.model = sg.CVDmodel() | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_reject_bogus_states(self): | ||
funcs = [mb.can_start_embargo, mb.embargo_viable] | ||
bogus_states = ["abbso", "abs", "absd", "absdx", "absdxa", "absdpxa"] | ||
for func in funcs: | ||
for state in bogus_states: | ||
self.assertRaises(StateValidationError, func, state) | ||
|
||
def test_embargo_viable(self): | ||
m = self.model | ||
|
||
# walk all the states and check the embargo_viable function | ||
for state in m.states: | ||
if "pxa" in state: | ||
self.assertTrue(mb.embargo_viable(state)) | ||
else: | ||
self.assertFalse(mb.embargo_viable(state)) | ||
|
||
def test_can_start_embargo(self): | ||
m = self.model | ||
|
||
# walk all the states and check the can_start_embargo function | ||
for state in m.states: | ||
if "dpxa" in state: | ||
self.assertTrue(mb.can_start_embargo(state)) | ||
else: | ||
self.assertFalse(mb.can_start_embargo(state)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright (c) 2023. Carnegie Mellon University | ||
# | ||
# See LICENSE for details | ||
|
||
import unittest | ||
from enum import Enum | ||
|
||
import vultron.cvd_states.patterns.info as info | ||
from vultron.cvd_states.hypercube import CVDmodel | ||
|
||
|
||
class MyTestCase(unittest.TestCase): | ||
def setUp(self): | ||
self.model = CVDmodel() | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_info(self): | ||
for state in self.model.states: | ||
result = info.info(state) | ||
# result should always be a list of non-zero length of strings of non-zero length | ||
self.assertIsInstance(result, list) | ||
self.assertGreater(len(result), 0) | ||
for item in result: | ||
self.assertIsInstance(item, Enum) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Copyright (c) 2023. Carnegie Mellon University | ||
# | ||
# See LICENSE for details | ||
|
||
import unittest | ||
from enum import IntEnum | ||
|
||
from vultron.cvd_states.enums.utils import ( | ||
enum_item_in_list, | ||
enum_list_to_string_list, | ||
uniq_enum_iter, | ||
unique_enum_list, | ||
) | ||
|
||
|
||
class Foo(IntEnum): | ||
No = 0 | ||
Yes = 1 | ||
|
||
|
||
class Bar(IntEnum): | ||
No = 0 | ||
Yes = 1 | ||
|
||
|
||
class MyTestCase(unittest.TestCase): | ||
def setUp(self): | ||
pass | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_enum_list_to_string_list(self): | ||
list_of_items = [Foo.No, Bar.Yes] | ||
results = enum_list_to_string_list(list_of_items) | ||
self.assertEqual(results, ["Foo.No", "Bar.Yes"]) | ||
|
||
def test_enum_item_in_list(self): | ||
list_of_items = [Foo.No, Bar.Yes] | ||
for test_item in [Foo.No, Bar.Yes]: | ||
self.assertTrue(enum_item_in_list(test_item, list_of_items)) | ||
for test_item in [Foo.Yes, Bar.No]: | ||
self.assertFalse(enum_item_in_list(test_item, list_of_items)) | ||
|
||
def test_uniq_enum_iter(self): | ||
list_of_items = [Foo.No, Bar.Yes, Foo.No, Bar.Yes] | ||
results = list(uniq_enum_iter(list_of_items)) | ||
self.assertEqual(results, [Foo.No, Bar.Yes]) | ||
|
||
def test_unique_enum_list(self): | ||
list_of_items = [Foo.No, Bar.Yes, Foo.No, Bar.Yes] | ||
results = unique_enum_list(list_of_items) | ||
self.assertEqual(results, [Foo.No, Bar.Yes]) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright (c) 2023. Carnegie Mellon University | ||
# | ||
# See LICENSE for details | ||
|
||
import unittest | ||
|
||
from vultron.cvd_states.hypercube import CVDmodel | ||
from vultron.cvd_states.patterns import potential_actions as pa | ||
|
||
|
||
class MyTestCase(unittest.TestCase): | ||
def setUp(self): | ||
self.model = CVDmodel() | ||
pass | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_pa_action(self): | ||
for state in self.model.states: | ||
result = pa.action(state) | ||
# actions should be a list | ||
self.assertIsInstance(result, list) | ||
# actions should be non-empty | ||
self.assertGreater(len(result), 0) | ||
# actions should be a list of enums | ||
for a in result: | ||
self.assertIsInstance(a, pa.Actions) | ||
# actions should be unique | ||
self.assertEqual(len(result), len(set(result))) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.