diff --git a/murano/api/v1/environments.py b/murano/api/v1/environments.py index 57ba93645..8818cbde8 100644 --- a/murano/api/v1/environments.py +++ b/murano/api/v1/environments.py @@ -52,10 +52,10 @@ class Controller(object): @request_statistics.stats_count(API_NAME, 'Create') def create(self, request, body): - LOG.debug('Environments:Create '.format(body)) + LOG.debug(u'Environments:Create '.format(body)) policy.check('create_environment', request.context) - LOG.debug('ENV NAME: {0}>'.format(body['name'])) - if VALID_NAME_REGEX.match(str(body['name'])): + name = unicode(body['name']) + if VALID_NAME_REGEX.match(name): try: environment = envs.EnvironmentServices.create( body.copy(), diff --git a/murano/tests/unit/api/v1/test_environments.py b/murano/tests/unit/api/v1/test_environments.py index 699d4015e..5aad6a8e8 100644 --- a/murano/tests/unit/api/v1/test_environments.py +++ b/murano/tests/unit/api/v1/test_environments.py @@ -1,3 +1,4 @@ +# coding: utf-8 # Copyright (c) 2014 Hewlett-Packard Development Company, L.P. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -112,6 +113,20 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase): result = req.get_response(self.api) self.assertEqual(400, result.status_code) + def test_unicode_environment_name_create(self): + """Check that an unicode env name results in an HTTPClientError.""" + self._set_policy_rules( + {'list_environments': '@', + 'create_environment': '@', + 'show_environment': '@'} + ) + self.expect_policy_check('create_environment') + + body = {'name': u'yaql ♥ unicode'.encode('utf-8')} + req = self._post('/environments', json.dumps(body)) + result = req.get_response(self.api) + self.assertEqual(400, result.status_code) + def test_missing_environment(self): """Check that a missing environment results in an HTTPNotFound.""" self._set_policy_rules(