def test_actor_execution_with_unsigned_data(monkeypatch):
    def consume_unsigned_message_mocked(*models):
        installed_rpm = [
            RPM(name='sample02', version='0.1', release='1.sm01', epoch='1', packager=RH_PACKAGER, arch='noarch',
                pgpsig='SOME_OTHER_SIG_X'),
            RPM(name='sample04', version='0.1', release='1.sm01', epoch='1', packager=RH_PACKAGER, arch='noarch',
                pgpsig='SOME_OTHER_SIG_X'),
            RPM(name='sample06', version='0.1', release='1.sm01', epoch='1', packager=RH_PACKAGER, arch='noarch',
                pgpsig='SOME_OTHER_SIG_X'),
            RPM(name='sample08', version='0.1', release='1.sm01', epoch='1', packager=RH_PACKAGER, arch='noarch',
                pgpsig='SOME_OTHER_SIG_X')]
        yield InstalledUnsignedRPM(items=installed_rpm)

    monkeypatch.setattr(api, "consume", consume_unsigned_message_mocked)
    monkeypatch.setattr(api, "produce", produce_mocked())
    monkeypatch.setattr(api, "show_message", lambda x: True)
    monkeypatch.setattr(reporting, "create_report", create_report_mocked())

    packages = library.get_unsigned_packages()
    assert len(packages) == 4
    library.generate_report(packages)
    assert reporting.create_report.called == 1
    assert 'Packages not signed by Red Hat found' in reporting.create_report.report_fields['title']
    assert all(r['remediations']['context'][0] == 'yum' and
               r['remediations']['context'][1] == '-y' and
               r['remediations']['context'][2] == 'remove' and
               'sample' in r['remediations']['context'][3]
               for r in reporting.create_report.report_fields['remediations'])
Ejemplo n.º 2
0
def test_actor_execution_without_unsigned_data(monkeypatch):
    def consume_unsigned_message_mocked(*models):
        installed_rpm = []
        yield InstalledUnsignedRPM(items=installed_rpm)
    monkeypatch.setattr(api, "consume", consume_unsigned_message_mocked)
    monkeypatch.setattr(api, "produce", produce_mocked())
    monkeypatch.setattr(api, "show_message", lambda x: True)
    monkeypatch.setattr(reporting, "report_with_remediation", report_generic_mocked())

    packages = library.get_unsigned_packages()
    assert len(packages) == 0
    library.generate_report(packages)
    assert reporting.report_with_remediation.called == 0
def test_actor_execution_with_unsigned_data(monkeypatch):
    def consume_unsigned_message_mocked(*models):
        installed_rpm = [
            RPM(name='sample02',
                version='0.1',
                release='1.sm01',
                epoch='1',
                packager=RH_PACKAGER,
                arch='noarch',
                pgpsig='SOME_OTHER_SIG_X'),
            RPM(name='sample04',
                version='0.1',
                release='1.sm01',
                epoch='1',
                packager=RH_PACKAGER,
                arch='noarch',
                pgpsig='SOME_OTHER_SIG_X'),
            RPM(name='sample06',
                version='0.1',
                release='1.sm01',
                epoch='1',
                packager=RH_PACKAGER,
                arch='noarch',
                pgpsig='SOME_OTHER_SIG_X'),
            RPM(name='sample08',
                version='0.1',
                release='1.sm01',
                epoch='1',
                packager=RH_PACKAGER,
                arch='noarch',
                pgpsig='SOME_OTHER_SIG_X')
        ]
        yield InstalledUnsignedRPM(items=installed_rpm)

    monkeypatch.setattr(api, "consume", consume_unsigned_message_mocked)
    monkeypatch.setattr(api, "produce", produce_mocked())
    monkeypatch.setattr(reporting, "report_with_remediation",
                        report_generic_mocked())

    packages = library.get_unsigned_packages()
    assert len(packages) == 4
    library.generate_report(packages)
    assert reporting.report_with_remediation.called == 1
    assert 'Packages not signed by Red Hat found' in reporting.report_with_remediation.report_fields[
        'title']
    assert 'yum remove sample' in reporting.report_with_remediation.report_fields[
        'remediation']