Add nullauth for testing

This commit is contained in:
Melon 2024-05-14 11:12:37 +01:00
parent c4c2d8bd33
commit c2ed5662a7
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
5 changed files with 39 additions and 5 deletions

2
go.mod
View File

@ -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

4
go.sum
View File

@ -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=

22
nullauth.go Normal file
View File

@ -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{}
}

7
nullauth_stub.go Normal file
View File

@ -0,0 +1,7 @@
//go:build !nullauth
package jasmine
func NullAuth(provider AuthProvider) AuthProvider {
return provider
}

View File

@ -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 {