Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Ostorlab/ostorlab into feature/add-…
Browse files Browse the repository at this point in the history
…support-for-stack-traces-in-vulnerability-location-proto-msg
  • Loading branch information
deadly-panda committed Feb 26, 2025
2 parents bf93a00 + 13f66e1 commit 1e297da
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ license_files = LICENSE
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/Ostorlab/ostorlab
version=1.4.3
version=1.4.4
project_urls =
Documentation = https://oxo.ostorlab.co/
Source = https://github.com/Ostorlab/oxo
Expand Down
17 changes: 13 additions & 4 deletions src/ostorlab/testing/agent.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""mock agent implements the required methods to test the agent's behavior without using external components."""

from typing import List, Union
import dataclasses

import pytest

from typing import List

from ostorlab.agent.message import message as msg


Expand Down Expand Up @@ -95,9 +94,15 @@ def _get(key):
if key in storage:
return storage[key]

def _add(key, value):
def _add(key: Union[str, bytes], value: bytes) -> None:
"""Check values are present in the storage dict."""
storage[key] = str(value).encode()
if isinstance(value, bytes) is False:
value = str(value).encode()
storage[key] = value

def _exists(key: Union[str, bytes]) -> bool:
"""Check if thr key is present in the storage dict."""
return key in storage

def _hash_add(hash_name, mapping):
for k, v in mapping.items():
Expand Down Expand Up @@ -156,6 +161,10 @@ def _value_type(key):
"ostorlab.agent.mixins.agent_persist_mixin.AgentPersistMixin.add",
side_effect=_add,
)
mocker.patch(
"ostorlab.agent.mixins.agent_persist_mixin.AgentPersistMixin.exists",
side_effect=_exists,
)
mocker.patch(
"ostorlab.agent.mixins.agent_persist_mixin.AgentPersistMixin.hash_add",
side_effect=_hash_add,
Expand Down
3 changes: 3 additions & 0 deletions tests/testing/agent_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ def testMockPersistAgent_whensetMethodsAreCalled_stateIsPersistedByMock(
assert test_agent.set_add("test", "1") is True
assert test_agent.set_is_member("test", "1") is True
assert agent_persist_mock == {"test": {"1"}}
assert test_agent.exists("akey") is False
test_agent.add("akey", b"aval")
assert test_agent.exists("akey") is True

0 comments on commit 1e297da

Please sign in to comment.