示例#1
0
def test_build_pdf_error(tmpdir, monkeypatch):
    monkeypatch.setattr(
        'helperFunctions.pdf.execute_shell_command_get_return_code', lambda _:
        ('', 1))

    with pytest.raises(RuntimeError):
        build_pdf_report(TEST_FW, Path(str(tmpdir)))
示例#2
0
def test_build_pdf_report(tmpdir):
    pdf_path = build_pdf_report(TEST_FW, Path(str(tmpdir)))

    assert get_file_type_from_binary(
        pdf_path.read_bytes())['mime'] == 'application/pdf'
    assert pdf_path.name == '{}_analysis_report.pdf'.format(
        TEST_FW.device_name.replace(' ', '_'))
示例#3
0
def test_build_pdf_report(tmpdir, monkeypatch):
    def create_stub_file(_):
        Path(str(tmpdir), 'pdf', 'any.pdf').write_bytes(b'\x00')
        return '', 0

    monkeypatch.setattr(
        'helperFunctions.pdf.execute_shell_command_get_return_code',
        create_stub_file)

    binary, pdf_path = build_pdf_report(TEST_FW, Path(str(tmpdir)))

    assert binary == b'\x00'
    assert pdf_path == Path(str(tmpdir), 'pdf', 'any.pdf')
示例#4
0
    def _download_pdf_report(self, uid):
        with ConnectTo(FrontEndDbInterface, self._config) as sc:
            object_exists = sc.existence_quick_check(uid)
        if not object_exists:
            return render_template('uid_not_found.html', uid=uid)

        with ConnectTo(FrontEndDbInterface, self._config) as connection:
            firmware = connection.get_complete_object_including_all_summaries(uid)

        try:
            with TemporaryDirectory(dir=get_temp_dir_path(self._config)) as folder:
                pdf_path = build_pdf_report(firmware, folder)
                binary = pdf_path.read_bytes()
        except RuntimeError as error:
            return render_template('error.html', message=str(error))

        response = make_response(binary)
        response.headers['Content-Disposition'] = 'attachment; filename={}'.format(pdf_path.name)

        return response