Ejemplo n.º 1
0
def update_affected_commits(bug_id, result, project, ecosystem, public):
  """Update affected commits."""
  to_put = []
  to_delete = []

  for commit in result.commits:
    affected_commit = osv.AffectedCommit(
        id=bug_id + '-' + commit,
        bug_id=bug_id,
        commit=commit,
        confidence=result.confidence,
        project=project,
        ecosystem=ecosystem,
        public=public)

    to_put.append(affected_commit)

  # Delete any affected commits that no longer apply. This can happen in cases
  # where a FixResult comes in later and we had previously marked a commit prior
  # to the fix commit as being affected by a vulnerability.
  for existing in osv.AffectedCommit.query(osv.AffectedCommit.bug_id == bug_id):
    if existing.commit not in result.commits:
      to_delete.append(existing.key)

  ndb.put_multi(to_put)
  ndb.delete_multi(to_delete)
Ejemplo n.º 2
0
    def setUp(self):
        tests.reset_emulator()
        self.clone_repository_patcher = mock.patch('pygit2.clone_repository')
        self.maxDiff = None

        mock_clone = self.clone_repository_patcher.start()
        mock_clone.return_value = pygit2.Repository('osv-test')

        patcher = mock.patch('osv.types.utcnow')
        mock_utcnow = patcher.start()
        mock_utcnow.return_value = datetime.datetime(2021, 1, 1)
        self.addCleanup(patcher.stop)

        allocated_bug = osv.Bug(id='2020-1337',
                                timestamp=datetime.datetime(2020, 1, 1),
                                source_id='oss-fuzz:123',
                                status=osv.BugStatus.UNPROCESSED,
                                public=False)
        allocated_bug.put()

        should_be_deleted = osv.AffectedCommit(id='2020-1337-abcd',
                                               bug_id='2020-1337',
                                               commit='abcd',
                                               confidence=100,
                                               project='project',
                                               ecosystem='ecosystem',
                                               public=False)
        should_be_deleted.put()
Ejemplo n.º 3
0
    def test_mark_bug_invalid(self):
        """Test mark_bug_invalid."""
        osv.Bug(id='2021-1', source_id='oss-fuzz:1337').put()
        osv.AffectedCommit(bug_id='2021-1').put()
        osv.AffectedCommit(bug_id='2021-1').put()

        message = mock.Mock()
        message.attributes = {
            'type': 'invalid',
            'testcase_id': '1337',
            'source_id': '',
        }

        worker.mark_bug_invalid(message)
        bug = ndb.Key(osv.Bug, '2021-1').get()
        self.assertEqual(osv.BugStatus.INVALID, bug.status)

        commits = list(osv.AffectedCommit.query())
        self.assertEqual(0, len(commits))
Ejemplo n.º 4
0
    def setUp(self):
        tests.reset_emulator()
        self.maxDiff = None

        tests.mock_clone(self, return_value=pygit2.Repository('osv-test'))
        tests.mock_datetime(self)

        allocated_bug = osv.Bug(id='2020-1337',
                                timestamp=datetime.datetime(2020, 1, 1),
                                source_id='oss-fuzz:123',
                                status=osv.BugStatus.UNPROCESSED,
                                public=False)
        allocated_bug.put()

        should_be_deleted = osv.AffectedCommit(id='2020-1337-abcd',
                                               bug_id='2020-1337',
                                               commit='abcd',
                                               project='project',
                                               ecosystem='ecosystem',
                                               public=False)
        should_be_deleted.put()