Пример #1
0
    def _fetch_data(self):
        self._fetch_by_id()
        commit = self.get_master_commit()
        if commit:
            commit = self._vulnerability.master_commit
            self.commit_link = commit.commit_link
            self.commit_hash = commit.commit_hash
            self.repo_url = commit.repo_url
        # Initialize VCS specific data.
        self._init_repo_data()
        self._fetch_by_commit_hash()

        # Fetch IDs from vulnerability entry if it exists.
        if self._vulnerability:
            self.vcdb_id = str(self._vulnerability.vcdb_id)
            self.vuln_id = str(self._vulnerability.id)
            if self._vulnerability.cve_id:
                self.cve_id = self._vulnerability.cve_id

        # Fetch corresponding NVD data if possible.
        if self.cve_id:
            self._nvd_data = Nvd.get_by_cve_id(self.cve_id)
        elif self.commit_hash:
            self._nvd_data = Nvd.get_by_commit_hash(self.commit_hash)

        # Make sure to always use the properly formatted CVE-ID if available.
        if self._nvd_data:
            self.cve_id = self._nvd_data.cve_id

        if self._vulnerability or self._nvd_data:
            self.fetch_tree_cache()
            self.vulnerability_view = VulnerabilityView(
                self._vulnerability, self._nvd_data)
Пример #2
0
    def generate_testdata(self):
        def generate_commit_data():
            return VulnerabilityGitCommits(
                commit_link='https://github.com/0WN3R/REP0',
                commit_hash='F00D',
                repo_name='REP0',
                repo_owner='0WN3R',
            )

        self.vuln1 = Vulnerability(cve_id='CVE-1337',
                                   commits=[generate_commit_data()],
                                   comment="Test comment.",
                                   date_created=datetime.date.today())
        self.nvd1 = Nvd(cve_id='CVE-1337',
                        published_date=datetime.date.today(),
                        descriptions=[])
        self.vuln2 = Vulnerability(
            cve_id='CVE-1339',
            commits=[generate_commit_data()],
            date_created=datetime.date.today(),
            comment="Test comment2.",
        )

        self.vulns = [self.vuln1, self.vuln2]

        self.vuln_view1 = vuln.VulnerabilityView(self.vuln1,
                                                 self.nvd1,
                                                 preview=True)
        self.vuln_view2 = vuln.VulnerabilityView(self.vuln1,
                                                 None,
                                                 preview=True)
        self.vuln_view3 = vuln.VulnerabilityView(None, self.nvd1, preview=True)