Files
grafana/pkg/services/authn/authntest/fake.go
T
Karl Persson 95ea4bad6f AuthN: Rebuild Authenticate so we only have to call it once in context handler (#61705)
* 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>
2023-01-26 10:50:44 +01:00

70 lines
1.6 KiB
Go

package authntest
import (
"context"
"github.com/grafana/grafana/pkg/services/authn"
)
type FakeService struct {
authn.Service
}
var _ authn.ContextAwareClient = new(FakeClient)
type FakeClient struct {
ExpectedName string
ExpectedErr error
ExpectedTest bool
ExpectedPriority uint
ExpectedIdentity *authn.Identity
}
func (f *FakeClient) Name() string {
return f.ExpectedName
}
func (f *FakeClient) Authenticate(ctx context.Context, r *authn.Request) (*authn.Identity, error) {
return f.ExpectedIdentity, f.ExpectedErr
}
func (f *FakeClient) Test(ctx context.Context, r *authn.Request) bool {
return f.ExpectedTest
}
func (f *FakeClient) Priority() uint {
return f.ExpectedPriority
}
var _ authn.PasswordClient = new(FakePasswordClient)
type FakePasswordClient struct {
ExpectedErr error
ExpectedIdentity *authn.Identity
}
func (f FakePasswordClient) AuthenticatePassword(ctx context.Context, r *authn.Request, username, password string) (*authn.Identity, error) {
return f.ExpectedIdentity, f.ExpectedErr
}
var _ authn.RedirectClient = new(FakeRedirectClient)
type FakeRedirectClient struct {
ExpectedErr error
ExpectedURL string
ExpectedName string
ExpectedIdentity *authn.Identity
}
func (f FakeRedirectClient) Name() string {
return f.ExpectedName
}
func (f FakeRedirectClient) Authenticate(ctx context.Context, r *authn.Request) (*authn.Identity, error) {
return f.ExpectedIdentity, f.ExpectedErr
}
func (f FakeRedirectClient) RedirectURL(ctx context.Context, r *authn.Request) (string, error) {
return f.ExpectedURL, f.ExpectedErr
}