Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
fix(cognito): parse quoted attribute names in ListUsers Filter (#1050)
kjdevc69a4de8a6c5
diff --git a/ministack/services/cognito.py b/ministack/services/cognito.pyindex b81ab244..e5de65d5 100644--- a/ministack/services/cognito.py+++ b/ministack/services/cognito.py@@ -4810,13 +4810,15 @@ def _generate_temp_password() -> str:def _apply_user_filter(users: list, filter_str: str) -> list:"""- Supports simple Cognito filter syntax:- attribute_name = "value"- attribute_name ^= "value" (starts with)+ Supports Cognito filter syntax:+ "attribute_name" = "value" (AWS official syntax; attribute name quoted)+ attribute_name = "value" (unquoted, kept for backward compatibility)+ attribute_name ^= "value" (starts with)attribute_name != "value""""- m = re.match(r'(\w+)\s*(=|\^=|!=)\s*"([^"]*)"', filter_str.strip())+ m = re.match(r'"?(\w+)"?\s*(=|\^=|!=)\s*"([^"]*)"', filter_str.strip())if not m:+ logger.warning("Cognito: ListUsers Filter could not be parsed, ignoring: %r", filter_str)return usersattr_name, op, value = m.group(1), m.group(2), m.group(3)result = []diff --git a/tests/test_cognito.py b/tests/test_cognito.pyindex 27e4bedc..0cd07b92 100644--- a/tests/test_cognito.py+++ b/tests/test_cognito.py@@ -126,6 +126,26 @@ def test_cognito_list_users_filter(cognito_idp):assert len(users) == 1assert users[0]["Username"] == "bob"+def test_cognito_list_users_filter_quoted_attribute_name(cognito_idp):+ pid = cognito_idp.create_user_pool(PoolName="QuotedFilterUsersPool")["UserPool"]["Id"]+ cognito_idp.admin_create_user(+ UserPoolId=pid,+ Username="bob",+ UserAttributes=[{"Name": "email", "Value": "[email protected]"}],+ )+ cognito_idp.admin_create_user(+ UserPoolId=pid,+ Username="charlie",+ UserAttributes=[{"Name": "email", "Value": "[email protected]"}],+ )+ resp = cognito_idp.list_users(UserPoolId=pid, Filter='"email" = "[email protected]"')+ users = resp["Users"]+ assert len(users) == 1+ assert users[0]["Username"] == "bob"++ resp = cognito_idp.list_users(UserPoolId=pid, Filter='"email" = "[email protected]"')+ assert resp["Users"] == []+def test_cognito_admin_set_user_password(cognito_idp):pid = cognito_idp.create_user_pool(PoolName="PwdPool")["UserPool"]["Id"]cid = cognito_idp.create_user_pool_client(