Merge "Modify User Attributes API - Fix"

This commit is contained in:
Jenkins 2013-09-10 01:53:07 +00:00 committed by Gerrit Code Review
commit 175057fdcb
4 changed files with 25 additions and 10 deletions

View File

@ -57,7 +57,7 @@ non_empty_string = {
host_string = {
"type": "string",
"minLength": 0,
"minLength": 1,
"pattern": "^[%]?[\w(-).]*[%]?$"
}

View File

@ -346,13 +346,11 @@ class MySqlAdmin(object):
new_host=user_attrs.get('host'))
t = text(str(uu))
client.execute(t)
if user_attrs.get('name') is not None:
if user_attrs['name'] not in grantee:
if user_attrs.get('host') is None:
host = user.host
else:
host = user_attrs.get('host')
self.grant_access(user_attrs['name'], host, db_access)
uname = user_attrs.get('name') or username
host = user_attrs.get('host') or hostname
find_user = "'%s'@'%s'" % (uname, host)
if find_user not in grantee:
self.grant_access(uname, host, db_access)
def create_database(self, databases):
"""Create the list of specified databases"""

View File

@ -276,6 +276,23 @@ class TestUsers(object):
self.dbaas.users.update_attributes, instance_info.id,
"root", user_new)
@test()
def test_updateuser_emptyhost(self):
# Cannot update the user hostname with an empty string
users = []
username = "testuser1"
hostname = "192.168.0.1"
users.append({"name": username, "password": "password",
"host": hostname, "databases": []})
self.dbaas.users.create(instance_info.id, users)
user_new = {"host": ""}
hostname = hostname.replace('.', '%2e')
assert_raises(exceptions.BadRequest,
self.dbaas.users.update_attributes, instance_info.id,
username, user_new, hostname)
assert_equal(400, self.dbaas.last_http_code)
self.dbaas.users.delete(instance_info.id, username, hostname=hostname)
@test(depends_on=[test_create_users])
def test_hostname_ipv4_restriction(self):
# By default, user hostnames are required to be % or IPv4 addresses.

View File

@ -106,13 +106,13 @@ class FakeGuest(object):
self._create_user({
"_name": name,
"_host": host,
"_password": self.users[(name, host)]['password'],
"_password": self.users[(old_name, host)]['_password'],
"_databases": [],
})
self.grants[(name, host)] = old_grants
del self.users[(old_name, old_host)]
if new_password:
self.users[(name, host)]['password'] = new_password
self.users[(name, host)]['_password'] = new_password
def create_database(self, databases):
for db in databases: