Files
mvt/tests/test_cli.py
T
Donncha Ó Cearbhaill c95e6659c6 Add a platform-neutral mvt command
Several MVT commands have nothing to do with the acquisition of one
platform, yet they were reachable only through mvt-ios and mvt-android.
Asking which version is installed or downloading the public indicators
meant picking one of the two platform commands arbitrarily, and each of
those tasks had to be written, documented and maintained twice.

Add a third console script, mvt, hosting the commands which belong to no
platform: version and download-iocs for now, with completion following
in a later commit.

Commands installed in the new mvt.cli_plugins entry-point group are
registered on mvt, and on mvt only, so that a command package chooses
the CLI each of its commands is added to: mvt.ios.cli_plugins for
mvt-ios, mvt.android.cli_plugins for mvt-android and mvt.cli_plugins for
mvt. A command wanted on both platform CLIs is registered in both
platform groups; no group adds a command to every CLI. The
MVT_CUSTOM_COMMANDS variable loads command files and folders into mvt
the way the platform variables already do for mvt-ios and mvt-android.

Run on its own, mvt prints the banner and its help instead of a usage
error. The help text reminds that the forensic analysis of an
acquisition runs through mvt-ios and mvt-android, so that the command
which knows nothing about acquisitions says where they are analysed.

version and download-iocs stay on mvt-ios and mvt-android for now, so
that no documented invocation stops working. They are to be dropped from
the platform CLIs in a later release, once mvt has been available long
enough for the change to be announced.

Unlike mvt-ios and mvt-android, which point at their subpackages, the
console script points at mvt.cli:main and the mvt package re-exports
nothing of it. Importing mvt has to stay cheap and free of side effects:
it is the package plugins import from, and pulling in Click, the CLI and
everything the commands import merely because something imported mvt
would work against that.

While here, give the version command of both platform CLIs the context
settings every other command already has, so that "mvt-ios version -h"
prints its help instead of failing on an unknown option.
2026-08-26 12:43:12 +02:00

50 lines
1.7 KiB
Python

# Mobile Verification Toolkit (MVT)
# Copyright (c) 2021-2026 The MVT Authors.
# Use of this software is governed by the MVT License 1.1 that can be found at
# https://license.mvt.re/1.1/
from click.testing import CliRunner
from mvt.cli import cli
from mvt.common.updates import IndicatorsUpdates
from mvt.common.version import MVT_VERSION
# Keep the banner of the group callback from checking for updates online.
OFFLINE = ["--disable-update-check", "--disable-indicator-update-check"]
class TestMvtCommand:
def test_running_mvt_alone_shows_the_logo_and_the_commands(self):
result = CliRunner().invoke(cli, OFFLINE)
assert result.exit_code == 0
logo_at = result.output.index("Mobile Verification Toolkit")
usage_at = result.output.index("Usage:")
assert logo_at < usage_at
assert "mvt-ios" in result.output and "mvt-android" in result.output
def test_help_reminds_where_the_analysis_runs(self):
result = CliRunner().invoke(cli, ["--help"])
assert result.exit_code == 0
assert "mvt-ios" in result.output
assert "mvt-android" in result.output
assert "check-*" in result.output
def test_version_prints_the_installed_version(self):
result = CliRunner().invoke(cli, [*OFFLINE, "version"])
assert result.exit_code == 0
assert f"Version: {MVT_VERSION}" in result.output
def test_download_iocs_updates_the_indicators(self, monkeypatch):
updates = []
monkeypatch.setattr(
IndicatorsUpdates, "update", lambda self: updates.append(self)
)
result = CliRunner().invoke(cli, [*OFFLINE, "download-iocs"])
assert result.exit_code == 0
assert len(updates) == 1