mirror of
https://github.com/authelia/authelia.git
synced 2026-10-28 09:34:52 +08:00
Pointing the filesystem notifier at a fifo previously panicked: `StartupCheck` truncated the path with `os.WriteFile`, which on a fifo opens `O_WRONLY|O_CREATE|O_TRUNC` and blocks until a reader connects, and `Send` always called `f.Sync()`, which returns `EINVAL` on a pipe. `FileNotifier` now stat-checks the destination via `os.ModeNamedPipe`. When the path is a fifo, `StartupCheck` skips the empty-write step and `Send` opens with `O_WRONLY` only and skips the trailing `f.Sync()`. Detection is per-call so it works whether or not `disable_startup_check` is set, and it survives the operator replacing the file between startup and runtime. Behaviour for regular files is byte-identical to before, including the `O_TRUNC` / `O_APPEND` open flags and the `Sync` call. The bytes written to the destination (`Date:` / `Recipient:` / `Subject:` header, rendered template body, double newline) are identical regardless of whether the destination is a regular file or a fifo, so existing parsers continue to work. The fifo must be pre-created by the operator with `mkfifo` and a reader must be attached on the other end; if no reader is connected when a notification is generated, `Send` blocks until one is, matching POSIX fifo semantics. A new `authelia debug notification` subcommand is added alongside `authelia debug tls` / `expression` / `oidc`. It loads the configuration, runs the notifier startup check, and dispatches a single test notification using the configured notifier (SMTP or filesystem). It is useful as an ops tool for verifying that the SMTP server, filesystem path, or fifo consumer is reachable, and is the deterministic, browser-free trigger used by the new CLI suite tests. Coverage for the fifo branches is added in `internal/notification/file_notifier_test.go` (`TestIsFIFO`, fifo `StartupCheck`, fifo `Send` end-to-end via `syscall.Mkfifo` plus a reader goroutine), and the CLI integration suite gains two end-to-end tests: `TestShouldDeliverSequentialNotificationsToFIFOViaDebugCommand` runs three notifications back-to-back through fresh `O_RDONLY` readers to validate pipe re-use, and `TestShouldDeliverConcurrentNotificationsToFIFOViaDebugCommand` holds the fifo open `O_RDWR` while two `authelia debug notification` invocations write concurrently and asserts both subjects land intact. Closes #11386. --------- Signed-off-by: Amir Zarrinkafsh <3339418+nightah@users.noreply.github.com> Co-authored-by: James Elliott <james-d-elliott@users.noreply.github.com>