1
1
mirror of https://github.com/docker-mailserver/docker-mailserver synced 2024-09-28 17:21:51 +02:00
docker-mailserver/test/config
Brennan Kinney f3a7f08f96
tests: Revise OAuth2 tests (#3795)
* tests: OAuth2 - Replace Python `/userinfo` endpoint with Caddy

Better documented, easier flow and separation of concerns via Caddy.

The python code had additional noise related to setting up a basic API which is abstracted away via `Caddyfile` config that's dedicated to this task.

* tests: OAuth2 - Minimize noise + Improve test assertion

Caddyfile can use an Access Token instead of a JWT. Much smaller and correct for this OAuth2 configuration. This new value has been documented inline.

Likewise the `sub` field returned is not important to this test. `email_verified` is kept as it may be helpful for further coverage testing.

The actual test-case has better assertions for success and failure by checking for Dovecot logs we expect instead of netcat response.

`oauth2` to `auth` for the Caddy container hostname is not necessary, just a more generic subdomain choice.

* tests: OAuth2 - Caddyfile `imap/xoauth2` route dynamic via query string

This way is more flexible and doesn't require modifying the `Caddyfile` directly, while still easy to use.

Additionally simplifies understanding the Caddyfile to maintainers by removing the `route` directive that was required to ensure a deterministic order of vars.

* tests: OAuth2 - `/imap/xoauth2` respond with IMAP commands for netcat

Since this is the only intended usage, might as well have it respond with the full file content.

* tests: OAuth2 - Implement coverage for `OAUTHBEARER`

Caddyfile route for `/imap/` now accepts any subpath to support handling both `xoauth2` and `oauthbearer` subpaths.

Both SASL mechanisms represent the same information, with `XOAUTH2` being a common mechanism to encounter defined by Google, whilst `OAUTHBEARER` is the newer variant standardized by RFC 7628 but not yet as widely adopted.

The request to `/userinfo` endpoint will be the same, only the `credentials` value to be encoded differs.

Instead of repeating the block for a similar route, this difference is handled via the Caddyfile `map` directive.

We match the path context (_`/xoauth2` or `/oauthbearer`, the `/imap` prefix was stripped by `handle_path` earlier_), when there is a valid match, `sasl_mechanism` and `credentials` map vars are created and assigned to be referenced by the later `respond` directive.

---

Repeat the same test-case logic, DRY with log asserts extracted to a common function call. This should be fine as the auth method will be sufficient to match against or a common failure caught.

* tests: OAuth2 - Minor revisions

Separate test cases and additional comment on creating the same base64 encoded credentials via CLI as an alternative to running Caddy.

Added a simple `compose.yaml` for troubleshooting or running the container for the `/imap/xoauth2` / `/imap/oauthbearer` endpoints.

* tests: OAuth2 - Route endpoints in Caddyfile with snippets instead

`reverse_proxy` was a bit more convenient, but the additional internal ports weren't really relevant. It also added noise to logging when troubleshooting.

The `import` directive with Snippet blocks instead is a bit cleaner, but when used in a single file snippets must be defined prior to referencing them with the `import` directive.

---

`compose.yaml` inlines the examples, with slight modification to `localhost:80`, since the Caddyfile examples `auth.example.test` is more relevant to the tests which can use it, and not applicable to troubleshooting locally outside of tests.

* chore: Add entry to `CHANGELOG.md`

* chore: Additional context on access token
2024-01-20 10:49:09 +01:00
..
dovecot-lmtp config: ensure SASL socket file is not inside a volume mount (#3131) 2023-03-03 23:42:55 +01:00
dovecot-sieve tests: Extract some test cases out from tests.bats (#2980) 2023-01-07 11:36:20 +13:00
dsn feat: Postfix permit DSN (Delivery Status Notification) only on authenticated ports (465 + 587) (#3572) 2023-10-22 15:16:41 +02:00
duplicate_config_test Fix linter issue 2020-10-20 15:02:31 +02:00
example-opendkim ci(fix): Normalize for .gitattributes + improve eclint coverage (#3566) 2023-10-04 12:53:32 +02:00
fetchmail ci(fix): Normalize for .gitattributes + improve eclint coverage (#3566) 2023-10-04 12:53:32 +02:00
getmail feature: adding getmail as an alternative to fetchmail (#2803) 2023-05-23 17:25:08 +02:00
ldap ci(fix): Normalize for .gitattributes + improve eclint coverage (#3566) 2023-10-04 12:53:32 +02:00
oauth2 tests: Revise OAuth2 tests (#3795) 2024-01-20 10:49:09 +01:00
override-configs ci(fix): Normalize for .gitattributes + improve eclint coverage (#3566) 2023-10-04 12:53:32 +02:00
relay-hosts Update relayhost_map with virtual accounts too 2020-08-28 15:03:51 +02:00
rspamd_full scripts: Rspamd stabilization pt. 2 (#3282) 2023-04-23 14:02:56 +02:00
smtp-delivery tests: Extract some test cases out from tests.bats (#2980) 2023-01-07 11:36:20 +13:00
templates ci(fix): Normalize for .gitattributes + improve eclint coverage (#3566) 2023-10-04 12:53:32 +02:00
user-patches Remove unusual space from shebang line (#2834) 2022-10-17 10:40:09 +02:00
without-accounts Reinstane required (empty) folder 2020-10-18 02:25:03 +02:00
amavis.cf Allow user to provide Amavis configuration (#299) 2016-09-02 09:08:41 +02:00
fail2ban-fail2ban.cf Add ability to override fail2ban.conf with fail2ban.local values. (#769) 2017-12-07 19:27:31 +01:00
fail2ban-jail.cf firewall: replace iptables with nftables (#2505) 2022-04-05 15:13:59 +02:00
postfix-regexp.cf ci(fix): Normalize for .gitattributes + improve eclint coverage (#3566) 2023-10-04 12:53:32 +02:00
postfix-virtual.cf ci(fix): Normalize for .gitattributes + improve eclint coverage (#3566) 2023-10-04 12:53:32 +02:00
whitelist_clients.local Include whitelist_clients.local in postgrey setup from config folder (#564) 2017-04-12 17:59:04 +02:00
whitelist_recipients Support for additional postgrey options (Close: #998, #999, #1046) 2018-11-01 19:32:36 +01:00