Skip to content

Commit ac8be2f

Browse files
committed
Fix security advisory updater including wrong files.
The updater looked for all files with a '.md' extension that had bee modified. This was looking at README.md in error. This fixes the behavior to only look at files named 'mfsaYYYY-NN.md'.
1 parent c6d0a3d commit ac8be2f

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

bedrock/security/management/commands/update_security_advisories.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from dateutil.parser import parse as parsedate
1919

2020
from bedrock.security.models import Product, SecurityAdvisory
21-
from bedrock.security.utils import chdir, parse_md_file
21+
from bedrock.security.utils import FILENAME_RE, chdir, parse_md_file
2222

2323

2424
ADVISORIES_REPO = settings.MOFO_SECURITY_ADVISORIES_REPO
@@ -54,6 +54,11 @@ def mkdir_p(path):
5454
raise
5555

5656

57+
def filter_advisory_filenames(filenames):
58+
return [os.path.join(ADVISORIES_PATH, fn) for fn in filenames
59+
if FILENAME_RE.search(fn)]
60+
61+
5762
@chdir(ADVISORIES_PATH)
5863
def git_pull():
5964
old_hash = get_current_git_hash()
@@ -64,16 +69,12 @@ def git_pull():
6469

6570
@chdir(ADVISORIES_PATH)
6671
def git_diff(old_hash, new_hash):
67-
modified_files = []
6872
if old_hash != new_hash:
6973
proc = Popen((GIT, 'diff', '--name-only', old_hash, new_hash), stdout=PIPE)
7074
git_out = proc.communicate()[0].split()
71-
for mf in git_out:
72-
if not mf.endswith('.md'):
73-
continue
74-
modified_files.append(os.path.join(ADVISORIES_PATH, mf))
75+
return filter_advisory_filenames(git_out)
7576

76-
return modified_files
77+
return []
7778

7879

7980
@chdir(ADVISORIES_PATH)

bedrock/security/tests/test_commands.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,37 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

5+
from django.conf import settings
6+
57
from nose.tools import eq_
6-
from bedrock.mozorg.tests import TestCase
8+
79
from bedrock.security.management.commands import update_security_advisories
810

911

10-
class TestUpdateSecurityAdvisories(TestCase):
11-
def test_fix_product_name(self):
12-
"""Should fix SeaMonkey and strip '.0' from names."""
13-
eq_(update_security_advisories.fix_product_name('Seamonkey 2.2'),
14-
'SeaMonkey 2.2')
15-
eq_(update_security_advisories.fix_product_name('Firefox 2.2'),
16-
'Firefox 2.2')
17-
eq_(update_security_advisories.fix_product_name('fredflintstone 2.2'),
18-
'fredflintstone 2.2')
19-
eq_(update_security_advisories.fix_product_name('Firefox 32.0'),
20-
'Firefox 32')
21-
eq_(update_security_advisories.fix_product_name('Firefox 32.0.1'),
22-
'Firefox 32.0.1')
12+
def test_fix_product_name():
13+
"""Should fix SeaMonkey and strip '.0' from names."""
14+
eq_(update_security_advisories.fix_product_name('Seamonkey 2.2'),
15+
'SeaMonkey 2.2')
16+
eq_(update_security_advisories.fix_product_name('Firefox 2.2'),
17+
'Firefox 2.2')
18+
eq_(update_security_advisories.fix_product_name('fredflintstone 2.2'),
19+
'fredflintstone 2.2')
20+
eq_(update_security_advisories.fix_product_name('Firefox 32.0'),
21+
'Firefox 32')
22+
eq_(update_security_advisories.fix_product_name('Firefox 32.0.1'),
23+
'Firefox 32.0.1')
24+
25+
26+
def test_filter_advisory_names():
27+
filenames = [
28+
'README.md',
29+
'LICENSE.txt',
30+
'announce/2015/mfsa2015-01.md',
31+
'stuff/whatnot.md',
32+
'mfsa2015-02.md',
33+
]
34+
good_filenames = [
35+
settings.MOFO_SECURITY_ADVISORIES_PATH + '/announce/2015/mfsa2015-01.md',
36+
settings.MOFO_SECURITY_ADVISORIES_PATH + '/mfsa2015-02.md',
37+
]
38+
eq_(update_security_advisories.filter_advisory_filenames(filenames), good_filenames)

0 commit comments

Comments
 (0)