From c2ed5662a796b8adb33d485111f57c13e20c2731 Mon Sep 17 00:00:00 2001 From: MrMelon54 Date: Tue, 14 May 2024 11:12:37 +0100 Subject: [PATCH] Add nullauth for testing --- go.mod | 2 +- go.sum | 4 ++-- nullauth.go | 22 ++++++++++++++++++++++ nullauth_stub.go | 7 +++++++ server.go | 9 +++++++-- 5 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 nullauth.go create mode 100644 nullauth_stub.go diff --git a/go.mod b/go.mod index bfdda36..5f16e94 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22 require ( git.sr.ht/~sircmpwn/tokidoki v0.0.0-20240419154046-4ca7d8c4e7ca - github.com/1f349/cardcaldav v0.0.3 + github.com/1f349/cardcaldav v0.0.4 github.com/1f349/violet v0.0.13 github.com/charmbracelet/log v0.4.0 github.com/emersion/go-webdav v0.5.1-0.20240419143909-21f251fa1de2 diff --git a/go.sum b/go.sum index 2a5e5d6..3fa4bfe 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= git.sr.ht/~sircmpwn/tokidoki v0.0.0-20240419154046-4ca7d8c4e7ca h1:HBRu4nwicaaZ4oqwTis2qy4Gb/CKLA2OSlibdKpMhb8= git.sr.ht/~sircmpwn/tokidoki v0.0.0-20240419154046-4ca7d8c4e7ca/go.mod h1:/1jsi+vx9b/T8UHrDRJXwoY8td9JUXd9UajtVCpVoeg= -github.com/1f349/cardcaldav v0.0.3 h1:c2/wmOf+hwgKdaWLlKm5v8l0g9brD+Seqcp+xIDUXJI= -github.com/1f349/cardcaldav v0.0.3/go.mod h1:MCoGRimM7p/rLWtaJxYO91tsvgXZ47M69X3lldb5dfk= +github.com/1f349/cardcaldav v0.0.4 h1:byhhQOFJ2JItbMBp9mUc1hn8KAE22iem8ico4/piyyA= +github.com/1f349/cardcaldav v0.0.4/go.mod h1:MCoGRimM7p/rLWtaJxYO91tsvgXZ47M69X3lldb5dfk= github.com/1f349/violet v0.0.13 h1:lJpTz15Ea83Uc1VAISXTjtKuzr8Pe8NM4cMGp3Aiyhk= github.com/1f349/violet v0.0.13/go.mod h1:Ga5/hWqI+EkR6J1mAMNzs7aJhuGcA89XFqgQaDXC7Jo= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= diff --git a/nullauth.go b/nullauth.go new file mode 100644 index 0000000..7f79cbe --- /dev/null +++ b/nullauth.go @@ -0,0 +1,22 @@ +//go:build nullauth + +package jasmine + +import ( + "context" + "net/http" +) + +type nullAuth struct{} + +func (n *nullAuth) Middleware(next http.Handler) http.Handler { + return next +} + +func (n *nullAuth) CurrentUserPrincipal(ctx context.Context) (string, error) { + return "/jane@example.com/", nil +} + +func NullAuth(_ AuthProvider) AuthProvider { + return &nullAuth{} +} diff --git a/nullauth_stub.go b/nullauth_stub.go new file mode 100644 index 0000000..2fdb82e --- /dev/null +++ b/nullauth_stub.go @@ -0,0 +1,7 @@ +//go:build !nullauth + +package jasmine + +func NullAuth(provider AuthProvider) AuthProvider { + return provider +} diff --git a/server.go b/server.go index 490911f..fe560e2 100644 --- a/server.go +++ b/server.go @@ -16,7 +16,7 @@ type Conf struct { } type jasmineHandler struct { - auth *cardcaldav.Auth + auth AuthProvider backend caldav.Backend } @@ -55,9 +55,14 @@ func (j *jasmineHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { http.NotFound(rw, req) } +type AuthProvider interface { + cardcaldav.ProviderMiddleware + webdav.UserPrincipalBackend +} + func NewHttpServer(conf Conf, wd string) *http.Server { cardcaldav.SetupLogger(Logger) - principle := cardcaldav.NewAuth(conf.DB, Logger) + principle := NullAuth(cardcaldav.NewAuth(conf.DB, Logger)) calStorage, _, err := storage.NewFilesystem(filepath.Join(wd, "storage"), "/calendar/", "/contacts/", principle) if err != nil {