Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn if lib32- variant is missing when adding a group #129

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions test/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,69 @@ def test_add_group_with_dot_in_pkgrel(db, client):
set_and_assert_group_data(db, client, url_for('tracker.add_group'), affected='1.2-3.4')


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would love to see a test as well that already has the lib32 variant and adds the non-lib32 one later. maybe that case should be detected and flashed as well 😺

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, but the code is rather deeply nested, maybe some lambda/filter/map logic can be used to make it nicer.

@create_package(name='foo', version='1.2.3-4')
@create_package(name='lib32-foo', version='1.2.3-4')
@logged_in
def test_add_group_missing_foo(db, client):
pkgnames = ['lib32-foo']
issues = ['CVE-1234-1234', 'CVE-2222-2222']
data = default_group_dict(dict(
cve='\n'.join(issues),
pkgnames='\n'.join(pkgnames),
))

resp = client.post(url_for('tracker.add_group'), follow_redirects=True, data=data)
assert 200 == resp.status_code
assert 'Missing AVG for foo' in resp.data.decode()


@create_package(name='foo', version='1.2.3-4')
@create_package(name='lib32-foo', version='1.2.3-4')
@logged_in
def test_add_group_missing_lib32(db, client):
pkgnames = ['foo']
issues = ['CVE-1234-1234', 'CVE-2222-2222']
data = default_group_dict(dict(
cve='\n'.join(issues),
pkgnames='\n'.join(pkgnames),
))

resp = client.post(url_for('tracker.add_group'), follow_redirects=True, data=data)
assert 200 == resp.status_code
assert 'Missing AVG for lib32-foo' in resp.data.decode()


@create_package(name='foo', version='1.2.3-4')
@create_package(name='lib32-foo', version='1.2.3-4')
@logged_in
def test_add_group_missing_lib32_included(db, client):
pkgnames = ['foo', 'lib32-foo']
issues = ['CVE-1234-1234', 'CVE-2222-2222']
data = default_group_dict(dict(
cve='\n'.join(issues),
pkgnames='\n'.join(pkgnames),
))

resp = client.post(url_for('tracker.add_group'), follow_redirects=True, data=data)
assert 200 == resp.status_code
assert 'Missing AVG for lib32-foo' not in resp.data.decode()


@create_package(name='foo', version='1.2.3-4')
@logged_in
def test_add_group_missing_lib32_invalid(db, client):
pkgnames = ['foo']
issues = ['CVE-1234-1234', 'CVE-2222-2222']
data = default_group_dict(dict(
cve='\n'.join(issues),
pkgnames='\n'.join(pkgnames),
))

resp = client.post(url_for('tracker.add_group'), follow_redirects=True, data=data)
assert 200 == resp.status_code
assert 'Missing AVG for lib32-foo' not in resp.data.decode()


@create_package(name='foo')
@logged_in
def test_dont_add_group_with_dot_at_beginning_of_pkgrel(db, client):
Expand Down
23 changes: 23 additions & 0 deletions tracker/view/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from tracker.model import CVEGroup
from tracker.model import CVEGroupEntry
from tracker.model import CVEGroupPackage
from tracker.model import Package
from tracker.model.enum import Affected
from tracker.model.enum import Remote
from tracker.model.enum import Severity
Expand Down Expand Up @@ -199,4 +200,26 @@ def add_group():

db.session.commit()
flash('Added {}'.format(group.name))

missing_variants(pkgnames, group)

return redirect('/{}'.format(group.name))


def missing_variants(pkgnames, group, variants=['lib32']):
testpkgs = []
for pkgname in pkgnames:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this locally and the behavior is correct. I wanted to make sure that we don't add a "there's a lib32 package added but this still flashes the warning" behavior. Could we add a test for it?

Copy link
Member Author

@jelly jelly Jun 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I think test_add_group_missing_lib32_invaid handles this case, since the lib32-foo pakage is not created.

for variant in variants:
if variant in pkgname:
pkg = pkgname.replace(f'{variant}-', '')
if pkg not in pkgnames:
testpkgs.append(pkg)
else:
pkg = f'{variant}-{pkgname}'
if pkg not in pkgnames:
testpkgs.append(pkg)

package_data = Package.query.filter(Package.name.in_(testpkgs)).all()
for pkg in package_data:
if pkg not in group.packages:
flash('Missing AVG for {}'.format(pkg.name))