Skip to content

tests: parity mac() helper double-encodes pypcapfile addresses that are already ASCII #749

Description

@JarryShaw

tests/foundation/engines/test_new_engine_parity_runtime.py:82's mac() helper assumes pypcapfile's Ethernet.dst/.src are raw 6-byte values needing hex-formatting. They are already colon-separated ASCII.

Confirmed at source — pcapfile/protocols/linklayer/ethernet.py, Ethernet.__init__:

(dst, src, self.type) = struct.unpack('!6s6sH', packet[:14])
dst = bytearray(dst); src = bytearray(src)
self.dst = b':'.join([('%02x' % o).encode('ascii') for o in dst])
self.src = b':'.join([('%02x' % o).encode('ascii') for o in src])

So .dst is b'40:33:1a:d1:85:1c', and mac() hex-encodes that a second time — producing '33:34:3a:...' against an expected '40:33:1a:d1:85:1c'. This is unconditional in pypcapfile and independent of layers=.

Why this matters for the other two

test_pypcapfile_agrees_with_the_default_engine is one of three HAS_PYPCAPFILE-gated parity methods, and each of the three needs a different fix:

test needs
test_pypcapfile_agrees_with_the_default_engine this issue
ipv4_reassembly parity #746 (engine hexlify) + #743 (toolkit addresses)
traces_only parity #746 + #743

Measured on 3.10.21: with #746's fix alone the Ethernet fields decode correctly but the other two hit #743's AddressValueError; overlaying #747's toolkit fix takes both fully green. This one stays red regardless, because neither the engine nor the toolkit can reach it.

So "the three parity tests go green" was the wrong acceptance criterion for #746 — I set it, and it was only ever true for two of them, and only in combination with #747. Correcting that here rather than leaving it implied.

Scope note

The fix is almost certainly deleting the re-encoding in mac() rather than changing library code — the library is right and the test is wrong. Worth confirming whether mac() is also applied to the default engine's output in the same comparison, because if so it may be correct for one side and wrong for the other, which would make a bare deletion break the other half.

Found while fixing #746 (PR #748), which correctly did not edit this file.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtestPull requests that add or correct tests (test: subject prefix)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions