Skip to content

Commit

Permalink
rest put firmware: added unknown plugin test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jstucke committed Oct 19, 2023
1 parent f0ea020 commit 5d40a33
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions src/test/integration/web_interface/rest/test_rest_firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
from test.integration.web_interface.rest.base import RestTestBase


UPLOAD_DATA = {
'binary': standard_b64encode(b'test_file_content').decode(),
'file_name': 'test_file.txt',
'device_name': 'test_device',
'device_part': 'full',
'device_class': 'test_class',
'version': '1',
'vendor': 'test_vendor',
'release_date': '1970-01-01',
'tags': '',
'requested_analysis_systems': ['dummy'],
}


@pytest.mark.usefixtures('database_interfaces')
class TestRestFirmware(RestTestBase):
def test_rest_firmware_existing(self, backend_db):
Expand Down Expand Up @@ -52,34 +66,28 @@ def test_rest_upload_valid(self, monkeypatch):
'intercom.front_end_binding.InterComFrontEndBinding.get_available_analysis_plugins',
lambda _: ['dummy'],
)
data = {
'binary': standard_b64encode(b'test_file_content').decode(),
'file_name': 'test_file.txt',
'device_name': 'test_device',
'device_part': 'full',
'device_class': 'test_class',
'version': '1',
'vendor': 'test_vendor',
'release_date': '1970-01-01',
'tags': '',
'requested_analysis_systems': ['dummy'],
}
rv = self.test_client.put('/rest/firmware', json=data, follow_redirects=True)
rv = self.test_client.put('/rest/firmware', json=UPLOAD_DATA, follow_redirects=True)
assert b'c1f95369a99b765e93c335067e77a7d91af3076d2d3d64aacd04e1e0a810b3ed_17' in rv.data
assert b'"status": 0' in rv.data

def test_rest_upload_invalid(self):
def test_upload_unknown_plugin(self, monkeypatch):
monkeypatch.setattr(
'intercom.front_end_binding.InterComFrontEndBinding.get_available_analysis_plugins',
lambda _: ['plugin_1'],
)
data = {
'binary': standard_b64encode(b'test_file_content').decode(),
'file_name': 'test_file.txt',
'device_name': 'test_device',
'device_part': 'test_part',
'device_class': 'test_class',
'vendor': 'test_vendor',
'release_date': '01.01.1970',
'tags': '',
'requested_analysis_systems': ['dummy'],
**UPLOAD_DATA,
'requested_analysis_systems': ['plugin_1', 'plugin_2'],
}
response = self.test_client.put('/rest/firmware', json=data, follow_redirects=True).json
assert 'error_message' in response
assert 'The requested analysis plugins are not available' in response['error_message']
assert 'plugin_2' in response['error_message']
assert 'plugin_1' not in response['error_message']

def test_rest_upload_invalid(self):
data = {**UPLOAD_DATA}
data.pop('version')
rv = self.test_client.put('/rest/firmware', json=data, follow_redirects=True)
assert rv.json['message'] == 'Input payload validation failed'
assert 'version' in rv.json['errors']
Expand Down

0 comments on commit 5d40a33

Please sign in to comment.