1
1
import os
2
2
import os .path
3
+ import shutil
3
4
import zipfile
4
5
from unittest .mock import patch
5
6
6
7
import pytest
7
8
import requests
8
-
9
9
from quark .report import Report
10
10
11
11
@@ -19,7 +19,8 @@ def invalid_file(tempfile):
19
19
@pytest .fixture (scope = "module" )
20
20
def sample_apk_file ():
21
21
APK_SOURCE = (
22
- "https://github.com/quark-engine/" "apk-malware-samples/raw/master/Ahmyth.apk"
22
+ "https://github.com/quark-engine/"
23
+ "apk-malware-samples/raw/master/Ahmyth.apk"
23
24
)
24
25
APK_NAME = "Ahmyth.apk"
25
26
@@ -130,6 +131,67 @@ def test_analysis_with_rule_directory(
130
131
assert mock_run .call_count == num_of_rules
131
132
assert mock_generate_report .call_count == num_of_rules
132
133
134
+ def test_analysis_without_specified_rizin_path (
135
+ self , sample_apk_file , sample_rule_directory
136
+ ):
137
+ expected_path = shutil .which ("rizin" )
138
+
139
+ with patch ("quark.core.quark.Quark.run" ) as mock_run :
140
+ with patch (
141
+ "quark.core.quark.Quark.generate_json_report"
142
+ ) as mock_generate_report :
143
+ sample_report = Report ()
144
+ sample_report .analysis (
145
+ sample_apk_file ,
146
+ sample_rule_directory ,
147
+ core_library = "rizin" ,
148
+ )
149
+
150
+ assert sample_report .rizin_path == expected_path
151
+
152
+ mock_run .assert_called_once ()
153
+ mock_generate_report .assert_called_once ()
154
+
155
+ def test_analysis_with_specified_rizin_path (
156
+ self , sample_apk_file , sample_rule_directory
157
+ ):
158
+ rizin_path = shutil .which ("rizin" )
159
+
160
+ with patch ("quark.core.quark.Quark.run" ) as mock_run :
161
+ with patch (
162
+ "quark.core.quark.Quark.generate_json_report"
163
+ ) as mock_generate_report :
164
+ with patch (
165
+ "quark.utils.tools.find_rizin_instance"
166
+ ) as mock_find_rizin :
167
+
168
+ sample_report = Report ()
169
+ sample_report .analysis (
170
+ sample_apk_file ,
171
+ sample_rule_directory ,
172
+ core_library = "rizin" ,
173
+ rizin_path = rizin_path ,
174
+ )
175
+
176
+ assert sample_report .rizin_path == rizin_path
177
+
178
+ mock_find_rizin .assert_not_called ()
179
+ mock_run .assert_called_once ()
180
+ mock_generate_report .assert_called_once ()
181
+
182
+ def test_analysis_with_invalid_rizin_path (
183
+ self , sample_report , sample_apk_file , sample_rule_directory
184
+ ):
185
+ invalid_path = "INVALID_PATH"
186
+
187
+ with pytest .raises (ValueError ):
188
+ sample_report .analysis (
189
+ sample_apk_file ,
190
+ sample_rule_directory ,
191
+ core_library = "rizin" ,
192
+ rizin_path = invalid_path ,
193
+ )
194
+
133
195
def test_get_report_with_invalid_type (self , sample_report ):
134
196
with pytest .raises (ValueError ):
135
197
sample_report .get_report (None )
0 commit comments