Merge "protect branch name validation from improperly formatted names"
This commit is contained in:
commit
962e043185
@ -566,7 +566,13 @@ def validate_stable_branches(deliverable_info, series_name,
|
||||
if not d.startswith('_')
|
||||
))
|
||||
for branch in branches:
|
||||
prefix, series = branch['name'].split('/')
|
||||
try:
|
||||
prefix, series = branch['name'].split('/')
|
||||
except ValueError:
|
||||
mk_error(
|
||||
('stable branch name expected to be stable/name '
|
||||
'but got %s') % (branch['name'],))
|
||||
continue
|
||||
if prefix != 'stable':
|
||||
continue
|
||||
location = branch.get('location')
|
||||
@ -633,7 +639,13 @@ def validate_feature_branches(deliverable_info, workdir, mk_warning, mk_error):
|
||||
"Apply the rules for feature branches."
|
||||
branches = deliverable_info.get('branches', [])
|
||||
for branch in branches:
|
||||
prefix, series = branch['name'].split('/')
|
||||
try:
|
||||
prefix, series = branch['name'].split('/')
|
||||
except ValueError:
|
||||
mk_error(
|
||||
('feature branch name expected to be feature/name '
|
||||
'but got %s') % (branch['name'],))
|
||||
continue
|
||||
if prefix != 'feature':
|
||||
continue
|
||||
location = branch['location']
|
||||
@ -669,7 +681,13 @@ def validate_driverfixes_branches(deliverable_info, workdir, mk_warning, mk_erro
|
||||
))
|
||||
branches = deliverable_info.get('branches', [])
|
||||
for branch in branches:
|
||||
prefix, series = branch['name'].split('/')
|
||||
try:
|
||||
prefix, series = branch['name'].split('/')
|
||||
except ValueError:
|
||||
mk_error(
|
||||
('driverfixes branch name expected to be driverfixes/name '
|
||||
'but got %s') % (branch['name'],))
|
||||
continue
|
||||
if prefix != 'driverfixes':
|
||||
continue
|
||||
location = branch['location']
|
||||
|
@ -1139,6 +1139,29 @@ class TestValidateStableBranches(base.BaseTestCase):
|
||||
self.assertEqual(0, len(warnings))
|
||||
self.assertEqual(0, len(errors))
|
||||
|
||||
def test_badly_formatted_name(self):
|
||||
deliverable_data = textwrap.dedent('''
|
||||
releases:
|
||||
- version: 1.5.0
|
||||
projects:
|
||||
- repo: openstack/automaton
|
||||
hash: be2885f544637e6ee6139df7dc7bf937925804dd
|
||||
branches:
|
||||
- name: ocata
|
||||
location: 1.5.0
|
||||
''')
|
||||
warnings = []
|
||||
errors = []
|
||||
deliverable_info = yaml.safe_load(deliverable_data)
|
||||
validate.validate_stable_branches(
|
||||
deliverable_info,
|
||||
'ocata',
|
||||
warnings.append,
|
||||
errors.append,
|
||||
)
|
||||
self.assertEqual(0, len(warnings))
|
||||
self.assertEqual(1, len(errors))
|
||||
|
||||
def test_version_not_in_deliverable(self):
|
||||
deliverable_data = textwrap.dedent('''
|
||||
releases:
|
||||
@ -1437,6 +1460,31 @@ class TestValidateFeatureBranches(base.BaseTestCase):
|
||||
self.assertEqual(0, len(warnings))
|
||||
self.assertEqual(0, len(errors))
|
||||
|
||||
def test_badly_formatted_name(self):
|
||||
deliverable_data = textwrap.dedent('''
|
||||
releases:
|
||||
- version: 1.5.0
|
||||
projects:
|
||||
- repo: openstack/automaton
|
||||
hash: be2885f544637e6ee6139df7dc7bf937925804dd
|
||||
branches:
|
||||
- name: abc
|
||||
location:
|
||||
openstack/automaton: be2885f544637e6ee6139df7dc7bf937925804dd
|
||||
''')
|
||||
warnings = []
|
||||
errors = []
|
||||
deliverable_info = yaml.safe_load(deliverable_data)
|
||||
validate.validate_feature_branches(
|
||||
deliverable_info,
|
||||
self.tmpdir,
|
||||
warnings.append,
|
||||
errors.append,
|
||||
)
|
||||
print(warnings, errors)
|
||||
self.assertEqual(0, len(warnings))
|
||||
self.assertEqual(1, len(errors))
|
||||
|
||||
def test_location_no_such_sha(self):
|
||||
deliverable_data = textwrap.dedent('''
|
||||
releases:
|
||||
@ -1568,6 +1616,31 @@ class TestValidateDriverfixesBranches(base.BaseTestCase):
|
||||
self.assertEqual(0, len(warnings))
|
||||
self.assertEqual(0, len(errors))
|
||||
|
||||
def test_badly_formatted_name(self):
|
||||
deliverable_data = textwrap.dedent('''
|
||||
releases:
|
||||
- version: 1.5.0
|
||||
projects:
|
||||
- repo: openstack/automaton
|
||||
hash: be2885f544637e6ee6139df7dc7bf937925804dd
|
||||
branches:
|
||||
- name: austin
|
||||
location:
|
||||
openstack/automaton: be2885f544637e6ee6139df7dc7bf937925804dd
|
||||
''')
|
||||
warnings = []
|
||||
errors = []
|
||||
deliverable_info = yaml.safe_load(deliverable_data)
|
||||
validate.validate_driverfixes_branches(
|
||||
deliverable_info,
|
||||
self.tmpdir,
|
||||
warnings.append,
|
||||
errors.append,
|
||||
)
|
||||
print(warnings, errors)
|
||||
self.assertEqual(0, len(warnings))
|
||||
self.assertEqual(1, len(errors))
|
||||
|
||||
def test_location_no_such_sha(self):
|
||||
deliverable_data = textwrap.dedent('''
|
||||
releases:
|
||||
|
Loading…
Reference in New Issue
Block a user