Skip to content

Commit

Permalink
fix(feed): actually return proper atom including full content
Browse files Browse the repository at this point in the history
Additionally, lets test for the appropriate content-type during tests.
  • Loading branch information
anthraxx committed Mar 31, 2022
1 parent e55c2c0 commit 40be7f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions test/test_advisory.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ def test_advisory_cve_listing_sorted_numerically(db, client):
def test_advisory_atom_no_data(db, client):
resp = client.get(url_for('tracker.advisory_atom'), follow_redirects=True)
assert 200 == resp.status_code
assert 'application/atom+xml; charset=utf-8' == resp.content_type
data = resp.data.decode()
assert DEFAULT_ADVISORY_ID not in data

Expand Down
25 changes: 14 additions & 11 deletions tracker/view/advisory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
from re import match

from feedgen.feed import FeedGenerator
from flask import Response
from flask import flash
from flask import make_response
from flask import redirect
from flask import render_template
from flask import request
from pytz import UTC
from sqlalchemy import and_

Expand Down Expand Up @@ -64,27 +63,31 @@ def advisory_atom():
data = get_advisory_data()['published'][:TRACKER_FEED_ADVISORY_ENTRIES]

feed = FeedGenerator()
feed.title('Arch Linux Security - Recent advisories')
feed.description('Arch Linux recent advsisories RSS feed')
feed.link(href=request.url_root)
feed.id(TRACKER_ISSUE_URL.format('advisory'))
feed.title('Arch Linux Security Advisories')
feed.subtitle('Feed containing the last published Arch Linux Security Advisories')
feed.link(href=TRACKER_ISSUE_URL.format('advisory'), rel='alternate')
feed.link(href=TRACKER_ISSUE_URL.format('advisory/feed.atom'), rel='self')
feed.language('en')

for entry in data:
package = entry['package']
advisory = entry['advisory']
content=render_template('feed.html', content=advisory.content)
summary=render_template('feed.html', content=advisory.impact)
content = render_template('feed.html', content=advisory.content)
impact = render_template('feed.html', content=advisory.impact)
published = updated = advisory.created.replace(tzinfo=UTC)

entry = feed.add_entry()
entry.id(TRACKER_ISSUE_URL.format(advisory.id))
entry.title(f'[{advisory.id}] {package.pkgname}: {advisory.advisory_type}')
entry.author(name='Arch Linux Security Team')
entry.description(content)
entry.description(summary, isSummary=True)
entry.content(content.replace('\n', '<br/>'), type='html')
entry.summary(impact.replace('\n', '<br/>'), type='html')
entry.published(published)
entry.updated(updated)
entry.link(href=TRACKER_ISSUE_URL.format(advisory.id))
entry.link(href=TRACKER_ISSUE_URL.format(advisory.id), rel='alternate')

return make_response(feed.rss_str())
return Response(feed.atom_str(pretty=True), 200, content_type='application/atom+xml; charset=utf-8')


@tracker.route('/advisory<regex("[./]json"):postfix>', methods=['GET'])
Expand Down

0 comments on commit 40be7f9

Please sign in to comment.