Skip to content

Commit 9ee950b

Browse files
authored
Merge pull request #1 from nexB/main
Merging updated codebase
2 parents 80c65a2 + 86424ee commit 9ee950b

27 files changed

Lines changed: 371 additions & 77 deletions

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
pip install -r requirements.txt
3939
4040
- name: Run tests
41-
run: python -m pytest
41+
run: python -m pytest -v -m "not webtest"
4242
env:
4343
# The hostname, username used to communicate with the PostgreSQL service container
4444
POSTGRES_HOST: localhost
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
on:
2+
workflow_dispatch: # allow manual execution
3+
push:
4+
schedule:
5+
# run on every 9 o'clock
6+
- cron: '0 9 * * *'
7+
8+
jobs:
9+
unit_tests:
10+
runs-on: ubuntu-latest
11+
12+
services:
13+
# Label used to access the service container
14+
postgres:
15+
image: postgres
16+
env:
17+
POSTGRES_PASSWORD: vulnerablecode
18+
POSTGRES_DB: vulnerablecode
19+
# Set health checks to wait until postgres has started
20+
options: >-
21+
--health-cmd pg_isready
22+
--health-interval 10s
23+
--health-timeout 5s
24+
--health-retries 5
25+
ports:
26+
# Maps tcp port 5432 on service container to the host
27+
- 5432:5432
28+
steps:
29+
- name: Check out repository code
30+
uses: actions/checkout@v2
31+
32+
- name: Set up Python 3.8
33+
uses: actions/setup-python@v2
34+
with:
35+
python-version: 3.8
36+
37+
- name: Install dependencies
38+
run: |
39+
sudo apt install python3-dev postgresql libpq-dev build-essential libxml2-dev libxslt1-dev
40+
python -m pip install --upgrade pip
41+
pip install -r requirements.txt
42+
43+
- name: Run tests
44+
run: pytest -v -m webtest
45+
env:
46+
# The hostname, username used to communicate with the PostgreSQL service container
47+
POSTGRES_HOST: localhost
48+
VC_DB_USER: postgres
49+
POSTGRES_PORT: 5432
50+
DJANGO_DEV: 1
51+
GH_TOKEN: 1

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ before_script:
1818

1919
script:
2020
- ./manage.py collectstatic
21-
- python -m pytest
21+
- python -m pytest -v -m "not webtest"
2222

2323
notifications:
2424
email: false

AUTHORS.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ The following organizations or individuals have contributed to this repo:
1111
- Islam Elhakmi @EslamHiko
1212
- Edoardo Lanzini @elanzini
1313
- Navonil Das @NavonilDas
14-
- Tushar Upadhyay @tushar912
14+
- Tushar Upadhyay @tushar912
15+
- Hritik Vijay @hritik14

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ ENV PYTHONUNBUFFERED 1
66
RUN mkdir /vulnerablecode
77
WORKDIR /vulnerablecode
88
ADD . /vulnerablecode/
9-
RUN pip install -r requirements.txt
9+
RUN pip install -r requirements.txt && \
10+
DJANGO_DEV=1 python manage.py collectstatic
1011

1112
LABEL "base_image": "pkg:docker/python@sha256%3Ae9b7e3b4e9569808066c5901b8a9ad315a9f14ae8d3949ece22ae339fff2cad0"
1213
LABEL "dockerfile_url": "https://github.com/nexB/vulnerablecode/blob/develop/Dockerfile"

README.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,12 @@ On Debian-based distros, these can be installed with::
141141

142142
**Application dependencies**
143143

144-
Create a virtualenv, install dependencies, and run the database migrations::
144+
Create a virtualenv, install dependencies, generate static files and run the database migrations::
145145

146146
python3 -m venv venv
147147
source venv/bin/activate
148148
pip install -r requirements.txt
149+
DJANGO_DEV=1 python manage.py collectstatic
149150
DJANGO_DEV=1 python manage.py migrate
150151

151152
The environment variable ``DJANGO_DEV`` is used to load settings suitable for
@@ -160,6 +161,11 @@ for this purpose::
160161

161162
SECRET_KEY=$(python -c "from django.core.management import utils; print(utils.get_random_secret_key())")
162163

164+
You will also need to setup the VC_ALLOWED_HOSTS environment variable to match the hostname where the app is deployed::
165+
166+
VC_ALLOWED_HOSTS=vulnerablecode.your.domain.example.com
167+
168+
You can specify several host by separating them with a colon `:`
163169

164170
Using Nix
165171
~~~~~~~~~

etc/nix/flake.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
# mach-nix release) is usually insufficient. Use
5454
# ./get-latest-pypi-deps-db.sh to obtain the data rev & hash.
5555
pypiDataRev =
56-
"499750266bb4b2840cbe856c2cc0e3297685e362"; # 2021-03-06T08:13:08Z
56+
"e9b0fc6b92cd6efbca7ba3b3d4a551bcc13a73c5"; # 2021-03-27T08:13:04Z
5757
pypiDataSha256 =
58-
"188g24k8pk4lgqybywimkvwjwh8014v6l2mrkvzv309882i9p5gc";
58+
"1ssa48l2iz8kncby1gfrbds79mg114dkhpxrridwcq6q2c37p62s";
5959
});
6060

6161
in {

requirements.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ contextlib2==0.5.5
99
decorator==4.4.2
1010
dephell-specifier==0.2.1
1111
dj-database-url==0.4.2
12-
Django==3.0.7
12+
Django==3.0.13
1313
django-filter==2.2.0
14-
djangorestframework==3.11.0
14+
djangorestframework==3.11.2
1515
django-widget-tweaks==1.4.8
1616
drf-spectacular==0.13.0
1717
gunicorn==19.7.1
1818
importlib-metadata==1.3.0
1919
ipython==7.13.0
2020
ipython-genutils==0.2.0
2121
jedi==0.17.0
22-
lxml==4.6.2
22+
lxml==4.6.3
2323
more-itertools==8.0.2
2424
packageurl-python==0.9.3
2525
packaging==19.2
@@ -34,7 +34,7 @@ ptyprocess==0.6.0
3434
py==1.8.0
3535
pycparser==2.20
3636
pygit2==1.5.0
37-
Pygments==2.6.1
37+
Pygments==2.7.4
3838
pyparsing==2.4.5
3939
pytest==5.3.2
4040
django-widget-tweaks==1.4.8
@@ -54,5 +54,5 @@ whitenoise==5.0.1
5454
zipp==0.6.0
5555
requests==2.23.0
5656
toml==0.10.2
57-
PyYAML==5.3.1
57+
PyYAML==5.4
5858
freezegun==1.1.0

vulnerabilities/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def bulk_search(self, request):
152152
)
153153
for purl in request.data["purls"]:
154154
try:
155+
purl_string = purl
155156
purl = PackageURL.from_string(purl).to_dict()
156157
except ValueError as ve:
157158
return Response(status=400, data={"Error": f"Invalid Package URL: {purl}"})
@@ -165,6 +166,7 @@ def bulk_search(self, request):
165166
purl_response = purl
166167
purl_response["unresolved_vulnerabilities"] = []
167168
purl_response["resolved_vulnerabilities"] = []
169+
purl_response["purl"] = purl_string
168170
response.append(purl_response)
169171

170172
return Response(response)

vulnerabilities/data_source.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
from vulnerabilities.oval_parser import OvalParser
4646
from vulnerabilities.severity_systems import ScoringSystem
47+
from vulnerabilities.helpers import is_cve
4748

4849
logger = logging.getLogger(__name__)
4950

@@ -88,6 +89,10 @@ class Advisory:
8889
resolved_package_urls: Iterable[PackageURL] = dataclasses.field(default_factory=list)
8990
references: List[Reference] = dataclasses.field(default_factory=list)
9091

92+
def __post_init__(self):
93+
if self.vulnerability_id and not is_cve(self.vulnerability_id):
94+
raise ValueError("CVE expected, found: {}".format(self.vulnerability_id))
95+
9196
def normalized(self):
9297
impacted_package_urls = {package_url for package_url in self.impacted_package_urls}
9398
resolved_package_urls = {package_url for package_url in self.resolved_package_urls}

0 commit comments

Comments
 (0)