mvt/tests/common/test_indicators.py

42 lines
1.7 KiB
Python
Raw Normal View History

2022-01-18 15:00:03 +00:00
# Mobile Verification Toolkit (MVT)
2023-09-09 15:55:27 +00:00
# Copyright (c) 2021-2023 The MVT Authors.
2022-01-18 15:00:03 +00:00
# Use of this software is governed by the MVT License 1.1 that can be found at
# https://license.mvt.re/1.1/
2021-12-16 11:50:12 +00:00
import logging
import os
from mvt.common.indicators import Indicators
2022-01-18 15:00:03 +00:00
2021-12-16 11:50:12 +00:00
class TestIndicators:
2022-01-07 16:51:21 +00:00
def test_parse_stix2(self, indicator_file):
2021-12-16 11:50:12 +00:00
ind = Indicators(log=logging)
2022-01-07 16:51:21 +00:00
ind.load_indicators_files([indicator_file], load_default=False)
2023-03-29 10:57:41 +00:00
assert ind.ioc_collections[0]["count"] == 5
2022-02-02 17:14:10 +00:00
assert len(ind.ioc_collections[0]["domains"]) == 1
assert len(ind.ioc_collections[0]["emails"]) == 1
assert len(ind.ioc_collections[0]["file_names"]) == 1
assert len(ind.ioc_collections[0]["processes"]) == 1
2023-03-29 10:57:41 +00:00
assert len(ind.ioc_collections[0]["android_property_names"]) == 1
2021-12-16 11:50:12 +00:00
2022-01-07 16:51:21 +00:00
def test_check_domain(self, indicator_file):
2021-12-16 11:50:12 +00:00
ind = Indicators(log=logging)
2022-01-07 16:51:21 +00:00
ind.load_indicators_files([indicator_file], load_default=False)
assert ind.check_domain(42) is None
assert ind.check_domain("https://www.example.org/foobar")
assert ind.check_domain("http://example.org:8080/toto")
assert ind.check_domain("https://github.com") is None
2021-12-16 11:50:12 +00:00
2023-03-29 10:57:41 +00:00
def test_check_android_property(self, indicator_file):
ind = Indicators(log=logging)
ind.load_indicators_files([indicator_file], load_default=False)
assert ind.check_android_property_name("sys.foobar")
assert ind.check_android_property_name("sys.soundsokay") is None
2022-01-07 16:51:21 +00:00
def test_env_stix(self, indicator_file):
os.environ["MVT_STIX2"] = indicator_file
2021-12-16 11:50:12 +00:00
ind = Indicators(log=logging)
ind.load_indicators_files([], load_default=False)
2023-03-29 10:57:41 +00:00
assert ind.total_ioc_count == 5