Catch empty artifact names

In case a planfile specifies a null name for an artifact,
anticipate the TypeError and correctly count the name as invalid.

Closes-Bug: #1442789

Change-Id: Ia412c8b59ba369c1f111090c55c02cad216a566d
This commit is contained in:
Ed Cranford
2015-04-13 13:35:45 -05:00
parent cee7128a89
commit 29a2cf13f6
3 changed files with 29 additions and 2 deletions

View File

@@ -79,7 +79,7 @@ def ValidName(string):
def lpname_is_valid(string):
try:
re.match(r'^([a-z0-9-_]{1,100})$', string).group(0)
except AttributeError:
except (TypeError, AttributeError):
return False
return True

View File

@@ -289,6 +289,32 @@ class TestSolum(base.TestCase):
"characters and must only contain "
"a-z,A-Z,0-9,-,_\n", out)
def test_app_create_with_bad_artifact_name(self):
raw_data = '\n'.join([
'version: 1',
'name: explan1',
'description: python web app',
'artifacts:',
'- name:',
' content:',
' href: https://example.com',
' language_pack: auto',
' unittest_cmd: ./unit_tests.sh',
' run_cmd: python app.py',
' ports: 5000'])
mopen = mock.mock_open(read_data=raw_data)
with mock.patch('%s.open' % solum.__name__, mopen, create=True):
self.make_env()
out = self.shell("app create --plan-file /dev/null")
# No part of the plan is in error; the next step in the test
# is authorization, which is deliberately mocked.
self.assertEqual("ERROR: "
"Authorization Failed: Unable to establish "
"connection to http://no.where/tokens\n", out)
def test_app_create_with_artifacts_empty(self):
raw_data = 'version: 1\nname: ex_plan1\ndescription: dsc1.\nartifacts:'
mopen = mock.mock_open(read_data=raw_data)

View File

@@ -105,7 +105,8 @@ class PlanManager(solum_base.CrudManager, solum_base.FindMixin):
resp = self.client.post(
self.build_url(base_url="/v1", **kwargs), **kwargs)
except Exception as e:
raise exceptions.BadRequest(message=e.details)
message = vars(e).get('details', str(e))
raise exceptions.BadRequest(message=message)
try:
resp_plan = yamlutils.load(resp.content)
except ValueError as e: