mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* AuthN: set up boilerplate for proxy client * AuthN: Implement Test for proxy client * AuthN: parse accept list in constructor * AuthN: add proxy client interface * AuthN: handle error * AuthN: Implement the proxy client interface for ldap * AuthN: change reciever name * AuthN: add grafana as a proxy client * AuthN: for error returned * AuthN: add tests for grafana proxy auth * AuthN: swap order of grafan and ldap auth * AuthN: Parse additional proxy headers in proxy client and pass down
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package authntest
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana/pkg/services/authn"
|
|
)
|
|
|
|
var _ authn.Client = new(MockClient)
|
|
|
|
type MockClient struct {
|
|
AuthenticateFunc func(ctx context.Context, r *authn.Request) (*authn.Identity, error)
|
|
TestFunc func(ctx context.Context, r *authn.Request) bool
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
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
|
|
}
|