|
| 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 requires 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 | +import api_data as api |
| 25 | +import json |
| 26 | + |
| 27 | +test_data = """ |
| 28 | +[{ |
| 29 | + "Modified": "2008-11-15T00:00:00", |
| 30 | + "Published": "2007-02-19T21:28:00", |
| 31 | + "access": { |
| 32 | + "authentication": "NONE", |
| 33 | + "complexity": "MEDIUM", |
| 34 | + "vector": "NETWORK" |
| 35 | + }, |
| 36 | + "cvss": 4.3, |
| 37 | + "cvss-time": "2007-02-20T14:55:00", |
| 38 | + "id": "CVE-2007-1004", |
| 39 | + "impact": { |
| 40 | + "availability": "NONE", |
| 41 | + "confidentiality": "NONE", |
| 42 | + "integrity": "PARTIAL" |
| 43 | + }, |
| 44 | + "reason": "Link", |
| 45 | + "references": [ |
| 46 | + "http://securityreason.com/securityalert/2264", |
| 47 | + "http://www.securityfocus.com/archive/1/archive/1/460369/100/0/threaded", |
| 48 | + "http://www.securityfocus.com/archive/1/archive/1/460412/100/0/threaded", |
| 49 | + "http://www.securityfocus.com/archive/1/archive/1/460617/100/0/threaded", |
| 50 | + "http://www.securityfocus.com/bid/22601", |
| 51 | + "http://xforce.iss.net/xforce/xfdb/32580" |
| 52 | + ], |
| 53 | + "summary": "Mozilla Firefox might allow remote", |
| 54 | + "vulnerable_configuration": [ |
| 55 | + "cpe:2.3:a:mozilla:firefox:2.0:rc3" |
| 56 | + ], |
| 57 | + "vulnerable_configuration_cpe_2_2": [ |
| 58 | + "cpe:/a:mozilla:firefox:2.0:rc3" |
| 59 | + ]}] |
| 60 | +""" |
| 61 | + |
| 62 | + |
| 63 | +def test_extract_fields_data(): |
| 64 | + fields_names = ['id', 'cvss', 'summary'] |
| 65 | + data = json.loads(test_data) |
| 66 | + extracted_data = api.extract_fields(data=data, fields_names=fields_names) |
| 67 | + |
| 68 | + assert extracted_data == [{'cvss': 4.3, 'id': 'CVE-2007-1004', |
| 69 | + 'summary': 'Mozilla Firefox might allow remote'}] |
| 70 | + |
| 71 | + |
| 72 | +def test_extract_fields(): |
| 73 | + fields_names = [] |
| 74 | + data = json.loads(test_data) |
| 75 | + extracted_data = api.extract_fields(data=data, fields_names=fields_names) |
| 76 | + assert extracted_data == [{}] |
| 77 | + |
| 78 | + fields_names = [''] |
| 79 | + extracted_data = api.extract_fields(data=data, fields_names=fields_names) |
| 80 | + assert extracted_data == [{'': None}] |
| 81 | + |
| 82 | + fields_names = ['invalid_field'] |
| 83 | + extracted_data = api.extract_fields(data=data, fields_names=fields_names) |
| 84 | + assert extracted_data == [{'invalid_field': None}] |
0 commit comments