Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions test/case_states/test_cvss_patterns.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Carnegie Mellon University and Contributors.
# Copyright (c) 2023-2025 Carnegie Mellon University and Contributors.
# - see Contributors.md for a full list of Contributors
# - see ContributionInstructions.md for information on how you can Contribute to this project
# Vultron Multiparty Coordinated Vulnerability Disclosure Protocol Prototype is
Expand Down Expand Up @@ -26,21 +26,14 @@ def setUp(self):
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_find_matches(self):
for patterndict in [cvss.CVSS_31_E_, cvss.CVSS_31_RL_]:
for state in self.model.states:
result = cvss.find_matches(state, patterndict)
# 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:
Expand All @@ -52,7 +45,7 @@ def test_cvss_31(self):

def test_cvss_exploitation_state(self):
for state in self.model.states:
result = cvss.cvss_31_e(state)
result = cvss.find_matches(state, cvss.CVSS_31_E_)
# if A in state, then Exploitation: Active should be in result
if "A" in state:
self.assertIn(cvss.CVSS_31_E.HIGH, result)
Expand Down
28 changes: 20 additions & 8 deletions test/test_as_vocab/test_actvitities/test_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,18 @@ def _test_base_actor_activity(
for actor_class in ACTOR_CLASSES:
_actor = actor_class(name=actor_class.__name__)
_case = VulnerabilityCase(name=f"{actor_class.__name__} Case")
_object = cls(as_object=_actor, target=_case)
_object = cls(actor=_actor, object=_actor, target=_case)

# check activity is correct type
self.assertIsInstance(_object, as_Activity)
self.assertIsInstance(_object, expect_class)
self.assertIsInstance(_object, cls)
# check the _object of the activity is correct instance
self.assertEqual(_object.as_object, _actor)
# check the target of the activity is correct instance
self.assertEqual(_object.target, _case)
# check the actor of the activity is correct instance
self.assertEqual(_object.actor, _actor)

# check json
_json = _object.to_json()
Expand All @@ -83,18 +87,26 @@ def _test_base_actor_activity(
self.assertIn('"target"', _json)

# check json loads back in correctly
reloaded = cls.from_json(_json)
reloaded = cls.model_validate_json(_json)

# the type should be Reject, not RejectActorRecommendation, etc.
self.assertEqual(reloaded.as_type, expect_type)

self.assertEqual(reloaded.as_object.as_id, _actor.as_id)
self.assertIn(reloaded.as_object.as_type, _actor.as_type)
self.assertEqual(reloaded.as_object.name, actor_class.__name__)
self.assertEqual(
getattr(reloaded.as_object, "as_id"), _actor.as_id
)
self.assertIn(
getattr(reloaded.as_object, "as_type"), _actor.as_type
)
self.assertEqual(
getattr(reloaded.as_object, "name"), actor_class.__name__
)

self.assertEqual(reloaded.target.as_id, _case.as_id)
self.assertEqual(reloaded.target.as_type, _case.as_type)
self.assertEqual(reloaded.target.name, _case.name)
self.assertEqual(getattr(reloaded.target, "as_id"), _case.as_id)
self.assertEqual(
getattr(reloaded.target, "as_type"), _case.as_type
)
self.assertEqual(getattr(reloaded.target, "name"), _case.name)


if __name__ == "__main__":
Expand Down
15 changes: 4 additions & 11 deletions test/test_as_vocab/test_vocab_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ def test_note(self):
def test_add_note_to_case(self):
activity = examples.add_note_to_case()
self.assertIsInstance(activity, as_Activity)
vendor = examples.vendor()
finder = examples.finder()
case = examples.case()
note = examples.note()
Expand Down Expand Up @@ -494,7 +493,6 @@ def test_rm_invite_to_case(self):
self.assertIsInstance(activity, as_Activity)
vendor = examples.vendor()
case = examples.case()
finder = examples.finder()
coordinator = examples.coordinator()

self.assertIsInstance(activity, as_Invite)
Expand Down Expand Up @@ -624,7 +622,6 @@ def test_invite_to_case(self):
self.assertIsInstance(activity, as_Activity)
vendor = examples.vendor()
case = examples.case()
finder = examples.finder()
coordinator = examples.coordinator()

self.assertIsInstance(activity, as_Invite)
Expand All @@ -639,8 +636,6 @@ def test_create_participant_status(self):
activity = examples.create_participant_status()
self.assertIsInstance(activity, as_Activity)
vendor = examples.vendor()
case = examples.case()
coordinator = examples.coordinator()

self.assertIsInstance(activity, as_Create)
self.assertEqual(activity.as_type, "Create")
Expand All @@ -652,18 +647,16 @@ def test_add_status_to_participant(self):
activity = examples.add_status_to_participant()
self.assertIsInstance(activity, as_Activity)
vendor = examples.vendor()
case = examples.case()
coordinator = examples.coordinator()
status = examples.participant_status()

self.assertIsInstance(activity, as_Add)
self.assertEqual(activity.as_type, "Add")

self.assertEqual(activity.actor, vendor.as_id)
self.assertEqual(activity.target, coordinator.as_id)
self.assertEqual(activity.as_object, status.as_id)
self.assertEqual(activity.target, status.context)
self.assertEqual(activity.as_object, status)

def test_add_status_to_participant(self):
def test_add_status_to_participant2(self):
activity = examples.add_status_to_participant()
self.assertIsInstance(activity, as_Activity)
vendor = examples.vendor()
Expand Down Expand Up @@ -708,7 +701,7 @@ def test_choose_preferred_embargo(self):
activity = examples.choose_preferred_embargo()
self.assertIsInstance(activity, as_Activity)
case = examples.case()
embargo = examples.embargo_event()
examples.embargo_event()
coordinator = examples.coordinator()

# is it a question?
Expand Down
5 changes: 2 additions & 3 deletions test/test_bt/test_base/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2023 Carnegie Mellon University and Contributors.
#!/usr/bin/env python
# Copyright (c) 2023-2025 Carnegie Mellon University and Contributors.
# - see Contributors.md for a full list of Contributors
# - see ContributionInstructions.md for information on how you can Contribute to this project
# Vultron Multiparty Coordinated Vulnerability Disclosure Protocol Prototype is
Expand All @@ -10,5 +11,3 @@
# (“Third Party Software”). See LICENSE.md for more details.
# Carnegie Mellon®, CERT® and CERT Coordination Center® are registered in the
# U.S. Patent and Trademark Office by Carnegie Mellon University

#!/usr/bin/env python
14 changes: 9 additions & 5 deletions test/test_bt/test_base/test_factory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Carnegie Mellon University and Contributors.
# Copyright (c) 2023-2025 Carnegie Mellon University and Contributors.
# - see Contributors.md for a full list of Contributors
# - see ContributionInstructions.md for information on how you can Contribute to this project
# Vultron Multiparty Coordinated Vulnerability Disclosure Protocol Prototype is
Expand Down Expand Up @@ -128,8 +128,10 @@ def test_fuzzer(self):
self.assertIsInstance(node_cls(), node_cls)

def test_condition_check(self):
func = lambda: True
func.__doc__ = "bar"
def func() -> bool:
"""bar"""
return True

node_cls = condition_check("foo", func)

self.assertTrue(issubclass(node_cls, ConditionCheck))
Expand All @@ -140,8 +142,10 @@ def test_condition_check(self):
self.assertIsInstance(node_cls(), node_cls)

def test_action_node(self):
func = lambda: True
func.__doc__ = "bar"
def func() -> bool:
"""bar"""
return True

node_cls = action_node("foo", func)

self.assertTrue(issubclass(node_cls, ActionNode))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Carnegie Mellon University and Contributors.
# Copyright (c) 2023-2025 Carnegie Mellon University and Contributors.
# - see Contributors.md for a full list of Contributors
# - see ContributionInstructions.md for information on how you can Contribute to this project
# Vultron Multiparty Coordinated Vulnerability Disclosure Protocol Prototype is
Expand All @@ -13,6 +13,7 @@

import unittest
from itertools import product
from typing import Callable, Any

# noinspection PyProtectedMember
import vultron.bt.messaging.inbound._behaviors.cs_messages as vmc
Expand All @@ -22,14 +23,18 @@


class MockMsg:
msg_type: Mt = None
msg_type: Mt | None = None


def mock_emit(*args):
pass


class MockState:
current_message: MockMsg = None
q_cs: CS = None
current_message: MockMsg | None = None
q_cs: CS | None = None
name: str = "Foo"
emit_func: callable = lambda *x: None
emit_func: Callable[[Any], Any] = mock_emit
msg_history: list = []
msgs_emitted_this_tick: list = []
incoming_messages: list = []
Expand Down
6 changes: 3 additions & 3 deletions test/test_bt/test_report_management/test_conditions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Carnegie Mellon University and Contributors.
# Copyright (c) 2023-2025 Carnegie Mellon University and Contributors.
# - see Contributors.md for a full list of Contributors
# - see ContributionInstructions.md for information on how you can Contribute to this project
# Vultron Multiparty Coordinated Vulnerability Disclosure Protocol Prototype is
Expand All @@ -24,8 +24,8 @@ def _test_generic_rm_in_state(self, cls, state):
node = cls()
node.bb = ActorState()

self.assertEqual("q_rm", node.key)
self.assertEqual(state, node.state)
self.assertIn("q_rm", node.name)
self.assertIn(state.name, node.name)

for rm_state in RM:
node.bb.q_rm = rm_state
Expand Down
4 changes: 4 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion vultron/as_vocab/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Carnegie Mellon University and Contributors.
# Copyright (c) 2023-2025 Carnegie Mellon University and Contributors.
# - see Contributors.md for a full list of Contributors
# - see ContributionInstructions.md for information on how you can Contribute to this project
# Vultron Multiparty Coordinated Vulnerability Disclosure Protocol Prototype is
Expand All @@ -11,3 +11,5 @@
# Carnegie Mellon®, CERT® and CERT Coordination Center® are registered in the
# U.S. Patent and Trademark Office by Carnegie Mellon University
"""The vultron.as_vocab package implements Vultron-specific Activity Streams 2.0 objects and activities."""

from .base.registry import VOCABULARY
9 changes: 7 additions & 2 deletions vultron/as_vocab/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@

from typing import Literal

from pydantic import BaseModel, Field, model_validator, ConfigDict
from pydantic import (
BaseModel,
Field,
model_validator,
ConfigDict,
)
from pydantic.alias_generators import to_camel

from vultron.as_vocab.base.utils import generate_new_id
Expand All @@ -33,7 +38,7 @@ class as_Base(BaseModel):
as_context: Literal[ACTIVITY_STREAMS_NS] = Field(
default=ACTIVITY_STREAMS_NS, alias="@context"
)
as_type: str = Field(default=None, alias="type")
as_type: str | None = Field(default=None, alias="type")
as_id: str = Field(default_factory=generate_new_id, alias="id")
name: str | None = None
preview: str | None = None
Expand Down
3 changes: 2 additions & 1 deletion vultron/as_vocab/base/objects/activities/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# U.S. Patent and Trademark Office by Carnegie Mellon University

from vultron.as_vocab.base.links import as_Link
from vultron.as_vocab.base.objects.actors import as_ActorRef
from vultron.as_vocab.base.objects.base import as_Object


Expand All @@ -30,7 +31,7 @@ class as_Activity(as_Object):

as_type: str = "Activity"

actor: as_Object | as_Link | str = None
actor: as_ActorRef
target: as_Object | as_Link | str | None = None
origin: as_Object | as_Link | str | None = None
instrument: as_Object | as_Link | str | None = None
Expand Down
8 changes: 4 additions & 4 deletions vultron/as_vocab/base/objects/activities/intransitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# Carnegie Mellon®, CERT® and CERT Coordination Center® are registered in the
# U.S. Patent and Trademark Office by Carnegie Mellon University


from datetime import datetime
from typing import Literal

from vultron.as_vocab.base.links import as_Link
from vultron.as_vocab.base.objects.activities.base import (
Expand Down Expand Up @@ -42,7 +42,7 @@ class as_Travel(as_IntransitiveActivity):
See definition in ActivityStreams Vocabulary <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-travel>
"""

as_type: Literal["Travel"] = "Travel"
as_type: str = "Travel"


@activitystreams_activity
Expand All @@ -51,7 +51,7 @@ class as_Arrive(as_IntransitiveActivity):
See definition in ActivityStreams Vocabulary <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-arrive>
"""

as_type: Literal["Arrive"] = "Arrive"
as_type: str = "Arrive"


@activitystreams_activity
Expand All @@ -60,7 +60,7 @@ class as_Question(as_IntransitiveActivity):
See definition in ActivityStreams Vocabulary <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-question>
"""

as_type: Literal["Question"] = "Question"
as_type: str = "Question"

anyOf: as_Object | as_Link | str | None = None
oneOf: as_Object | as_Link | str | None = None
Expand Down
Loading
Loading