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.
This commit is contained in:
Ana Maria Martinez Gomez
2021-03-02 19:46:21 +01:00
parent 29b6772721
commit c522f5094a

View File

@@ -7,6 +7,7 @@
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 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. # See the License for the specific language governing permissions and limitations under the License.
import sys import sys
import json
import textwrap import textwrap
import pytest import pytest
@@ -367,15 +368,18 @@ def test_not_render_rules_also_matched(z9324d_extractor, capsys):
assert "create TCP socket" in std.out assert "create TCP socket" in std.out
# It tests main works with different backends. It doesn't test that the backend # It tests main works with different backends
# is actually called.
def test_backend_option(capsys): def test_backend_option(capsys):
if sys.version_info > (3, 0): if sys.version_info > (3, 0):
path = get_data_path_by_name("pma16-01") 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() 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() 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