|
| 1 | +# |
| 2 | +# Copyright (c) 2017 nexB Inc. and others. All rights reserved. |
| 3 | +# http://nexb.com and https://github.com/nexB/vulnerablecode/ |
| 4 | +# The VulnerableCode software is licensed under the Apache License version 2.0. |
| 5 | +# Data generated with VulnerableCode require an acknowledgment. |
| 6 | +# |
| 7 | +# You may not use this software except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0 |
| 9 | +# Unless required by applicable law or agreed to in writing, software distributed |
| 10 | +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 11 | +# CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 12 | +# specific language governing permissions and limitations under the License. |
| 13 | +# |
| 14 | +# When you publish or redistribute any data created with VulnerableCode or any VulnerableCode |
| 15 | +# derivative work, you must accompany this data with the following acknowledgment: |
| 16 | +# |
| 17 | +# Generated with VulnerableCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES |
| 18 | +# OR CONDITIONS OF ANY KIND, either express or implied. No content created from |
| 19 | +# VulnerableCode should be considered or used as legal advice. Consult an Attorney |
| 20 | +# for any legal advice. |
| 21 | +# VulnerableCode is a free software code scanning tool from nexB Inc. and others. |
| 22 | +# Visit https://github.com/nexB/vulnerablecode/ for support and download. |
| 23 | + |
| 24 | +from django.test import TestCase |
| 25 | + |
| 26 | +from vulncode_app.models import Vulnerability |
| 27 | +from vulncode_app.models import VulnerabilityReference |
| 28 | +from vulncode_app.models import Package |
| 29 | +from vulncode_app.data_dump import debian_dump |
| 30 | + |
| 31 | +import json |
| 32 | + |
| 33 | +from scraper import debian |
| 34 | + |
| 35 | + |
| 36 | +class TestDataDump(TestCase): |
| 37 | + def test_data_dump(self): |
| 38 | + """ |
| 39 | + Scrape data from Debian' main tracker, dump it |
| 40 | + in the database and verify entries. |
| 41 | + """ |
| 42 | + with open("tests/test_data/debian.json") as f: |
| 43 | + test_data = json.loads(f.read()) |
| 44 | + |
| 45 | + extract_data = debian.extract_data(test_data) |
| 46 | + |
| 47 | + for data in extract_data: |
| 48 | + vulnerability = Vulnerability(summary=data.get('description')) |
| 49 | + vulnerability_reference = VulnerabilityReference(reference_id=data.get('vulnerability_id')) |
| 50 | + package = Package(name=data.get('package_name'), version=data.get('fixed_version')) |
| 51 | + |
| 52 | + vulnerability.save() |
| 53 | + vulnerability_reference.save() |
| 54 | + package.save() |
| 55 | + |
| 56 | + self.assertEqual(getattr(vulnerability, 'summary'), None) |
| 57 | + self.assertEqual(getattr(vulnerability_reference, 'reference_id'), "TEMP-0807341-84E914") |
| 58 | + self.assertEqual(getattr(package, 'name'), "git-repair") |
0 commit comments