Skip to content
Snippets Groups Projects
Commit aa8d4527 authored by Pierre Lalet's avatar Pierre Lalet Committed by GitHub
Browse files

Merge pull request #389 from guedou/appveyor

AppVeyor support
parents 97326605 58fdc06c
No related branches found
No related tags found
No related merge requests found
environment:
# Python versions that will be tested
# Note: it defines variables that can be used later
matrix:
- PYTHON: "C:\\Python27-x64"
PYTHON_VERSION: "2.7.x"
PYTHON_ARCH: "64"
# There is no build phase for Scapy
build: off
install:
# Installing WinPcap directly does not work,
# see http://help.appveyor.com/discussions/problems/2280-winpcap-installation-issue
- choco install -y nmap
- refreshenv
# Install Python modules
- "%PYTHON%\\python -m pip install ecdsa pycrypto"
test_script:
# Set environment variables
- set PYTHONPATH=%APPVEYOR_BUILD_FOLDER%
- set PATH=%APPVEYOR_BUILD_FOLDER%;C:\Windows\System32\Npcap\;%PATH%
# Main unit tests
- "%PYTHON%\\python bin\\UTscapy -f text -t test\\regression.uts -F -K automaton -K mock_read_routes6_bsd || exit /b 42"
- 'del test\regression.uts'
# Secondary unit tests
- 'del test\bpf.uts' # Don't bother with BPF regression tests
- "for %%t in (test\\*.uts) do (%PYTHON%\\python bin\\UTscapy -f text -t %%t -F -K combined_modes || exit /b 42)"
# Contrib unit tests
- "for %%t in (scapy\\contrib\\*.uts) do (%PYTHON%\\python bin\\UTscapy -f text -t %%t -F -P \"load_contrib(\'%%~nt\')\" || exit /b 42)"
...@@ -85,7 +85,7 @@ if conf.use_winpcapy: ...@@ -85,7 +85,7 @@ if conf.use_winpcapy:
try: try:
p = devs p = devs
while p: while p:
if p.contents.name.endswith(iff): if p.contents.name.endswith(iff.guid):
a = p.contents.addresses a = p.contents.addresses
while a: while a:
if a.contents.addr.contents.sa_family == socket.AF_INET: if a.contents.addr.contents.sa_family == socket.AF_INET:
......
...@@ -236,7 +236,7 @@ class NetworkInterface(object): ...@@ -236,7 +236,7 @@ class NetworkInterface(object):
self._update_pcapdata() self._update_pcapdata()
try: try:
self.ip = socket.inet_ntoa(get_if_raw_addr(data['guid'])) self.ip = socket.inet_ntoa(get_if_raw_addr(data))
except (KeyError, AttributeError, NameError): except (KeyError, AttributeError, NameError):
pass pass
...@@ -461,3 +461,23 @@ def get_working_if(): ...@@ -461,3 +461,23 @@ def get_working_if():
return LOOPBACK_NAME return LOOPBACK_NAME
conf.iface = get_working_if() conf.iface = get_working_if()
def route_add_loopback():
"""Add a route to 127.0.0.1 to simplify unit tests on Windows"""
# Build the packed network addresses
loop_net = struct.unpack("!I", socket.inet_aton("127.0.0.0"))[0]
loop_mask = struct.unpack("!I", socket.inet_aton("255.0.0.0"))[0]
# Get the adapter from an existing route
if len(conf.route.routes) == 0:
return
adapter = conf.route.routes[0][3]
# Build and inject the fake route
loopback_route = (loop_net, loop_mask, "0.0.0.0", adapter, "127.0.0.1")
conf.route.routes.append(loopback_route)
# Flush the cache
conf.route.invalidate_cache()
...@@ -87,9 +87,15 @@ def inet_ntop(af, addr): ...@@ -87,9 +87,15 @@ def inet_ntop(af, addr):
hexstr = hex(value)[2:] hexstr = hex(value)[2:]
except TypeError: except TypeError:
raise Exception("Illegal syntax for IP address") raise Exception("Illegal syntax for IP address")
parts.append(hexstr.lower()) parts.append(hexstr.lstrip("0").lower())
result = ":".join(parts)
# Note: the returned address is never compact while ":::" in result:
return ":".join(parts) result = result.replace(":::", "::")
# Leaving out leading and trailing zeros is only allowed with ::
if result.endswith(":") and not result.endswith("::"):
result = result + "0"
if result.startswith(":") and not result.startswith("::"):
result = "0" + result
return result
else: else:
raise Exception("Address family not supported yet") raise Exception("Address family not supported yet")
...@@ -9,6 +9,7 @@ Unit testing infrastructure for Scapy ...@@ -9,6 +9,7 @@ Unit testing infrastructure for Scapy
import sys,getopt,imp import sys,getopt,imp
import bz2, base64, os.path, time, traceback, zlib, sha import bz2, base64, os.path, time, traceback, zlib, sha
from scapy.arch.consts import WINDOWS
#### Import tool #### #### Import tool ####
...@@ -293,6 +294,10 @@ def remove_empty_testsets(test_campaign): ...@@ -293,6 +294,10 @@ def remove_empty_testsets(test_campaign):
#### RUN CAMPAIGN ##### #### RUN CAMPAIGN #####
def run_campaign(test_campaign, get_interactive_session, verb=2): def run_campaign(test_campaign, get_interactive_session, verb=2):
if WINDOWS:
# Add a route to 127.0.0.1
from scapy.arch.windows import route_add_loopback
route_add_loopback()
passed=failed=0 passed=failed=0
if test_campaign.preexec: if test_campaign.preexec:
test_campaign.preexec_output = get_interactive_session(test_campaign.preexec.strip())[0] test_campaign.preexec_output = get_interactive_session(test_campaign.preexec.strip())[0]
......
...@@ -4562,6 +4562,7 @@ assert isinstance(pkt, DNS) and isinstance(pkt.payload, NoPayload) ...@@ -4562,6 +4562,7 @@ assert isinstance(pkt, DNS) and isinstance(pkt.payload, NoPayload)
+ Mocked read_routes() calls + Mocked read_routes() calls
= Truncated netstat -rn output on OS X = Truncated netstat -rn output on OS X
~ mock_read_routes6_bsd
import mock import mock
import StringIO import StringIO
...@@ -4618,6 +4619,7 @@ test_osx_netstat_truncated() ...@@ -4618,6 +4619,7 @@ test_osx_netstat_truncated()
+ Mocked read_routes6() calls + Mocked read_routes6() calls
= Preliminary definitions = Preliminary definitions
~ mock_read_routes6_bsd
import mock import mock
import StringIO import StringIO
...@@ -4647,6 +4649,7 @@ def check_mandatory_ipv6_routes(routes6): ...@@ -4647,6 +4649,7 @@ def check_mandatory_ipv6_routes(routes6):
= Mac OS X 10.9.5 = Mac OS X 10.9.5
~ mock_read_routes6_bsd
@mock.patch("scapy.arch.unix.in6_getifaddr") @mock.patch("scapy.arch.unix.in6_getifaddr")
@mock.patch("scapy.arch.unix.os") @mock.patch("scapy.arch.unix.os")
...@@ -4687,6 +4690,7 @@ test_osx_10_9_5() ...@@ -4687,6 +4690,7 @@ test_osx_10_9_5()
= Mac OS X 10.9.5 with global IPv6 connectivity = Mac OS X 10.9.5 with global IPv6 connectivity
~ mock_read_routes6_bsd
@mock.patch("scapy.arch.unix.in6_getifaddr") @mock.patch("scapy.arch.unix.in6_getifaddr")
@mock.patch("scapy.arch.unix.os") @mock.patch("scapy.arch.unix.os")
def test_osx_10_9_5_global(mock_os, mock_in6_getifaddr): def test_osx_10_9_5_global(mock_os, mock_in6_getifaddr):
...@@ -4734,6 +4738,7 @@ test_osx_10_9_5_global() ...@@ -4734,6 +4738,7 @@ test_osx_10_9_5_global()
= Mac OS X 10.10.4 = Mac OS X 10.10.4
~ mock_read_routes6_bsd
@mock.patch("scapy.arch.unix.in6_getifaddr") @mock.patch("scapy.arch.unix.in6_getifaddr")
@mock.patch("scapy.arch.unix.os") @mock.patch("scapy.arch.unix.os")
...@@ -4773,6 +4778,7 @@ test_osx_10_10_4() ...@@ -4773,6 +4778,7 @@ test_osx_10_10_4()
= FreeBSD 10.2 = FreeBSD 10.2
~ mock_read_routes6_bsd
@mock.patch("scapy.arch.unix.in6_getifaddr") @mock.patch("scapy.arch.unix.in6_getifaddr")
@mock.patch("scapy.arch.unix.os") @mock.patch("scapy.arch.unix.os")
...@@ -4811,6 +4817,7 @@ test_freebsd_10_2() ...@@ -4811,6 +4817,7 @@ test_freebsd_10_2()
= OpenBSD 5.5 = OpenBSD 5.5
~ mock_read_routes6_bsd
@mock.patch("scapy.arch.unix.OPENBSD") @mock.patch("scapy.arch.unix.OPENBSD")
@mock.patch("scapy.arch.unix.in6_getifaddr") @mock.patch("scapy.arch.unix.in6_getifaddr")
...@@ -4868,6 +4875,7 @@ test_openbsd_5_5() ...@@ -4868,6 +4875,7 @@ test_openbsd_5_5()
= NetBSD 7.0 = NetBSD 7.0
~ mock_read_routes6_bsd
@mock.patch("scapy.arch.unix.NETBSD") @mock.patch("scapy.arch.unix.NETBSD")
@mock.patch("scapy.arch.unix.in6_getifaddr") @mock.patch("scapy.arch.unix.in6_getifaddr")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment