WIP: Access cache

This commit is contained in:
binwiederhier
2026-05-28 17:13:14 -04:00
parent 47044c632e
commit 25520c4505
11 changed files with 601 additions and 64 deletions
+7
View File
@@ -7,6 +7,7 @@ import (
"heckel.io/ntfy/v2/server"
"heckel.io/ntfy/v2/test"
"testing"
"time"
)
func TestCLI_Access_Show(t *testing.T) {
@@ -43,6 +44,12 @@ user * (role: anonymous, tier: none)
`
require.Equal(t, expected, stdout.String())
// The CLI commands above ran against a separate Manager instance (their own
// process-equivalent), so the server's ACL cache hasn't seen the new grants
// yet. Wait for the server's background reloader (interval set in
// newTestServerWithAuth) to pick them up.
time.Sleep(150 * time.Millisecond)
// See if access permissions match
app, _, _, _ = newTestApp()
require.Error(t, app.Run([]string{
+5
View File
@@ -378,6 +378,11 @@ func createUserManager(c *cli.Context) (*user.Manager, error) {
ProvisionEnabled: false, // Hack: Do not re-provision users on manager initialization
BcryptCost: user.DefaultUserPasswordBcryptCost,
QueueWriterInterval: user.DefaultUserStatsQueueWriterInterval,
// CLI Managers are short-lived; the background ACL cache poller would only
// spam "database is closed" warnings after the subcommand returns. Mutations
// still refresh the local cache synchronously; the running server (if any)
// picks them up via its own poller.
AccessCacheReloadInterval: -1,
}
if databaseURL != "" {
host, dbErr := pg.Open(databaseURL)
+5
View File
@@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"testing"
"time"
)
func TestCLI_User_Add(t *testing.T) {
@@ -128,6 +129,10 @@ func newTestServerWithAuth(t *testing.T) (s *server.Server, conf *server.Config,
conf.File = configFile
conf.AuthFile = filepath.Join(t.TempDir(), "user.db")
conf.AuthDefault = user.PermissionDenyAll
// Tight interval so cross-process writes from the `ntfy access`/`ntfy user`
// CLI commands (which run via a separate Manager) propagate to the server's
// ACL cache within tens of ms instead of the default 5s.
conf.AuthAccessCacheReloadInterval = 25 * time.Millisecond
s, port = test.StartServerWithConfig(t, conf)
return
}