Skip to content

Commit

Permalink
Add group creation date to issues and group json
Browse files Browse the repository at this point in the history
Through the json interface currently there is no way to find when a
group was created. If an app for example uses /issues/vulnerable.json
and needs this information it currently additionally has to download the
group html for each group and parse the "Created date" from the html.

This MR adds group.created as 'date' to the issues and group json so for
example downloading /issues/vulnerable.json would include this
information and no additional download for each group is needed.

It uses Y-M-d date format same as is used for advisories creation date
in package json.
  • Loading branch information
jakedane committed May 10, 2023
1 parent c17735e commit 9c65c52
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion test/test_group.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

from flask import url_for
from werkzeug.exceptions import Forbidden
from werkzeug.exceptions import NotFound
Expand Down Expand Up @@ -338,14 +340,15 @@ def test_show_group(db, client):
assert 'text/html; charset=utf-8' == resp.content_type
assert DEFAULT_GROUP_NAME in resp.data.decode()

@create_group(id=DEFAULT_GROUP_ID, packages=['foo'], affected='1.2.3-3', fixed='1.2.3-4')
@create_group(id=DEFAULT_GROUP_ID, created=datetime(2023, 5, 10), packages=['foo'], affected='1.2.3-3', fixed='1.2.3-4')
@create_advisory(id=DEFAULT_ADVISORY_ID, group_package_id=DEFAULT_GROUP_ID, advisory_type=issue_types[1])
def test_show_group_json(db, client):
resp = client.get(url_for('tracker.show_group_json', avg=DEFAULT_GROUP_NAME, postfix='/json'), follow_redirects=True)
assert 200 == resp.status_code
assert 'application/json; charset=utf-8' == resp.content_type
data = resp.get_json()
assert data['name'] == DEFAULT_GROUP_NAME
assert data['date'] == '2023-05-10'
assert data['issues'] == [DEFAULT_ISSUE_ID]
assert data['packages'] == ['foo']
assert data['affected'] == '1.2.3-3'
Expand Down
8 changes: 6 additions & 2 deletions test/test_index.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

from flask import url_for

from .conftest import DEFAULT_GROUP_ID
Expand Down Expand Up @@ -32,21 +34,23 @@ def test_index_all(db, client):


@create_package(name='foo', version='1.2.3-4')
@create_group(id=DEFAULT_GROUP_ID, packages=['foo'], affected='1.2.3-3')
@create_group(id=DEFAULT_GROUP_ID, created=datetime(2023, 5, 10), packages=['foo'], affected='1.2.3-3')
def test_index_json(db, client):
resp = client.get(url_for('tracker.index_json', only_vulernable=False), follow_redirects=True)
assert 200 == resp.status_code
data = resp.get_json()
assert 'application/json; charset=utf-8' == resp.content_type
assert len(data) == 1
assert data[0]['name'] == DEFAULT_GROUP_NAME
assert data[0]['date'] == '2023-05-10'


@create_package(name='foo', version='1.2.3-4')
@create_group(id=DEFAULT_GROUP_ID, packages=['foo'], affected='1.2.3-3')
@create_group(id=DEFAULT_GROUP_ID, created=datetime(2023, 5, 10), packages=['foo'], affected='1.2.3-3')
def test_index_vulnerable_json(db, client):
resp = client.get(url_for('tracker.index_vulnerable_json'), follow_redirects=True)
assert 200 == resp.status_code
data = resp.get_json()
assert len(data) == 1
assert data[0]['name'] == DEFAULT_GROUP_NAME
assert data[0]['date'] == '2023-05-10'
1 change: 1 addition & 0 deletions tracker/view/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def index_json(only_vulnerable=False):

json_entry = OrderedDict()
json_entry['name'] = group.name
json_entry['date'] = group.created.strftime('%Y-%m-%d')
json_entry['packages'] = entry['pkgs']
json_entry['status'] = group.status.label
json_entry['severity'] = group.severity.label
Expand Down
1 change: 1 addition & 0 deletions tracker/view/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ def show_group_json(avg):

json_data = OrderedDict()
json_data['name'] = group.name
json_data['date'] = group.created.strftime('%Y-%m-%d')
json_data['packages'] = [package.pkgname for package in packages]
json_data['status'] = group.status.label
json_data['severity'] = group.severity.label
Expand Down

0 comments on commit 9c65c52

Please sign in to comment.