diff --git a/sync/http/route.go b/sync/http/route.go index 3eae4a123..254a80bfb 100644 --- a/sync/http/route.go +++ b/sync/http/route.go @@ -51,7 +51,7 @@ func NewOptionsRoute(p string, pr sync.ProcessorFunc, trace bool) Route { return NewRoute(p, http.MethodOptions, pr, trace, nil) } -// NewRoute creates a new route from a generic handler. +// NewRoute creates a new route from a generic handler with auth capability. func NewRoute(p string, m string, pr sync.ProcessorFunc, trace bool, auth auth.Authenticator) Route { return Route{Pattern: p, Method: m, Handler: handler(pr), Trace: trace, Auth: auth} } @@ -61,27 +61,42 @@ func NewRouteRaw(p string, m string, h http.HandlerFunc, trace bool) Route { return Route{Pattern: p, Method: m, Handler: h, Trace: trace} } -// NewAuthGetRoute creates a new GET route from a generic handler. +// NewAuthGetRoute creates a new GET route from a generic handler with auth capability. func NewAuthGetRoute(p string, pr sync.ProcessorFunc, trace bool, auth auth.Authenticator) Route { return NewRoute(p, http.MethodGet, pr, trace, auth) } -// NewAuthPostRoute creates a new POST route from a generic handler. +// NewAuthPostRoute creates a new POST route from a generic handler with auth capability. func NewAuthPostRoute(p string, pr sync.ProcessorFunc, trace bool, auth auth.Authenticator) Route { return NewRoute(p, http.MethodPost, pr, trace, auth) } -// NewAuthPutRoute creates a new PUT route from a generic handler. +// NewAuthPutRoute creates a new PUT route from a generic handler with auth capability. func NewAuthPutRoute(p string, pr sync.ProcessorFunc, trace bool, auth auth.Authenticator) Route { return NewRoute(p, http.MethodPut, pr, trace, auth) } -// NewAuthDeleteRoute creates a new DELETE route from a generic handler. +// NewAuthDeleteRoute creates a new DELETE route from a generic handler with auth capability. func NewAuthDeleteRoute(p string, pr sync.ProcessorFunc, trace bool, auth auth.Authenticator) Route { return NewRoute(p, http.MethodDelete, pr, trace, auth) } -// NewAuthRouteRaw creates a new route from a HTTP handler. +// NewAuthPatchRoute creates a new PATCH route from a generic handler with auth capability. +func NewAuthPatchRoute(p string, pr sync.ProcessorFunc, trace bool, auth auth.Authenticator) Route { + return NewRoute(p, http.MethodPatch, pr, trace, auth) +} + +// NewAuthHeadRoute creates a new HEAD route from a generic handler with auth capability. +func NewAuthHeadRoute(p string, pr sync.ProcessorFunc, trace bool, auth auth.Authenticator) Route { + return NewRoute(p, http.MethodHead, pr, trace, auth) +} + +// NewAuthOptionsRoute creates a new OPTIONS route from a generic handler with auth capability. +func NewAuthOptionsRoute(p string, pr sync.ProcessorFunc, trace bool, auth auth.Authenticator) Route { + return NewRoute(p, http.MethodOptions, pr, trace, auth) +} + +// NewAuthRouteRaw creates a new route from a HTTP handler with auth capability. func NewAuthRouteRaw(p string, m string, h http.HandlerFunc, trace bool, auth auth.Authenticator) Route { return Route{Pattern: p, Method: m, Handler: h, Trace: trace, Auth: auth} } diff --git a/sync/http/route_test.go b/sync/http/route_test.go index abb99adbe..fc79f3f50 100644 --- a/sync/http/route_test.go +++ b/sync/http/route_test.go @@ -121,6 +121,31 @@ func TestNewAuthDeleteRoute(t *testing.T) { assert.True(t, r.Trace) assert.NotNil(t, r.Auth) } + +func TestNewAuthPatchRoute(t *testing.T) { + r := NewAuthPatchRoute("/index", nil, true, &MockAuthenticator{}) + assert.Equal(t, "/index", r.Pattern) + assert.Equal(t, http.MethodPatch, r.Method) + assert.True(t, r.Trace) + assert.NotNil(t, r.Auth) +} + +func TestNewAuthHeadRoute(t *testing.T) { + r := NewAuthHeadRoute("/index", nil, true, &MockAuthenticator{}) + assert.Equal(t, "/index", r.Pattern) + assert.Equal(t, http.MethodHead, r.Method) + assert.True(t, r.Trace) + assert.NotNil(t, r.Auth) +} + +func TestNewAuthOptionsRoute(t *testing.T) { + r := NewAuthOptionsRoute("/index", nil, true, &MockAuthenticator{}) + assert.Equal(t, "/index", r.Pattern) + assert.Equal(t, http.MethodOptions, r.Method) + assert.True(t, r.Trace) + assert.NotNil(t, r.Auth) +} + func TestNewAuthRouteRaw(t *testing.T) { r := NewAuthRouteRaw("/index", http.MethodGet, nil, false, &MockAuthenticator{}) assert.Equal(t, "/index", r.Pattern)