Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

Fix Cognito ListUsers status filter matching wrong field (#1082)

Jey MFV375a5aac688e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fabaaaf9..4cc88c51 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,8 @@ Versioning follows [Semantic Versioning](https://semver.org/).
## [Unreleased]
+### Fixed
+- **Cognito — `ListUsers` `status` filter matched against the wrong field** — `Filter='status = "Enabled"'`/`"Disabled"` was compared against `UserStatus` (the confirmation-state enum: `CONFIRMED`, `FORCE_CHANGE_PASSWORD`, `UNCONFIRMED`, etc.), which never equals the literal string `"Enabled"`/`"Disabled"`. As a result, filtering by `status` always returned an empty list, regardless of how many users existed or their actual enabled/disabled state. `status` now correctly reflects the account's `Enabled` boolean toggled by `AdminEnableUser`/`AdminDisableUser`, matching real AWS Cognito's `ListUsers` Filter semantics. Contributed by @jey-mfv.
### Added
- **IoT — MQTT publishes are routed through topic rules to Lambda** — an MQTT/`iot-data` publish is now matched against each account's topic rules by the rule's `FROM '<topic filter>'` clause (with `+`/`#` wildcards), and every matching enabled rule's `lambda` actions are invoked asynchronously with the message payload as the event (`SELECT *`). Basic Ingest is supported: a publish to `$aws/rules/<ruleName>` is delivered straight to that rule's actions and bypasses pub/sub. Disabled rules are skipped.
diff --git a/ministack/services/cognito.py b/ministack/services/cognito.py
index e5de65d5..9bc08e92 100644
--- a/ministack/services/cognito.py
+++ b/ministack/services/cognito.py
@@ -4829,7 +4829,11 @@ def _apply_user_filter(users: list, filter_str: str) -> list:
if attr_name == "username":
field_val = user.get("Username", "")
elif attr_name == "status":
- field_val = user.get("UserStatus", "")
+ # "status" filters on the account's Enabled/Disabled state (toggled by
+ # AdminEnableUser/AdminDisableUser), not the UserStatus confirmation-state enum
+ # (CONFIRMED, FORCE_CHANGE_PASSWORD, etc.). Matches real AWS Cognito's ListUsers
+ # Filter semantics, where "status" = "Enabled" never matches UserStatus values.
+ field_val = "Enabled" if user.get("Enabled", True) else "Disabled"
elif attr_name == "email_verified":
field_val = attr_dict.get("email_verified", "")
if op == "=" and field_val == value:
diff --git a/tests/test_cognito.py b/tests/test_cognito.py
index 0cd07b92..545fbde0 100644
--- a/tests/test_cognito.py
+++ b/tests/test_cognito.py
@@ -146,6 +146,20 @@ def test_cognito_list_users_filter_quoted_attribute_name(cognito_idp):
resp = cognito_idp.list_users(UserPoolId=pid, Filter='"email" = "[email protected]"')
assert resp["Users"] == []
+def test_cognito_list_users_filter_status(cognito_idp):
+ pid = cognito_idp.create_user_pool(PoolName="StatusFilterUsersPool")["UserPool"]["Id"]
+ cognito_idp.admin_create_user(UserPoolId=pid, Username="active-user")
+ cognito_idp.admin_create_user(UserPoolId=pid, Username="disabled-user")
+ cognito_idp.admin_disable_user(UserPoolId=pid, Username="disabled-user")
+
+ resp = cognito_idp.list_users(UserPoolId=pid, Filter='status = "Enabled"')
+ usernames = [u["Username"] for u in resp["Users"]]
+ assert usernames == ["active-user"]
+
+ resp = cognito_idp.list_users(UserPoolId=pid, Filter='status = "Disabled"')
+ usernames = [u["Username"] for u in resp["Users"]]
+ assert usernames == ["disabled-user"]
+
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(