secdev / secdev/scapy

Enumerator tests keep failing on Windows

Open
#4,185 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
12.6k
Forks
2.2k
Avg merge
1d 4h
Merged PRs (30d)
56

Description

Disabled in https://github.com/secdev/scapy/pull/4186

###(014)=[failed] ServiceEnumerator execute
>>> from queue import Queue
>>> from scapy.supersocket import SuperSocket
>>> 
>>> class MockISOTPSocket(SuperSocket):
...     nonblocking_socket = True
...     @property
...     def closed(self):
...         return False
...     @closed.setter
...     def closed(self, var):
...         pass
...     def __init__(self, rcvd_queue=None):
...         self.rcvd_queue = Queue()
...         self.sent_queue = Queue()
...         if rcvd_queue is not None:
...             for c in rcvd_queue:
...                 self.rcvd_queue.put(c)
...     def recv_raw(self, x=MTU):
...         pkt = bytes(self.rcvd_queue.get(True, 0.01))
...         return UDS, pkt, 10.0
...     def send(self, x):
...         sx = raw(x)
...         try:
...             x.sent_time = 9.0
...         except AttributeError:
...             pass
...         self.sent_queue.put(sx)
...         return len(sx)
...     @staticmethod
...     def select(sockets, remain=None):
...         return sockets
... 
>>> sock = MockISOTPSocket()
>>> sock.rcvd_queue.put(b"\x41")
>>> sock.rcvd_queue.put(b"\x42")
>>> sock.rcvd_queue.put(b"\x43")
>>> sock.rcvd_queue.put(b"\x44")
>>> sock.rcvd_queue.put(b"\x45")
>>> sock.rcvd_queue.put(b"\x46")
>>> sock.rcvd_queue.put(b"\x47")
>>> sock.rcvd_queue.put(b"\x48")
>>> sock.rcvd_queue.put(b"\x49")
>>> sock.rcvd_queue.put(b"\x4A")
>>> 
>>> e = MyTestCase()
>>> 
>>> e.execute(sock, EcuState(session=1))
Finished iterator execution
>>> 
>>> assert len(e.filtered_results) == 10
>>> assert len(e.results_with_response) == 10
>>> assert len(e.results_without_response) == 0
>>> 
>>> assert e.has_completed(EcuState(session=1))
>>> assert e.completed
>>> 
>>> e.execute(sock, EcuState(session=2), timeout=0.01)
Socket <MockISOTPSocket object at 0x0000013F716E7F08> failed with ''. It was closed.
Traceback (most recent call last):
  File "<input>", line 2, in <module>
  File "C:\projects\scapy\scapy\contrib\automotive\scanner\enumerator.py", line 309, in execute
    res = self.sr1_with_retry_on_error(req, socket, state, timeout)
  File "C:\projects\scapy\scapy\contrib\automotive\scanner\enumerator.py", line 347, in sr1_with_retry_on_error
    chainEX=True, chainCC=True)
  File "C:\projects\scapy\scapy\supersocket.py", line 223, in sr1
    ans = sendrecv.sndrcv(self, *args, **kargs)[0]  # type: SndRcvList
  File "C:\projects\scapy\scapy\sendrecv.py", line 330, in sndrcv
    sndrcver = SndRcvHandler(*args, **kwargs)
  File "C:\projects\scapy\scapy\sendrecv.py", line 189, in __init__
    self._sndrcv_rcv(self._sndrcv_snd)
  File "C:\projects\scapy\scapy\sendrecv.py", line 317, in _sndrcv_rcv
    started_callback=callback
  File "C:\projects\scapy\scapy\sendrecv.py", line 1247, in _run
    for p in packets:
  File "C:\projects\scapy\scapy\sessions.py", line 56, in recv
    pkt = sock.recv()
  File "C:\projects\scapy\scapy\supersocket.py", line 180, in recv
    cls, val, ts = self.recv_raw(x)
  File "<input>", line 17, in recv_raw
  File "C:\Python37-x64\lib\queue.py", line 178, in get
    raise Empty
_queue.Empty
PACKET DISSECTION FAILED ON:
 Ether(hex_bytes('00155da5c62c00155da5c65c08004500003848b80000fe01814143e1a4030a0000e70b005831000000004500002848b80000010622310a0000e7ac4097c0733100505554d3f8'))
###(016)=[failed] Test negative response code retry if busy
>>> sock.rcvd_queue.put(b"\x7f\x01\x21")
>>> sock.rcvd_queue.put(b"\x7f\x01\x10")
>>> 
>>> e = MyTestCase()
>>> 
>>> e.execute(sock, EcuState(session=1))
>>> 
>>> assert e._retry_pkt[EcuState(session=1)]
>>> assert len(e.results_with_response) == 1
>>> assert len(e.results_with_negative_response) == 1
>>> assert len(e.results_without_response) == 0
>>> assert not e.completed
>>> 
>>> e.execute(sock, EcuState(session=1))
Socket <MockISOTPSocket object at 0x0000013F716E7F08> failed with ''. It was closed.
Traceback (most recent call last):
  File "<input>", line 2, in <module>
  File "C:\projects\scapy\scapy\contrib\automotive\scanner\enumerator.py", line 309, in execute
    res = self.sr1_with_retry_on_error(req, socket, state, timeout)
  File "C:\projects\scapy\scapy\contrib\automotive\scanner\enumerator.py", line 347, in sr1_with_retry_on_error
    chainEX=True, chainCC=True)
  File "C:\projects\scapy\scapy\supersocket.py", line 223, in sr1
    ans = sendrecv.sndrcv(self, *args, **kargs)[0]  # type: SndRcvList
  File "C:\projects\scapy\scapy\sendrecv.py", line 330, in sndrcv
    sndrcver = SndRcvHandler(*args, **kwargs)
  File "C:\projects\scapy\scapy\sendrecv.py", line 189, in __init__
    self._sndrcv_rcv(self._sndrcv_snd)
  File "C:\projects\scapy\scapy\sendrecv.py", line 317, in _sndrcv_rcv
    started_callback=callback
  File "C:\projects\scapy\scapy\sendrecv.py", line 1247, in _run
    for p in packets:
  File "C:\projects\scapy\scapy\sessions.py", line 56, in recv
    pkt = sock.recv()
  File "C:\projects\scapy\scapy\supersocket.py", line 180, in recv
    cls, val, ts = self.recv_raw(x)
  File "<input>", line 17, in recv_raw
  File "C:\Python37-x64\lib\queue.py", line 178, in get
    raise Empty
_queue.Empty
###(017)=[failed] Test negative response code don't retry if busy
>>> sock.rcvd_queue.put(b"\x7f\x01\x21")
>>> 
>>> e = MyTestCase()
>>> 
>>> e.execute(sock, EcuState(session=1), retry_if_busy_returncode=False)
more Socket <MockISOTPSocket object at 0x0000013F716E7F08> failed with ''. It was closed.
Traceback (most recent call last):
  File "<input>", line 2, in <module>
  File "C:\projects\scapy\scapy\contrib\automotive\scanner\enumerator.py", line 309, in execute
    res = self.sr1_with_retry_on_error(req, socket, state, timeout)
  File "C:\projects\scapy\scapy\contrib\automotive\scanner\enumerator.py", line 347, in sr1_with_retry_on_error
    chainEX=True, chainCC=True)
  File "C:\projects\scapy\scapy\supersocket.py", line 223, in sr1
    ans = sendrecv.sndrcv(self, *args, **kargs)[0]  # type: SndRcvList
  File "C:\projects\scapy\scapy\sendrecv.py", line 330, in sndrcv
    sndrcver = SndRcvHandler(*args, **kwargs)
  File "C:\projects\scapy\scapy\sendrecv.py", line 189, in __init__
    self._sndrcv_rcv(self._sndrcv_snd)
  File "C:\projects\scapy\scapy\sendrecv.py", line 317, in _sndrcv_rcv
    started_callback=callback
  File "C:\projects\scapy\scapy\sendrecv.py", line 1247, in _run
    for p in packets:
  File "C:\projects\scapy\scapy\sessions.py", line 56, in recv
    pkt = sock.recv()
  File "C:\projects\scapy\scapy\supersocket.py", line 180, in recv
    cls, val, ts = self.recv_raw(x)
  File "<input>", line 17, in recv_raw
  File "C:\Python37-x64\lib\queue.py", line 178, in get
    raise Empty
_queue.Empty

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the ServiceEnumerator execute and negative-response retry failures on Windows, then inspect scapy/contrib/automotive/scanner/enumerator.py along with the socket paths shown in scapy/supersocket.py, scapy/sendrecv.py, and scapy/sessions.py. Done means these enumerator tests pass on Windows without being disabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.