Merge pull request #2357 from brodie-g/master

Existing user now raises a UsernameExistsException
This commit is contained in:
Mike Grima 2019-10-14 09:33:56 -07:00 committed by GitHub
commit cc96a5e659
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 1 deletions

View file

@ -24,6 +24,16 @@ class UserNotFoundError(BadRequest):
})
class UsernameExistsException(BadRequest):
def __init__(self, message):
super(UsernameExistsException, self).__init__()
self.description = json.dumps({
"message": message,
'__type': 'UsernameExistsException',
})
class GroupExistsException(BadRequest):
def __init__(self, message):

View file

@ -14,7 +14,8 @@ from jose import jws
from moto.compat import OrderedDict
from moto.core import BaseBackend, BaseModel
from .exceptions import GroupExistsException, NotAuthorizedError, ResourceNotFoundError, UserNotFoundError
from .exceptions import GroupExistsException, NotAuthorizedError, ResourceNotFoundError, UserNotFoundError, \
UsernameExistsException
UserStatus = {
"FORCE_CHANGE_PASSWORD": "FORCE_CHANGE_PASSWORD",
@ -561,6 +562,9 @@ class CognitoIdpBackend(BaseBackend):
if not user_pool:
raise ResourceNotFoundError(user_pool_id)
if username in user_pool.users:
raise UsernameExistsException(username)
user = CognitoIdpUser(user_pool_id, username, temporary_password, UserStatus["FORCE_CHANGE_PASSWORD"], attributes)
user_pool.users[user.username] = user
return user