Exemple #1
0
    def test_scheduled_updates_already_done(self, mock_publish):
        """Scheduled updates already done."""
        source_repo = osv.SourceRepository.get_by_id('oss-fuzz')
        source_repo.last_update_date = importer.utcnow().date()
        source_repo.put()

        self.mock_repo.add_file('proj/OSV-2021-1337.yaml', '')
        self.mock_repo.commit('OSV', '*****@*****.**')
        osv.Bug(id='2021-1337',
                project='proj',
                fixed='',
                status=1,
                source_id='oss-fuzz:123',
                source_of_truth=osv.SourceOfTruth.SOURCE_REPO,
                timestamp=datetime.datetime(2020, 1, 1, 0, 0, 0, 0)).put()

        imp = importer.Importer('fake_public_key', 'fake_private_key',
                                self.tmp_dir, 'bucket')
        imp.run()

        self.assertEqual(0, mock_publish.call_count)
Exemple #2
0
    def test_scheduled_updates(self, mock_publish):
        """Test scheduled updates."""
        self.mock_repo.add_file('proj/OSV-2021-1337.yaml', '')
        self.mock_repo.add_file('proj/OSV-2021-1339.yaml', '')
        self.mock_repo.add_file('OSV-2021-1338.yaml', '')
        self.mock_repo.commit('OSV', '*****@*****.**')

        osv.Bug(id='2021-1337',
                project='proj',
                ecosystem='OSS-Fuzz',
                fixed='',
                status=1,
                source_id='oss-fuzz:123',
                source_of_truth=osv.SourceOfTruth.SOURCE_REPO,
                timestamp=datetime.datetime(2020, 1, 1, 0, 0, 0, 0)).put()
        osv.Bug(id='2021-1338',
                project='proj',
                fixed='fix',
                source_id='source:OSV-2021-1338.yaml',
                status=1,
                source_of_truth=osv.SourceOfTruth.SOURCE_REPO,
                timestamp=importer.utcnow()).put()
        osv.Bug(id='2021-1339',
                project='proj',
                ecosystem='OSS-Fuzz',
                fixed='',
                status=1,
                source_id='oss-fuzz:124',
                source_of_truth=osv.SourceOfTruth.INTERNAL,
                timestamp=datetime.datetime(2020, 1, 1, 0, 0, 0, 0)).put()

        imp = importer.Importer('fake_public_key', 'fake_private_key',
                                self.tmp_dir, 'bucket')
        imp.run()

        mock_publish.assert_has_calls([
            mock.call('projects/oss-vdb/topics/tasks',
                      data=b'',
                      deleted='false',
                      original_sha256=('e3b0c44298fc1c149afbf4c8996fb924'
                                       '27ae41e4649b934ca495991b7852b855'),
                      path='proj/OSV-2021-1337.yaml',
                      source='oss-fuzz',
                      type='update'),
            mock.call('projects/oss-vdb/topics/tasks',
                      allocated_id='2021-1339',
                      data=b'',
                      source_id='oss-fuzz:124',
                      type='impact'),
            mock.call('projects/oss-vdb/topics/tasks',
                      data=b'',
                      deleted='false',
                      original_sha256=('e3b0c44298fc1c149afbf4c8996fb924'
                                       '27ae41e4649b934ca495991b7852b855'),
                      path='OSV-2021-1338.yaml',
                      source='oss-fuzz',
                      type='update'),
        ])

        source_repo = osv.SourceRepository.get_by_id('oss-fuzz')
        self.assertEqual(datetime.date(2021, 1, 1),
                         source_repo.last_update_date)
Exemple #3
0
  def test_scheduled_updates(self, mock_publish):
    """Test scheduled updates."""
    self.mock_repo.add_file('proj/OSV-2021-1337.yaml', _EMPTY_VULNERABILITY)
    self.mock_repo.add_file('proj/OSV-2021-1339.yaml', _EMPTY_VULNERABILITY)
    self.mock_repo.add_file('OSV-2021-1338.yaml', _EMPTY_VULNERABILITY)
    self.mock_repo.commit('OSV', '*****@*****.**')

    osv.SourceRepository(
        type=osv.SourceRepositoryType.GIT,
        id='source',
        name='source',
        repo_url='file://' + self.remote_source_repo_path,
        repo_username='').put()
    osv.Bug(
        db_id='OSV-2021-1337',
        affected_packages=[
            osv.AffectedPackage(
                package=osv.Package(ecosystem='OSS-Fuzz', name='proj'))
        ],
        status=1,
        source_id='oss-fuzz:123',
        source_of_truth=osv.SourceOfTruth.SOURCE_REPO,
        timestamp=datetime.datetime(2020, 1, 1, 0, 0, 0, 0)).put()
    osv.Bug(
        db_id='OSV-2021-1338',
        affected_packages=[
            osv.AffectedPackage(
                package=osv.Package(ecosystem='ecosystem', name='proj'),
                ranges=[
                    osv.AffectedRange2(
                        type='GIT',
                        events=[
                            osv.AffectedEvent(type='introduced', value='0'),
                            osv.AffectedEvent(type='fixed', value='fix'),
                        ])
                ])
        ],
        source_id='source:OSV-2021-1338.yaml',
        status=1,
        source_of_truth=osv.SourceOfTruth.SOURCE_REPO,
        timestamp=importer.utcnow()).put()
    osv.Bug(
        db_id='OSV-2021-1339',
        affected_packages=[
            osv.AffectedPackage(
                package=osv.Package(ecosystem='OSS-Fuzz', name='proj'))
        ],
        status=1,
        source_id='oss-fuzz:124',
        source_of_truth=osv.SourceOfTruth.INTERNAL,
        timestamp=datetime.datetime(2020, 1, 1, 0, 0, 0, 0)).put()

    imp = importer.Importer('fake_public_key', 'fake_private_key', self.tmp_dir,
                            'bucket')
    imp.run()

    mock_publish.assert_has_calls([
        mock.call(
            'projects/oss-vdb/topics/tasks',
            data=b'',
            deleted='false',
            original_sha256=('bd3cc48676794308a58a19c97972a5e5'
                             '42abcc9eb948db5701421616432cc0b9'),
            path='proj/OSV-2021-1337.yaml',
            source='oss-fuzz',
            type='update'),
        mock.call(
            'projects/oss-vdb/topics/tasks',
            allocated_id='OSV-2021-1339',
            data=b'',
            source_id='oss-fuzz:124',
            type='impact'),
    ])

    source_repo = osv.SourceRepository.get_by_id('oss-fuzz')
    self.assertEqual(datetime.date(2021, 1, 1), source_repo.last_update_date)