def cves_get(ecosystem, name=None, version=None): """Get list of CVEs for E, EP, or EPV.""" cve = CVEGet(ecosystem, name, version) try: result = cve.get() except ValueError as e: return flask.jsonify({'error': str(e)}), 500 return flask.jsonify(result), 200
def test_cve_get_epv(mocker): """Test getting CVEs for (ecosystem,name,version).""" mocker.return_value = {'result': {'data': []}} cve = CVEGet('pypi', 'numpy', '99.0') response = cve.get() assert response assert 'count' in response assert response['count'] == 0 assert 'cve_ids' in response assert len(response['cve_ids']) == 0
def test_cve_get_e(mocker): """Test getting CVEs for (ecosystem).""" mocker.return_value = {'result': {'data': ['CVE-2018-0001']}} cve = CVEGet('pypi', None, None) response = cve.get() assert response assert 'count' in response assert response['count'] == 1 assert 'cve_ids' in response assert len(response['cve_ids']) == 1 assert response['cve_ids'][0] == 'CVE-2018-0001'
def test_cve_get_ep(mocker): """Test getting CVEs for (ecosystem,name).""" mocker.return_value = {'result': {'data': ['CVE-2018-0001', 'CVE-2018-0002']}} cve = CVEGet('pypi', 'numpy', None) response = cve.get() assert response assert 'count' in response assert response['count'] == 2 assert 'cve_ids' in response assert len(response['cve_ids']) == 2 assert response['cve_ids'][0] in ('CVE-2018-0001', 'CVE-2018-0002') assert response['cve_ids'][1] in ('CVE-2018-0001', 'CVE-2018-0002')