From c522f5094a7e5957e1cadfc7c420227289908780 Mon Sep 17 00:00:00 2001 From: Ana Maria Martinez Gomez Date: Tue, 2 Mar 2021 19:46:21 +0100 Subject: [PATCH] Use -j option in test_backend_option Use `-j` option in `test_backend_option` to check the extractor and that rules have been extracted. This way we don't need to check if a concrete rule matches, but only that at least a rule matches. --- tests/test_main.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 9b9dc89f..6732de2d 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -7,6 +7,7 @@ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and limitations under the License. import sys +import json import textwrap import pytest @@ -367,15 +368,18 @@ def test_not_render_rules_also_matched(z9324d_extractor, capsys): assert "create TCP socket" in std.out -# It tests main works with different backends. It doesn't test that the backend -# is actually called. +# It tests main works with different backends def test_backend_option(capsys): if sys.version_info > (3, 0): path = get_data_path_by_name("pma16-01") - assert capa.main.main([path, "-b", capa.main.BACKEND_VIV]) == 0 + assert capa.main.main([path, "-j", "-b", capa.main.BACKEND_VIV]) == 0 std = capsys.readouterr() - assert "check for PEB NtGlobalFlag flag (24 matches)" in std.out + std_json = json.loads(std.out) + assert std_json["meta"]["analysis"]["extractor"] == "VivisectFeatureExtractor" + assert len(std_json["rules"]) > 0 - assert capa.main.main([path, "-b", capa.main.BACKEND_SMDA]) == 0 + assert capa.main.main([path, "-j", "-b", capa.main.BACKEND_SMDA]) == 0 std = capsys.readouterr() - assert "check for PEB NtGlobalFlag flag (24 matches)" in std.out + std_json = json.loads(std.out) + assert std_json["meta"]["analysis"]["extractor"] == "SmdaFeatureExtractor" + assert len(std_json["rules"]) > 0