Skip to content

Issue2 adding tests#8

Merged
shaharyarn merged 8 commits intodevelopfrom
issue2_adding_tests
Mar 26, 2020
Merged

Issue2 adding tests#8
shaharyarn merged 8 commits intodevelopfrom
issue2_adding_tests

Conversation

@shaharyarn
Copy link
Copy Markdown
Collaborator

No description provided.

@tomlegkov tomlegkov self-requested a review March 23, 2020 17:56
@tomlegkov tomlegkov self-requested a review March 23, 2020 18:21
Copy link
Copy Markdown
Owner

@tomlegkov tomlegkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job. The main required fix is combining all of the filter_and_parse tests into a single test and adding a few more protocols.

@tomlegkov tomlegkov linked an issue Mar 23, 2020 that may be closed by this pull request

def test_packet_doesnt_pass_filter_because_of_bfp(marine_instance, tcp_packet, extracted_fields_from_tcp_packet):
passed, output = marine_instance.filter_and_parse(tcp_packet, 'arp', fields=extracted_fields_from_tcp_packet)
def test_packet_doesnt_pass_filter_because_of_bfp(
Copy link
Copy Markdown
Owner

@tomlegkov tomlegkov Mar 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, fix the typo to bpf

extracted_fields_from_udp_packet):
expected = dict(zip(extracted_fields_from_udp_packet, map(str, [mac_1, mac_2, ip_1, ip_2, port_3, port_4])))
passed, output = marine_instance.filter_and_parse(udp_packet, 'ip', 'udp', extracted_fields_from_udp_packet)
from pytest_lazyfixture import lazy_fixture
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new tests packages to tox.ini, and remember to run tox before pushing code :)

@tomlegkov tomlegkov self-requested a review March 24, 2020 17:22
Copy link
Copy Markdown
Owner

@tomlegkov tomlegkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the tox stuff and it's fine by me. Let's wait for the others to CR too.

@tomlegkov tomlegkov self-requested a review March 24, 2020 17:25
@tomlegkov tomlegkov requested a review from yehonatanz March 24, 2020 18:17
Copy link
Copy Markdown
Collaborator

@yehonatanz yehonatanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main issue is about the fixtures hell in test_filter_and_parse.
Let's talk about it on Slack before you proceed

"http_type": "GET",
"uri": f"/{create_random_string(8)}",
"version": "HTTP/1.1",
"host": create_random_url(),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seem like a domain name

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also didn't we decide to get rid of randomly generated values?

zip(
extracted_fields_from_packet,
map(
lambda x: str(request.getfixturevalue(x)), fields_expected_fixture_name
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we always return strings? Does wireshark always return strings? Don't you define a type for every field in lua dissectors?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently all of the results in the Python client are returned as strings, see this open issue.

bpf_filter="ip",
display_filter="http",
)
def test_packet_filter_and_parse(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parametrization for this test is way too complicated for what it tests.
I'd really rather you avoided fixtures in this test.
I want to see every tested packet next to every field and its value (with only relevant fields).
Something like:

@Parametrization.case(
    name="HTTP",
    packet=Ethernet(...) + IP(...) + TCP(...) + HTTP(...),
    bpf="ip",
    display_filter="http",
    fields=["http.type", "http.uri", "http.version"],
    expected=["GET", "/pasten", "1.1"],
)

Perhaps with some predefined consts for reptetive and not interesting layers (not interesting = not tested).

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think creating the packet for each case in the file will create a bit of a mess for example, look how many lines are needed to create a DHCP packet.
Is it really interesting to see the values being tested when you read the case, especially when there's only one packet per case? Hiding a lot of the data behind fixtures makes the case a lot more readable.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about it. My instinct is to make tests as explicit as possible.
Packets with extremly long tested layer (such as DHCP) might indeed justify a fixture (or const), but a standalone one, with no long dependency graph like now.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your instinct and I agree with it, however it means some cases will contain fixtures and some won't. I think it will be inconvenient to follow.

Maybe the solution is to go back to not using parameterize? Having a separate test for every protocol will allow more flexibility, but will contain code repetition.

Copy link
Copy Markdown
Collaborator

@yehonatanz yehonatanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had just one tiny note.
I'm still not entirely sure about the lack of parametrization, but it's ok for now :)

marine_instance.filter_and_parse(tcp_packet, display_filter='illegal_filter')
assert 'neither a field nor a protocol name' in str(excinfo)
marine_instance.filter_and_parse(tcp_packet, display_filter="illegal_filter")
assert "neither a field nor a protocol name" in str(excinfo)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use pytest.raises(..., match="some regex")

Comment on lines +20 to +21
bpf_filter: str,
display_filter: str,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In lines 322 and 323 you're passing bpf_filter and display_filter as None, so this should be Optional[str].

Copy link
Copy Markdown
Owner

@tomlegkov tomlegkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix this one tiny thing, and looks good otherwise :)

Copy link
Copy Markdown
Collaborator

@yehonatanz yehonatanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good :)
Just fix Tom's notes

@shaharyarn shaharyarn merged commit 14cefd5 into develop Mar 26, 2020
tomlegkov added a commit that referenced this pull request Mar 26, 2020
@tomlegkov tomlegkov deleted the issue2_adding_tests branch March 26, 2020 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for filter_and_parse for common protocols

4 participants