Skip to content

Commit

Permalink
Address comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
deadly-panda committed Feb 26, 2025
1 parent 1e297da commit 098f95c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ message CallTrace {

message Metadata {
optional MetadataTypeEnum type = 1;
oneof value {
string raw_value = 2;
oneof metadata_value {
string value = 2;
CallTrace calltrace = 3;
}
}
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Frame:
package_name: Optional[str] = None

def to_proto_dict(self) -> FrameProtoDictType:
"""Return a dictionary structured same as the corresponding `Frame` protobuf field of the callTrace message."""
proto_dict_value: FrameProtoDictType = {"function_name": self.function_name}
if self.class_name is not None:
proto_dict_value["class_name"] = self.class_name
Expand All @@ -58,6 +59,7 @@ class CallTrace:
frames: List[Frame] = dataclasses.field(default_factory=lambda: [])

def to_proto_dict(self) -> CallTraceProtoDictType:
"""Return a dictionary structured same as the corresponding `callTrace` protobuf message."""
proto_dict_value: CallTraceProtoDictType = {
"frames": [frame.to_proto_dict() for frame in self.frames]
}
Expand All @@ -77,7 +79,7 @@ def to_proto_dict(self) -> VulnerabilityLocationMetadataProtoDictType:
"type": self.metadata_type.name
}
if isinstance(self.value, str):
proto_dict_value["raw_value"] = self.value
proto_dict_value["value"] = self.value
if isinstance(self.value, CallTrace):
proto_dict_value["calltrace"] = self.value.to_proto_dict()
return proto_dict_value
Expand Down
19 changes: 3 additions & 16 deletions tests/agent/mixins/agent_report_vulnerability_mixin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,23 +218,10 @@ def testFrameToProtoDict_whenAllFieldsAreSet_returnsCompleteDict() -> None:
}


def testCallTraceToProtoDict_whenAllFieldsAreSet_returnsCompleteDict() -> None:
def testCallTraceToProtoDict_whenAllFieldsAreSet_returnsCompleteDict(
call_trace: agent_report_vulnerability_mixin.CallTrace,
) -> None:
"""Test that to_proto_dict returns a complete dictionary when all fields are set."""
frame1 = agent_report_vulnerability_mixin.Frame(
function_name="test_func1",
class_name="TestClass1",
package_name="test.package1",
)
frame2 = agent_report_vulnerability_mixin.Frame(
function_name="test_func2",
class_name="TestClass2",
package_name="test.package2",
)

call_trace = agent_report_vulnerability_mixin.CallTrace(
frames=[frame1, frame2],
)

proto_dict = call_trace.to_proto_dict()

assert proto_dict == {
Expand Down

0 comments on commit 098f95c

Please sign in to comment.