@@ -14,26 +14,14 @@ def test_send_file_to_usb_device(mocker):
14
14
mock_temp_dir = mocker .MagicMock ()
15
15
mock_temp_dir .__enter__ = mocker .MagicMock (return_value = 'mock_temp_dir' )
16
16
mocker .patch ('securedrop_client.export.TemporaryDirectory' , return_value = mock_temp_dir )
17
- export = Export (is_qubes = True )
17
+ export = Export ()
18
18
_run_disk_export = mocker .patch .object (export , '_run_disk_export' )
19
19
20
20
export .send_file_to_usb_device (['mock_filepath' ], 'mock passphrase' )
21
21
22
22
_run_disk_export .assert_called_once_with ('mock_temp_dir' , ['mock_filepath' ], 'mock passphrase' )
23
23
24
24
25
- def test_send_file_to_usb_device_not_qubes (mocker ):
26
- '''
27
- Ensure method returns without error and does not call qubes-only methods.
28
- '''
29
- export = Export (is_qubes = False )
30
- _run_disk_export = mocker .patch .object (export , '_run_disk_export' )
31
-
32
- export .send_file_to_usb_device (['mock_filepath' ], 'mock passphrase' )
33
-
34
- _run_disk_export .assert_not_called ()
35
-
36
-
37
25
def test_run_preflight_checks (mocker ):
38
26
'''
39
27
Ensure TemporaryDirectory is used when creating and sending the archives during the preflight
@@ -42,7 +30,7 @@ def test_run_preflight_checks(mocker):
42
30
mock_temp_dir = mocker .MagicMock ()
43
31
mock_temp_dir .__enter__ = mocker .MagicMock (return_value = 'mock_temp_dir' )
44
32
mocker .patch ('securedrop_client.export.TemporaryDirectory' , return_value = mock_temp_dir )
45
- export = Export (is_qubes = True )
33
+ export = Export ()
46
34
_run_usb_export = mocker .patch .object (export , '_run_usb_test' )
47
35
_run_disk_export = mocker .patch .object (export , '_run_disk_test' )
48
36
@@ -52,27 +40,13 @@ def test_run_preflight_checks(mocker):
52
40
_run_disk_export .assert_called_once_with ('mock_temp_dir' )
53
41
54
42
55
- def test_run_preflight_checks_not_qubes (mocker ):
56
- '''
57
- Ensure method returns without error and does not call qubes-only methods.
58
- '''
59
- export = Export (is_qubes = False )
60
- _run_usb_test = mocker .patch .object (export , '_run_usb_test' )
61
- _run_disk_test = mocker .patch .object (export , '_run_disk_test' )
62
-
63
- export .run_preflight_checks ()
64
-
65
- _run_usb_test .assert_not_called ()
66
- _run_disk_test .assert_not_called ()
67
-
68
-
69
43
def test__run_disk_export (mocker ):
70
44
'''
71
45
Ensure _export_archive and _create_archive are called with the expected parameters,
72
46
_export_archive is called with the return value of _create_archive, and
73
47
_run_disk_test returns without error if '' is the ouput status of _export_archive.
74
48
'''
75
- export = Export (is_qubes = False )
49
+ export = Export ()
76
50
export ._create_archive = mocker .MagicMock (return_value = 'mock_archive_path' )
77
51
export ._export_archive = mocker .MagicMock (return_value = '' )
78
52
@@ -94,7 +68,7 @@ def test__run_disk_export_raises_ExportError_if_not_empty_string(mocker):
94
68
'''
95
69
Ensure ExportError is raised if _run_disk_test returns anything other than ''.
96
70
'''
97
- export = Export (is_qubes = True )
71
+ export = Export ()
98
72
export ._create_archive = mocker .MagicMock (return_value = 'mock_archive_path' )
99
73
export ._export_archive = mocker .MagicMock (return_value = 'SOMETHING_OTHER_THAN_EMPTY_STRING' )
100
74
@@ -108,7 +82,7 @@ def test__run_disk_test(mocker):
108
82
_export_archive is called with the return value of _create_archive, and
109
83
_run_disk_test returns without error if 'USB_ENCRYPTED' is the ouput status of _export_archive.
110
84
'''
111
- export = Export (is_qubes = False )
85
+ export = Export ()
112
86
export ._create_archive = mocker .MagicMock (return_value = 'mock_archive_path' )
113
87
export ._export_archive = mocker .MagicMock (return_value = 'USB_ENCRYPTED' )
114
88
@@ -123,7 +97,7 @@ def test__run_disk_test_raises_ExportError_if_not_USB_ENCRYPTED(mocker):
123
97
'''
124
98
Ensure ExportError is raised if _run_disk_test returns anything other than 'USB_ENCRYPTED'.
125
99
'''
126
- export = Export (is_qubes = True )
100
+ export = Export ()
127
101
export ._create_archive = mocker .MagicMock (return_value = 'mock_archive_path' )
128
102
export ._export_archive = mocker .MagicMock (return_value = 'SOMETHING_OTHER_THAN_USB_ENCRYPTED' )
129
103
@@ -137,7 +111,7 @@ def test__run_usb_test(mocker):
137
111
_export_archive is called with the return value of _create_archive, and
138
112
_run_disk_test returns without error if 'USB_CONNECTED' is the return value of _export_archive.
139
113
'''
140
- export = Export (is_qubes = False )
114
+ export = Export ()
141
115
export ._create_archive = mocker .MagicMock (return_value = 'mock_archive_path' )
142
116
export ._export_archive = mocker .MagicMock (return_value = 'USB_CONNECTED' )
143
117
@@ -152,7 +126,7 @@ def test__run_usb_test_raises_ExportError_if_not_USB_CONNECTED(mocker):
152
126
'''
153
127
Ensure ExportError is raised if _run_disk_test returns anything other than 'USB_CONNECTED'.
154
128
'''
155
- export = Export (is_qubes = True )
129
+ export = Export ()
156
130
export ._create_archive = mocker .MagicMock (return_value = 'mock_archive_path' )
157
131
export ._export_archive = mocker .MagicMock (return_value = 'SOMETHING_OTHER_THAN_USB_CONNECTED' )
158
132
@@ -164,7 +138,7 @@ def test__create_archive(mocker):
164
138
'''
165
139
Ensure _create_archive creates an archive in the supplied directory.
166
140
'''
167
- export = Export (is_qubes = True )
141
+ export = Export ()
168
142
archive_path = None
169
143
with TemporaryDirectory () as temp_dir :
170
144
archive_path = export ._create_archive (temp_dir , 'mock.sd-export' , {})
@@ -175,7 +149,7 @@ def test__create_archive(mocker):
175
149
176
150
177
151
def test__create_archive_with_an_export_file (mocker ):
178
- export = Export (is_qubes = True )
152
+ export = Export ()
179
153
archive_path = None
180
154
with TemporaryDirectory () as temp_dir , NamedTemporaryFile () as export_file :
181
155
archive_path = export ._create_archive (temp_dir , 'mock.sd-export' , {}, [export_file .name ])
@@ -189,7 +163,7 @@ def test__create_archive_with_multiple_export_files(mocker):
189
163
'''
190
164
Ensure an archive
191
165
'''
192
- export = Export (is_qubes = True )
166
+ export = Export ()
193
167
archive_path = None
194
168
with TemporaryDirectory () as temp_dir , \
195
169
NamedTemporaryFile () as export_file_one , \
@@ -207,7 +181,7 @@ def test__export_archive(mocker):
207
181
Ensure the subprocess call returns the expected output.
208
182
'''
209
183
mocker .patch ('subprocess.check_output' , return_value = b'mock' )
210
- export = Export (is_qubes = True )
184
+ export = Export ()
211
185
status = export ._export_archive ('mock.sd-export' )
212
186
213
187
assert status == 'mock'
@@ -220,7 +194,7 @@ def test__export_archive_does_not_raise_ExportError_when_CalledProcessError(mock
220
194
mock_error = subprocess .CalledProcessError ('mock_cmd' , 123 )
221
195
mocker .patch ('subprocess.check_output' , side_effect = mock_error )
222
196
223
- export = Export (is_qubes = True )
197
+ export = Export ()
224
198
225
199
with pytest .raises (ExportError , match = 'CALLED_PROCESS_ERROR' ):
226
200
export ._export_archive ('mock.sd-export' )
@@ -230,10 +204,10 @@ def test__export_archive_with_evil_command(mocker):
230
204
'''
231
205
Ensure shell command is shell-escaped.
232
206
'''
233
- export = Export (is_qubes = False )
207
+ export = Export ()
234
208
check_output = mocker .patch ('subprocess.check_output' , return_value = b'' )
235
209
236
210
export ._export_archive ('somefile; rm -rf ~' )
237
211
238
212
check_output .assert_called_once_with (
239
- ['qvm-open-in-vm' , 'sd-export-usb' , "'somefile; rm -rf ~'" ], stderr = - 2 )
213
+ ['qvm-open-in-vm' , 'sd-export-usb' , "'somefile; rm -rf ~'" , '--view-only' ], stderr = - 2 )
0 commit comments