mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
@@ -9,28 +9,63 @@ import (
|
||||
var _ authn.Service = new(FakeService)
|
||||
|
||||
type FakeService struct {
|
||||
ExpectedErr error
|
||||
ExpectedRedirect *authn.Redirect
|
||||
ExpectedIdentity *authn.Identity
|
||||
ExpectedErr error
|
||||
ExpectedRedirect *authn.Redirect
|
||||
ExpectedIdentity *authn.Identity
|
||||
ExpectedErrs []error
|
||||
ExpectedIdentities []*authn.Identity
|
||||
CurrentIndex int
|
||||
}
|
||||
|
||||
func (f FakeService) Authenticate(ctx context.Context, r *authn.Request) (*authn.Identity, error) {
|
||||
func (f *FakeService) Authenticate(ctx context.Context, r *authn.Request) (*authn.Identity, error) {
|
||||
if f.ExpectedIdentities != nil {
|
||||
if f.CurrentIndex >= len(f.ExpectedIdentities) {
|
||||
panic("ExpectedIdentities is empty")
|
||||
}
|
||||
if f.CurrentIndex >= len(f.ExpectedErrs) {
|
||||
panic("ExpectedErrs is empty")
|
||||
}
|
||||
|
||||
identity := f.ExpectedIdentities[f.CurrentIndex]
|
||||
err := f.ExpectedErrs[f.CurrentIndex]
|
||||
|
||||
f.CurrentIndex += 1
|
||||
|
||||
return identity, err
|
||||
}
|
||||
|
||||
return f.ExpectedIdentity, f.ExpectedErr
|
||||
}
|
||||
|
||||
func (f FakeService) RegisterPostAuthHook(hook authn.PostAuthHookFn, priority uint) {}
|
||||
func (f *FakeService) RegisterPostAuthHook(hook authn.PostAuthHookFn, priority uint) {}
|
||||
|
||||
func (f *FakeService) Login(ctx context.Context, client string, r *authn.Request) (*authn.Identity, error) {
|
||||
if f.ExpectedIdentities != nil {
|
||||
if f.CurrentIndex >= len(f.ExpectedIdentities) {
|
||||
panic("ExpectedIdentities is empty")
|
||||
}
|
||||
if f.CurrentIndex >= len(f.ExpectedErrs) {
|
||||
panic("ExpectedErrs is empty")
|
||||
}
|
||||
|
||||
identity := f.ExpectedIdentities[f.CurrentIndex]
|
||||
err := f.ExpectedErrs[f.CurrentIndex]
|
||||
|
||||
f.CurrentIndex += 1
|
||||
|
||||
return identity, err
|
||||
}
|
||||
|
||||
func (f FakeService) Login(ctx context.Context, client string, r *authn.Request) (*authn.Identity, error) {
|
||||
return f.ExpectedIdentity, f.ExpectedErr
|
||||
}
|
||||
|
||||
func (f FakeService) RegisterPostLoginHook(hook authn.PostLoginHookFn, priority uint) {}
|
||||
func (f *FakeService) RegisterPostLoginHook(hook authn.PostLoginHookFn, priority uint) {}
|
||||
|
||||
func (f FakeService) RedirectURL(ctx context.Context, client string, r *authn.Request) (*authn.Redirect, error) {
|
||||
func (f *FakeService) RedirectURL(ctx context.Context, client string, r *authn.Request) (*authn.Redirect, error) {
|
||||
return f.ExpectedRedirect, f.ExpectedErr
|
||||
}
|
||||
|
||||
func (f FakeService) RegisterClient(c authn.Client) {}
|
||||
func (f *FakeService) RegisterClient(c authn.Client) {}
|
||||
|
||||
var _ authn.ContextAwareClient = new(FakeClient)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user