added cognito idp function admin_set_user_password to the code (#3328)
* added cognito idp function to the code * fixed linting issues
This commit is contained in:
parent
0b9903a3df
commit
2e0e542efe
@ -1687,7 +1687,7 @@
|
||||
- [ ] admin_reset_user_password
|
||||
- [ ] admin_respond_to_auth_challenge
|
||||
- [ ] admin_set_user_mfa_preference
|
||||
- [ ] admin_set_user_password
|
||||
- [X] admin_set_user_password
|
||||
- [ ] admin_set_user_settings
|
||||
- [ ] admin_update_auth_event_feedback
|
||||
- [ ] admin_update_device_status
|
||||
|
@ -353,7 +353,6 @@ class CognitoIdpUser(BaseModel):
|
||||
|
||||
class CognitoResourceServer(BaseModel):
|
||||
def __init__(self, user_pool_id, identifier, name, scopes):
|
||||
|
||||
self.user_pool_id = user_pool_id
|
||||
self.identifier = identifier
|
||||
self.name = name
|
||||
@ -1035,6 +1034,14 @@ class CognitoIdpBackend(BaseBackend):
|
||||
else:
|
||||
raise NotAuthorizedError(access_token)
|
||||
|
||||
def admin_set_user_password(self, user_pool_id, username, password, permanent):
|
||||
user = self.admin_get_user(user_pool_id, username)
|
||||
user.password = password
|
||||
if permanent:
|
||||
user.status = UserStatus["CONFIRMED"]
|
||||
else:
|
||||
user.status = UserStatus["FORCE_CHANGE_PASSWORD"]
|
||||
|
||||
|
||||
cognitoidp_backends = {}
|
||||
for region in Session().get_available_regions("cognito-idp"):
|
||||
|
@ -449,6 +449,16 @@ class CognitoIdpResponse(BaseResponse):
|
||||
)
|
||||
return ""
|
||||
|
||||
def admin_set_user_password(self):
|
||||
user_pool_id = self._get_param("UserPoolId")
|
||||
username = self._get_param("Username")
|
||||
password = self._get_param("Password")
|
||||
permanent = self._get_param("Permanent")
|
||||
cognitoidp_backends[self.region].admin_set_user_password(
|
||||
user_pool_id, username, password, permanent
|
||||
)
|
||||
return ""
|
||||
|
||||
|
||||
class CognitoIdpJsonWebKeyResponse(BaseResponse):
|
||||
def __init__(self):
|
||||
|
@ -1816,6 +1816,30 @@ def test_respond_to_auth_challenge_with_invalid_secret_hash():
|
||||
caught.should.be.true
|
||||
|
||||
|
||||
@mock_cognitoidp
|
||||
def test_admin_set_user_password():
|
||||
conn = boto3.client("cognito-idp", "us-west-2")
|
||||
|
||||
username = str(uuid.uuid4())
|
||||
value = str(uuid.uuid4())
|
||||
password = str(uuid.uuid4())
|
||||
user_pool_id = conn.create_user_pool(PoolName=str(uuid.uuid4()))["UserPool"]["Id"]
|
||||
conn.admin_create_user(
|
||||
UserPoolId=user_pool_id,
|
||||
Username=username,
|
||||
UserAttributes=[{"Name": "thing", "Value": value}],
|
||||
)
|
||||
conn.admin_set_user_password(
|
||||
UserPoolId=user_pool_id, Username=username, Password=password, Permanent=True
|
||||
)
|
||||
result = conn.admin_get_user(UserPoolId=user_pool_id, Username=username)
|
||||
result["Username"].should.equal(username)
|
||||
result["UserAttributes"].should.have.length_of(1)
|
||||
result["UserAttributes"][0]["Name"].should.equal("thing")
|
||||
result["UserAttributes"][0]["Value"].should.equal(value)
|
||||
result["UserStatus"].should.equal("CONFIRMED")
|
||||
|
||||
|
||||
# Test will retrieve public key from cognito.amazonaws.com/.well-known/jwks.json,
|
||||
# which isnt mocked in ServerMode
|
||||
if not settings.TEST_SERVER_MODE:
|
||||
|
Loading…
Reference in New Issue
Block a user