webadmin: make routes configurable: globally, per domain, per account

this simplifies some of the code that makes modifications to the config file. a
few protected functions can make changes to the dynamic config, which webadmin
can use. instead of having separate functions in mox-/admin.go for each type of
change.

this also exports the parsed full dynamic config to webadmin, so we need fewer
functions for specific config fields too.
This commit is contained in:
Mechiel Lukkien
2024-04-18 11:14:24 +02:00
parent baf4df55a6
commit a69887bfab
19 changed files with 1165 additions and 189 deletions

View File

@ -209,10 +209,18 @@ func TestAdminAuth(t *testing.T) {
api.Logout(ctx)
tneedErrorCode(t, "server:error", func() { api.Logout(ctx) })
}
err = queue.Init()
func TestAdmin(t *testing.T) {
os.RemoveAll("../testdata/webadmin/data")
mox.ConfigStaticPath = filepath.FromSlash("../testdata/webadmin/mox.conf")
mox.ConfigDynamicPath = filepath.Join(filepath.Dir(mox.ConfigStaticPath), "domains.conf")
mox.MustLoadConfig(true, false)
err := queue.Init()
tcheck(t, err, "queue init")
api := Admin{}
mrl := api.RetiredList(ctxbg, queue.RetiredFilter{}, queue.RetiredSort{})
tcompare(t, len(mrl), 0)
@ -233,6 +241,22 @@ func TestAdminAuth(t *testing.T) {
n = api.HookCancel(ctxbg, queue.HookFilter{})
tcompare(t, n, 0)
api.Config(ctxbg)
api.DomainConfig(ctxbg, "mox.example")
tneedErrorCode(t, "user:error", func() { api.DomainConfig(ctxbg, "bogus.example") })
api.AccountRoutesSave(ctxbg, "mjl", []config.Route{{Transport: "direct"}})
tneedErrorCode(t, "user:error", func() { api.AccountRoutesSave(ctxbg, "mjl", []config.Route{{Transport: "bogus"}}) })
api.AccountRoutesSave(ctxbg, "mjl", nil)
api.DomainRoutesSave(ctxbg, "mox.example", []config.Route{{Transport: "direct"}})
tneedErrorCode(t, "user:error", func() { api.DomainRoutesSave(ctxbg, "mox.example", []config.Route{{Transport: "bogus"}}) })
api.DomainRoutesSave(ctxbg, "mox.example", nil)
api.RoutesSave(ctxbg, []config.Route{{Transport: "direct"}})
tneedErrorCode(t, "user:error", func() { api.RoutesSave(ctxbg, []config.Route{{Transport: "bogus"}}) })
api.RoutesSave(ctxbg, nil)
}
func TestCheckDomain(t *testing.T) {