zeek/testing/btest
Arne Welzel 5659cf18f8 MIME: Cap nested MIME analysis depth to 100
OSS-Fuzz managed to produce a MIME multipart message construction with
thousands of nested entities (or that's what Zeek makes out of it anyhow).
Prevent such deep analysis by capping at a nesting depth of 100,
preventing unnecessary resource usage. A new weird named exceeded_mime_max_depth
is reported when this limit is reached.

This change reduces the runtime of the OSS-Fuzz reproducer from ~45 seconds
to ~2.5 seconds.

The test PCAP was produced from a Python script using the email package
and sending the rendered version via POST to a HTTP server.

Closes #208

(cherry picked from commit 4e5849fe82c6097df5d25cd1a74d69ab4fa50f46)
2024-01-19 08:22:19 -07:00
..
af_packet Include in Jan's AF_PACKET plugin as builtin plugin 2022-10-13 13:29:27 +02:00
Baseline MIME: Cap nested MIME analysis depth to 100 2024-01-19 08:22:19 -07:00
Baseline.cpp BTest baseline updates for -O gen-C++ 2023-05-05 12:03:00 -07:00
Baseline.dup
Baseline.inline
Baseline.opt
Baseline.usage
Baseline.xform
Baseline.zam BTest baseline updates for ZAM 2023-05-04 10:52:38 -07:00
bifs Revert "Merge remote-tracking branch 'origin/topic/vern/at-if-analyze'" 2023-05-31 09:20:33 +02:00
broker remote_event_ts_compat: Fix NETWORK_TIMESTAMP to NetworkTimestamp 2023-05-11 14:58:37 +02:00
core Fix tests so they work both with GNU and BSD tools 2024-01-18 14:09:51 -08:00
coverage Add test-all-policy-cluster 2023-05-31 00:37:30 -07:00
doc maintenance updates for -O C++ 2022-12-04 17:59:14 -08:00
Files/mmdb Merge remote-tracking branch 'origin/topic/awelzel/mmdb-fix-and-tests' 2023-10-24 13:49:25 -07:00
javascript Add experimental JavaScript support when libnode is available 2023-04-14 11:26:41 +02:00
language Revert "Merge remote-tracking branch 'origin/topic/vern/at-if-analyze'" 2023-05-31 09:20:33 +02:00
misc Add zeek -V/--build-info 2023-02-13 12:23:29 +01:00
opt annotated scripts to skip when testing compilation-to-C++ 2022-09-16 16:47:43 -07:00
plugins Modernize plugin test. 2023-05-15 16:08:47 +02:00
scripts MIME: Cap nested MIME analysis depth to 100 2024-01-19 08:22:19 -07:00
signatures Merge branch 'topic/xb-anssi/http_signature_body_end_match' of https://github.com/xb-anssi/zeek 2024-01-12 11:19:58 -07:00
spicy Merge remote-tracking branch 'origin/topic/bbannier/issue-3279' 2023-10-16 13:15:40 -07:00
supervisor Revert "Merge remote-tracking branch 'origin/topic/vern/at-if-analyze'" 2023-05-31 09:20:33 +02:00
telemetry
Traces MIME: Cap nested MIME analysis depth to 100 2024-01-19 08:22:19 -07:00
zam testing/btest: Add ZAM basic test 2023-01-09 12:30:26 +01:00
.gitignore
btest.cfg btest.cfg: Set HILTI_CXX_COMPILER_LAUNCHER based on build/CMakeCache.txt 2023-05-25 13:42:12 +02:00
Makefile
random.seed
README

This a test suite of small "unit tests" that verify individual pieces of Zeek
functionality.  They all utilize BTest, a simple framework/driver for
writing unit tests.  More information about BTest can be found at
https://github.com/zeek/btest

The test suite's BTest configuration is handled through the
``btest.cfg`` file.  Of particular interest is the "TestDirs" settings,
which specifies which directories BTest will recursively search for
test files.

Significant Subdirectories
==========================

* Baseline/
	Validated baselines for comparison against the output of each
	test on future runs. If the new output differs from the Baseline
	output, then the test fails.

* Traces/
	Packet captures utilized by the various BTest tests.

* scripts/
	This hierarchy of tests emulates the hierarchy of the Zeek scripts/
	directory.

* coverage/
	This collection of tests relates to checking whether we're covering
	everything we want to in terms of tests, documentation, and which
	scripts get loaded in different Zeek configurations.  These tests are
	more prone to fail as new Zeek scripts are developed and added to the
	distribution -- checking the individual test's comments is the best
	place to check for more details on what exactly the test is checking
	and hints on how to fix it when it fails.

Running Tests
=============

Either use the ``make all`` or ``make brief`` ``Makefile`` targets, or
run ``btest`` directly with desired options/arguments.  Examples:

* btest <no arguments>
	If you simply execute btest in this directory with no arguments,
	then all directories listed as "TestDirs" in btest.cfg will be
	searched recursively for test files.


* btest <btest options> test_directory
	You can specify a directory on the command line to run just the
	tests contained in that directory. This is useful if you wish to
	run all of a given type of test, without running all the tests
	there are. For example, "btest scripts" will run all of the Zeek
	script unit tests.


* btest <btest options> test_directory/test_file
	You can specify a single test file to run just that test. This
	is useful when testing a single failing test or when developing
	a new test.

Adding Tests
=============

See either the `BTest documentation
<https://github.com/zeek/btest>`_ or the existing unit
tests for examples of what they actually look like.  The essential
components of a new test include:

* A test file in one of the subdirectories listed in the ``TestDirs``
  of the ``btest.cfg`` file.

* If the unit test requires a known-good baseline output against which
  future tests will be compared (via ``btest-diff``), then that baseline
  output will need to live in the ``Baseline`` directory.  Manually
  adding that is possible, but it's easier to just use the ``-u`` or
  ``-U`` options of ``btest`` to do it for you (using ``btest -d`` on a
  test for which no baseline exists will show you the output so it can
  be verified first before adding/updating the baseline output).

If you create a new top-level testing directory for collecting related
tests, then you'll need to add it to the list of ``TestDirs`` in
``btest.cfg``. Do this only if your test really doesn't fit logically in
any of the extant directories.