Ejemplo n.º 1
0
    def test_clean_stale_issues(self):
        from security_monkey.common.audit_issue_cleanup import clean_stale_issues

        items = Item.query.all()
        assert len(items) == 1
        item = items[0]
        item.issues.append(ItemAudit(score=1, issue='Test Issue', item_id=item.id,
                                     auditor_setting=AuditorSettings(disabled=False,
                                                                     technology=self.technology,
                                                                     account=self.account,
                                                                     auditor_class='MockAuditor1')))

        item.issues.append(ItemAudit(score=1, issue='Issue with missing auditor', item_id=item.id,
                                     auditor_setting=AuditorSettings(disabled=False,
                                                                     technology=self.technology,
                                                                     account=self.account,
                                                                     auditor_class='MissingAuditor')))

        db.session.commit()

        clean_stale_issues()
        items = Item.query.all()
        assert len(items) == 1
        item = items[0]
        assert len(item.issues) == 1
        assert item.issues[0].issue == 'Test Issue'
Ejemplo n.º 2
0
    def _set_auditor_setting_for_issue(self, issue):

        auditor_setting = AuditorSettings.query.filter(
            and_(AuditorSettings.tech_id == issue.item.tech_id,
                 AuditorSettings.account_id == issue.item.account_id,
                 AuditorSettings.issue_text == issue.issue)).first()

        if auditor_setting:
            auditor_setting.issues.append(issue)
            db.session.add(auditor_setting)
            return auditor_setting

        auditor_setting = AuditorSettings(tech_id=issue.item.tech_id,
                                          account_id=issue.item.account_id,
                                          disabled=False,
                                          issue_text=issue.issue)

        auditor_setting.issues.append(issue)
        db.session.add(auditor_setting)
        db.session.commit()
        db.session.refresh(auditor_setting)

        app.logger.debug("Created AuditorSetting: {} - {} - {}".format(
            issue.issue, self.index, issue.item.account.name))

        return auditor_setting
Ejemplo n.º 3
0
    def _set_auditor_setting_for_issue(self, issue):

        auditor_setting = AuditorSettings.query.filter(
            and_(
                # TODO: This MUST be modified when switching to new issue logic in future:
                #       Currently there should be exactly 1 item in the list of sub_items:
                AuditorSettings.tech_id == issue.item.tech_id,
                AuditorSettings.account_id == issue.item.account_id,
                AuditorSettings.issue_text == issue.issue,
                AuditorSettings.auditor_class ==
                self.__class__.__name__)).first()

        if auditor_setting:
            auditor_setting.issues.append(issue)
            db.session.add(auditor_setting)
            return auditor_setting

        auditor_setting = AuditorSettings(
            # TODO: This MUST be modified when switching to new issue logic in future:
            #       Currently there should be exactly 1 item in the list of sub_items:
            tech_id=issue.item.tech_id,
            account_id=issue.item.account_id,
            disabled=False,
            issue_text=issue.issue,
            auditor_class=self.__class__.__name__)

        auditor_setting.issues.append(issue)
        db.session.add(auditor_setting)
        db.session.commit()
        db.session.refresh(auditor_setting)

        app.logger.debug("Created AuditorSetting: {} - {} - {}".format(
            issue.issue,
            self.index,
            # TODO: This MUST be modified when switching to new issue logic in future:
            #       Currently there should be exactly 1 item in the list of sub_items:
            issue.item.account.name))

        return auditor_setting