zulip/zerver
Mateusz Mandera 6dd6fc045f realm_settings: Improve authentication_methods param validation.
The endpoint was lacking validation that the authentication_methods dict
submitted by the user made sense. So e.g. it allowed submitting a
nonsense key like NoSuchBackend or modifying the realm's configured
authentication methods for a backend that's not enabled on the server,
which should not be allowed.

Both were ultimately harmless, because:
1. Submitting NoSuchBackend would luckily just trigger a KeyError inside
   the transaction.atomic() block in do_set_realm_authentication_methods
   so it would actually roll back the database changes it was trying to
   make. So this couldn't actually create some weird
   RealmAuthenticationMethod entries.
2. Silently enabling or disabling e.g. GitHub for a realm when GitHub
   isn't enabled on the server doesn't really change anything. And this
   action is only available to the realm's admins to begin with, so
   there's no attack vector here.

test_supported_backends_only_updated wasn't actually testing anything,
because the state it was asserting:
```
        self.assertFalse(github_auth_enabled(realm))
        self.assertTrue(dev_auth_enabled(realm))
        self.assertFalse(password_auth_enabled(realm))
```

matched the desired state submitted to the API...
```
        result = self.client_patch(
            "/json/realm",
            {
                "authentication_methods": orjson.dumps(
                    {"Email": False, "Dev": True, "GitHub": False}
                ).decode()
            },
        )
```

so we just replace it with a new test that tests the param validation.
2024-02-02 17:26:32 -08:00
..
actions realm_settings: Improve authentication_methods param validation. 2024-02-02 17:26:32 -08:00
data_import ruff: Fix SIM113 Use `enumerate()` for index variable in `for` loop. 2024-02-02 10:30:45 -08:00
integration_fixtures/nagios
lib ruff: Fix SIM113 Use `enumerate()` for index variable in `for` loop. 2024-02-02 10:30:45 -08:00
management requirements: Upgrade Python requirements. 2024-01-29 10:41:54 -08:00
migrations ruff: Fix SIM113 Use `enumerate()` for index variable in `for` loop. 2024-02-02 10:30:45 -08:00
models ruff: Fix DJ012 Order of model's inner classes, methods, and fields. 2024-01-29 10:41:54 -08:00
openapi requirements: Upgrade Python requirements. 2024-01-29 10:41:54 -08:00
tests realm_settings: Improve authentication_methods param validation. 2024-02-02 17:26:32 -08:00
tornado ruff: Fix SIM910 Use `d.get(…)` instead of `d.get(…, None)`. 2024-02-02 10:30:45 -08:00
transaction_tests models: Extract zerver.models.realms. 2023-12-16 22:08:44 -08:00
views realm_settings: Improve authentication_methods param validation. 2024-02-02 17:26:32 -08:00
webhooks ruff: Fix RUF019 Unnecessary key check before dictionary access. 2024-02-02 10:30:45 -08:00
worker queue_processors: Process user_activity in one query. 2024-01-22 16:25:13 -08:00
__init__.py
apps.py mypy: Enable new error explicit-override. 2023-10-12 12:28:41 -07:00
context_processors.py login: Remove external_authentication_methods from page_params. 2023-12-29 13:02:12 -08:00
decorator.py requirements: Upgrade Python requirements. 2024-01-29 10:41:54 -08:00
filters.py mypy: Enable new error explicit-override. 2023-10-12 12:28:41 -07:00
forms.py models: Extract zerver.models.realms. 2023-12-16 22:08:44 -08:00
logging_handlers.py error_notify: Remove custom email error reporting handler. 2023-07-20 11:00:09 -07:00
middleware.py csrf_failure: Update error page. 2024-01-10 09:49:24 -08:00
signals.py email: Add a space after the time and AM/PM in the login email. 2023-11-27 09:47:30 -08:00