mirror of
https://github.com/multipleof4/ntfy.git
synced 2026-10-08 21:05:21 +00:00
WIP: Access cache
This commit is contained in:
@@ -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{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user