def test_request_with_bad_recursive_flag(test_app):
    result = decode_response(test_app.get('/rest/firmware?recursive=true'))
    assert result['status'] == 1
    assert 'only permissible with non-empty query' in result['error_message']

    query = json.dumps({'processed_analysis.file_type.full': {'$regex': 'arm', '$options': 'si'}})
    result = decode_response(test_app.get('/rest/firmware?recursive=true&query={}'.format(quote(query))))
    assert result['status'] == 0
Пример #2
0
def test_empty_response(test_app):
    response = decode_response(test_app.get('/rest/firmware?offset=1'))
    assert 'error_message' not in response
    assert len(response['uids']) == 0

    response = decode_response(test_app.get('/rest/firmware?limit=1'))
    assert 'error_message' not in response
    assert len(response['uids']) == 0
Пример #3
0
def test_request_with_inverted_flag(test_app):
    result = decode_response(
        test_app.get('/rest/firmware?inverted=true&query={"foo": "bar"}'))
    assert result['status'] == 1
    assert 'Inverted flag can only be used with recursive' in result[
        'error_message']

    result = decode_response(
        test_app.get(
            '/rest/firmware?inverted=true&recursive=true&query={"foo": "bar"}')
    )
    assert result['status'] == 0
def test_request_with_unpacking(test_app):
    scheduled_analysis = ['unpacker', 'optional_plugin']
    requested_analysis = json.dumps(scheduled_analysis)
    result = decode_response(test_app.put('/rest/firmware/{}?update={}'.format(TEST_FW.uid, quote(requested_analysis))))
    assert result['status'] == 0
    assert sorted(result['request']['update']) == sorted(scheduled_analysis)
    assert 'unpacker' in result['request']['update']
Пример #5
0
def test_request_update(test_app):
    requested_analysis = json.dumps(['optional_plugin'])
    result = decode_response(
        test_app.put(
            f'/rest/firmware/{TEST_FW.uid}?update={quote(requested_analysis)}')
    )
    assert result['status'] == 0
 def test_get_rest(self):
     result = decode_response(
         self.test_client.get(
             '/plugins/file_system_metadata/rest/{}'.format('foo')))
     assert AnalysisPlugin.NAME in result
     assert 'some_file' in result[AnalysisPlugin.NAME]
     assert 'test_result' in result[AnalysisPlugin.NAME]['some_file']
Пример #7
0
def test_request_with_query(test_app):
    query = {'vendor': 'no real vendor'}
    quoted_query = quote(json.dumps(query))
    response = decode_response(
        test_app.get('/rest/firmware?query={}'.format(quoted_query)))
    assert 'query' in response['request'].keys()
    assert response['request']['query'] == query
Пример #8
0
def test_submit_no_release_date(test_app):
    request_data = {**TEST_FW_PAYLOAD}
    request_data.pop('release_date')
    result = decode_response(test_app.put('/rest/firmware', json=request_data))
    assert result['status'] == 0
    assert isinstance(result['request']['release_date'], str)
    assert result['request']['release_date'] == '1970-01-01'
Пример #9
0
 def test__get_rest(self):
     result = decode_response(
         self.test_client.get('/plugins/qemu_exec/rest/{}'.format('foo')))
     assert AnalysisPlugin.NAME in result
     assert 'parent_uid' in result[AnalysisPlugin.NAME]
     assert result[AnalysisPlugin.NAME]['parent_uid'] == {
         'executable': False
     }
Пример #10
0
def test_submit_missing_item(test_app):
    request_data = {
        'binary': standard_b64encode(b'\x01\x23\x45\x67\x89').decode(),
        'file_name': 'no_real_file',
        'device_name': 'no real device',
        'device_class': 'no real class',
        'firmware_version': 'no.real.version',
        'release_date': '01.01.1970',
        'requested_analysis_systems': ['file_type']
    }  # vendor missing
    result = decode_response(test_app.put('/rest/firmware', data=json.dumps(request_data)))
    assert result['status'] == 1
Пример #11
0
    def test_import_module_routes__rest(self):
        dummy_endpoint = 'plugins/dummy/rest'
        plugin_routes = PluginRoutesMock(self.app, self.config, api=self.api)

        assert dummy_endpoint not in self._get_app_endpoints(self.app)

        plugin_routes._import_module_routes('dummy', 'analysis')

        test_client = self.app.test_client()
        result = decode_response(test_client.get(dummy_endpoint))
        assert 'dummy' in result
        assert 'rest' in result['dummy']
Пример #12
0
def test_non_existing_uid(test_app):
    result = decode_response(test_app.get('/rest/firmware/some_uid'))
    assert 'No firmware with UID some_uid' in result['error_message']
Пример #13
0
def test_bad_paging(test_app):
    response = decode_response(test_app.get('/rest/firmware?offset=X&limit=V'))
    assert 'error_message' in response
    assert 'Malformed' in response['error_message']
Пример #14
0
def test_request_update_missing_parameter(test_app):  # pylint: disable=invalid-name
    result = decode_response(test_app.put(f'/rest/firmware/{TEST_FW.uid}'))
    assert result['status'] == 1
    assert 'missing parameter: update' in result['error_message']
Пример #15
0
def test_bad_query(test_app):
    search_query = quote('{\'vendor\': \'no real vendor\'}')
    result = decode_response(
        test_app.get('/rest/firmware?query={}'.format(search_query)))
    assert 'Query must be a json' in result['error_message']
Пример #16
0
def test_request_with_summary_parameter(test_app):
    result = decode_response(
        test_app.get('/rest/firmware/{}?summary=true'.format(TEST_FW.uid)))
    assert 'firmware' in result
Пример #17
0
def test_submit_success(test_app):
    result = decode_response(
        test_app.put('/rest/firmware', json=TEST_FW_PAYLOAD))
    assert result['status'] == 0
Пример #18
0
def test_submit_empty_data(test_app):
    result = decode_response(
        test_app.put('/rest/firmware', data=json.dumps(dict())))
    assert result['status'] == 1
Пример #19
0
def test_request_update_bad_parameter(test_app):
    result = decode_response(
        test_app.put('/rest/firmware/{}?update=no_list'.format(TEST_FW.uid)))
    assert result['status'] == 1
    assert 'has to be a list' in result['error_message']
 def test_get_rest__no_result(self):
     result = decode_response(
         self.test_client.get(
             '/plugins/file_system_metadata/rest/{}'.format('not_found')))
     assert AnalysisPlugin.NAME in result
     assert result[AnalysisPlugin.NAME] == {}
Пример #21
0
def test_bad_put_request(test_app):
    result = decode_response(test_app.put('/rest/firmware'))
    assert 'Input payload validation failed' in result['message']
Пример #22
0
def test_submit_empty_data(test_app):
    result = decode_response(
        test_app.put('/rest/firmware', data=json.dumps({})))
    assert 'Input payload validation failed' in result['message']
Пример #23
0
def test_submit_missing_item(test_app):
    request_data = {**TEST_FW_PAYLOAD}
    request_data.pop('vendor')
    result = decode_response(test_app.put('/rest/firmware', json=request_data))
    assert 'Input payload validation failed' in result['message']
    assert 'vendor' in result['errors']
Пример #24
0
def test_submit_invalid_binary(test_app):
    request_data = {**TEST_FW_PAYLOAD, 'binary': 'invalid_base64'}
    result = decode_response(test_app.put('/rest/firmware', json=request_data))
    assert 'Could not parse binary (must be valid base64!)' in result[
        'error_message']
Пример #25
0
def test_successful_uid_request(test_app):
    result = decode_response(
        test_app.get('/rest/firmware/{}'.format(TEST_FW.uid)))
    assert 'firmware' in result
    assert all(section in result['firmware']
               for section in ['meta_data', 'analysis'])
Пример #26
0
def test_request_update_missing_parameter(test_app):
    result = decode_response(
        test_app.put('/rest/firmware/{}'.format(TEST_FW.uid)))
    assert result['status'] == 1
    assert 'missing parameter: update' in result['error_message']
Пример #27
0
def test_bad_put_request(test_app):
    result = decode_response(test_app.put('/rest/firmware'))
    assert 'Request should be' in result['error_message']
Пример #28
0
def test_request_with_summary_parameter(test_app):  # pylint: disable=invalid-name
    result = decode_response(
        test_app.get(f'/rest/firmware/{TEST_FW.uid}?summary=true'))
    assert 'firmware' in result
Пример #29
0
def test_successful_request(test_app):
    response = decode_response(test_app.get('/rest/firmware'))
    assert 'error_message' not in response
    assert 'uids' in response
    assert len(response['uids']) == 1
Пример #30
0
 def test__get_rest__no_result(self):
     result = decode_response(self.test_client.get('/plugins/qemu_exec/rest/{}'.format('not_found')))
     assert AnalysisPlugin.NAME in result
     assert result[AnalysisPlugin.NAME] == {}