fix(nfproxy): export HttpHistory in nfproxy and ensure list immutability in getters

This commit is contained in:
Sogoss 2026-07-20 16:14:07 +02:00
parent dbc8b176b1
commit c71ad7c199
3 changed files with 33 additions and 3 deletions

View File

@ -1,5 +1,13 @@
import functools import functools
from firegex.nfproxy.models import RawPacket, TCPInputStream, TCPOutputStream, TCPClientStream, TCPServerStream from firegex.nfproxy.models import (
RawPacket,
TCPInputStream,
TCPOutputStream,
TCPClientStream,
TCPServerStream,
HttpHistory,
HttpStreamHistory,
)
from firegex.nfproxy.internals.models import Action, FullStreamAction from firegex.nfproxy.internals.models import Action, FullStreamAction
ACCEPT = Action.ACCEPT ACCEPT = Action.ACCEPT

View File

@ -411,12 +411,12 @@ class HttpHistory:
@property @property
def requests(self) -> list["HttpFullRequest"]: def requests(self) -> list["HttpFullRequest"]:
"""List of previous completed HTTP requests""" """List of previous completed HTTP requests"""
return self._requests return self._requests.copy()
@property @property
def responses(self) -> list["HttpFullResponse"]: def responses(self) -> list["HttpFullResponse"]:
"""List of previous completed HTTP responses""" """List of previous completed HTTP responses"""
return self._responses return self._responses.copy()
@classmethod @classmethod
def _fetch_packet(cls, internal_data: DataStreamCtx): def _fetch_packet(cls, internal_data: DataStreamCtx):

View File

@ -264,6 +264,25 @@ def filter_req(req: HttpFullRequest):
handle_packet(glob) handle_packet(glob)
def test_http_history_nfproxy_import():
from firegex.nfproxy import HttpHistory as HH1, HttpStreamHistory as HH2
assert HH1 is HttpHistory
assert HH2 is HttpStreamHistory
def test_http_history_list_mutation():
history_obj = HttpHistory(requests=["dummy_req"], responses=["dummy_resp"])
reqs = history_obj.requests
reqs.clear()
assert len(history_obj.requests) == 1
assert history_obj.requests == ["dummy_req"]
resps = history_obj.responses
resps.append("extra_resp")
assert len(history_obj.responses) == 1
assert history_obj.responses == ["dummy_resp"]
if __name__ == "__main__": if __name__ == "__main__":
test_http_history_model() test_http_history_model()
test_http_history_stream_execution() test_http_history_stream_execution()
@ -272,6 +291,9 @@ if __name__ == "__main__":
test_http_history_parameter_order() test_http_history_parameter_order()
test_http_history_property_immutability() test_http_history_property_immutability()
test_http_history_negative_max_size() test_http_history_negative_max_size()
test_http_history_nfproxy_import()
test_http_history_list_mutation()
print("All HTTP history unit tests passed successfully!") print("All HTTP history unit tests passed successfully!")