2019-01-18 20:46:37 +00:00
|
|
|
package mock
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2020-04-03 17:39:20 +00:00
|
|
|
"github.com/influxdata/influxdb/v2"
|
|
|
|
platcontext "github.com/influxdata/influxdb/v2/context"
|
2019-01-18 20:46:37 +00:00
|
|
|
)
|
|
|
|
|
2019-01-23 17:11:06 +00:00
|
|
|
// NewAuthMiddlewareHandler create a mocked middleware handler.
|
|
|
|
func NewAuthMiddlewareHandler(handler http.Handler, auth influxdb.Authorizer) http.Handler {
|
|
|
|
return &authMiddlewareHandler{
|
2019-01-18 20:46:37 +00:00
|
|
|
handler: handler,
|
|
|
|
auth: auth,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-23 17:11:06 +00:00
|
|
|
type authMiddlewareHandler struct {
|
2019-01-18 20:46:37 +00:00
|
|
|
handler http.Handler
|
|
|
|
auth influxdb.Authorizer
|
|
|
|
}
|
|
|
|
|
2019-01-23 17:11:06 +00:00
|
|
|
func (m *authMiddlewareHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
2019-01-18 20:46:37 +00:00
|
|
|
ctx := r.Context()
|
|
|
|
r = r.WithContext(platcontext.SetAuthorizer(ctx, m.auth))
|
|
|
|
m.handler.ServeHTTP(w, r)
|
|
|
|
}
|