#!/bin/sh

set -e
set -x
# Match the build-time environment from debian/rules: without a selected
# txaio framework, txaio.make_logger() raises in the CVE-2026-77528
# regression test.
export USE_ASYNCIO=1
export OSLO_PACKAGE_VERSION=$(dpkg-parsechangelog -SVersion | sed -e 's/^[[:digit:]]*://' -e 's/[-].*//' -e 's/~git.*//' -e 's/~/.0/' -e 's/+dfsg1//' -e 's/+ds1//' | head -n 1)

# The WebSocket test dir is ignored in the main pytest run, but the
# security regression test for CVE-2026-77528 (maxMessagePayloadSize
# enforcement against the uncompressed message size) is backend-neutral
# and standalone: run it explicitly after the main run. The
# debian/test-stubs dir shadows python3-snappy, whose StreamCompressor C
# extension is broken on this suite's Python (see
# debian/test-stubs/snappy.py), making the test skip the
# permessage-snappy subtests.
CWD=$(pwd)
PYTHON3S=$(py3versions -vs)
for i in ${PYTHON3S} ; do
	python${i} setup.py install --install-layout=deb --root ${CWD}/debian/tmp
	PYTHONPATH=${CWD}/debian/tmp/usr/lib/python3/dist-packages \
		python$i -m pytest -Wignore -v --ignore=./autobahn/twisted --ignore=./autobahn/wamp --ignore=./autobahn/websocket --ignore=./autobahn/xbr autobahn
	PYTHONPATH=${CWD}/debian/tmp/usr/lib/python3/dist-packages:${CWD}/debian/test-stubs \
		python$i -m pytest -Wignore -v autobahn/websocket/test/test_websocket_max_message_size.py
done
