Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sigma/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ def convert(
output,
)
elif isinstance(result, dict):
click.echo(bytes(json.dumps(result, indent=json_indent), encoding))
click.echo(bytes(json.dumps(result, indent=json_indent), encoding), output)
else:
raise click.ClickException(
f"Backend returned unexpected format {str(type(result))}"
Expand Down
21 changes: 21 additions & 0 deletions tests/test_convert.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import pathlib

from click.testing import CliRunner
Expand Down Expand Up @@ -129,6 +130,26 @@ def test_convert_output_bytes(tmp_path):
assert "ParentImage" in open(test_file, "r").read()


def test_convert_output_dict_to_file(tmp_path, monkeypatch):
"""A backend returning a dict must honour --output/-o like all other result types."""
monkeypatch.setattr(
sigma.backends.test.backend.TextQueryTestBackend,
"convert",
lambda self, rule_collection, output_format=None, correlation_method=None, callback=None: {
"queries": ["ParentImage"]
},
)
cli = CliRunner()
test_file = tmp_path / "test.json"
result = cli.invoke(
convert,
["-t", "text_query_test", "-o", str(test_file), "tests/files/valid"],
)
assert result.exit_code == 0
assert "queries" not in result.stdout
assert json.loads(test_file.read_text()) == {"queries": ["ParentImage"]}


def test_convert_unknown_backend():
cli = CliRunner()
result = cli.invoke(
Expand Down
Loading