95ea4bad6f
* API: Add reqSignedIn to router groups * AuthN: Add fall through in context handler * AuthN: Add IsAnonymous field * AuthN: add priority to context aware clients * ContextHandler: Add comment * AuthN: Add a simple priority queue * AuthN: Add Name to client interface * AuthN: register clients with function * AuthN: update mock and fake to implement interface * AuthN: rewrite test without reflection * AuthN: add comment * AuthN: fix queue insert * AuthN: rewrite tests * AuthN: make the queue generic so we can reuse it for hooks * ContextHandler: Add fixme for auth headers * AuthN: remove unused variable * AuthN: use multierror * AuthN: write proper tests for queue * AuthN: Add queue item that can store the value and priority Co-authored-by: Jo <joao.guerreiro@grafana.com>
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package authntest
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana/pkg/services/authn"
|
|
)
|
|
|
|
var _ authn.ContextAwareClient = new(MockClient)
|
|
|
|
type MockClient struct {
|
|
NameFunc func() string
|
|
AuthenticateFunc func(ctx context.Context, r *authn.Request) (*authn.Identity, error)
|
|
TestFunc func(ctx context.Context, r *authn.Request) bool
|
|
PriorityFunc func() uint
|
|
}
|
|
|
|
func (m MockClient) Name() string {
|
|
if m.NameFunc != nil {
|
|
return m.NameFunc()
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func (m MockClient) Authenticate(ctx context.Context, r *authn.Request) (*authn.Identity, error) {
|
|
if m.AuthenticateFunc != nil {
|
|
return m.AuthenticateFunc(ctx, r)
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (m MockClient) Test(ctx context.Context, r *authn.Request) bool {
|
|
if m.TestFunc != nil {
|
|
return m.TestFunc(ctx, r)
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (m MockClient) Priority() uint {
|
|
if m.PriorityFunc != nil {
|
|
return m.PriorityFunc()
|
|
}
|
|
return 0
|
|
}
|
|
|
|
var _ authn.ProxyClient = new(MockProxyClient)
|
|
|
|
type MockProxyClient struct {
|
|
AuthenticateProxyFunc func(ctx context.Context, r *authn.Request, username string, additional map[string]string) (*authn.Identity, error)
|
|
}
|
|
|
|
func (m MockProxyClient) AuthenticateProxy(ctx context.Context, r *authn.Request, username string, additional map[string]string) (*authn.Identity, error) {
|
|
if m.AuthenticateProxyFunc != nil {
|
|
return m.AuthenticateProxyFunc(ctx, r, username, additional)
|
|
}
|
|
return nil, nil
|
|
}
|