Authn: external identity sync (#73461)

* Authn: Add interface for external identity sync

This interface is implemented by authnimpl.Service and just triggers PostAuthHooks and skipping last seen update by default

* Authn: Add SyncIdentity to fake and add a new mock
This commit is contained in:
Karl Persson
2023-08-18 11:11:44 +02:00
committed by GitHub
parent 878e94ae25
commit 124e0efe1f
6 changed files with 80 additions and 9 deletions

View File

@@ -7,6 +7,7 @@ import (
)
var _ authn.Service = new(FakeService)
var _ authn.IdentitySynchronizer = new(FakeService)
type FakeService struct {
ExpectedErr error
@@ -67,6 +68,10 @@ func (f *FakeService) RedirectURL(ctx context.Context, client string, r *authn.R
func (f *FakeService) RegisterClient(c authn.Client) {}
func (f *FakeService) SyncIdentity(ctx context.Context, identity *authn.Identity) error {
return f.ExpectedErr
}
var _ authn.ContextAwareClient = new(FakeClient)
type FakeClient struct {

View File

@@ -6,6 +6,44 @@ import (
"github.com/grafana/grafana/pkg/services/authn"
)
var _ authn.Service = new(MockService)
var _ authn.IdentitySynchronizer = new(MockService)
type MockService struct {
SyncIdentityFunc func(ctx context.Context, identity *authn.Identity) error
}
func (m *MockService) Authenticate(ctx context.Context, r *authn.Request) (*authn.Identity, error) {
panic("unimplemented")
}
func (m *MockService) Login(ctx context.Context, client string, r *authn.Request) (*authn.Identity, error) {
panic("unimplemented")
}
func (m *MockService) RedirectURL(ctx context.Context, client string, r *authn.Request) (*authn.Redirect, error) {
panic("unimplemented")
}
func (m *MockService) RegisterClient(c authn.Client) {
panic("unimplemented")
}
func (m *MockService) RegisterPostAuthHook(hook authn.PostAuthHookFn, priority uint) {
panic("unimplemented")
}
func (m *MockService) RegisterPostLoginHook(hook authn.PostLoginHookFn, priority uint) {
panic("unimplemented")
}
func (m *MockService) SyncIdentity(ctx context.Context, identity *authn.Identity) error {
if m.SyncIdentityFunc != nil {
return m.SyncIdentityFunc(ctx, identity)
}
return nil
}
var _ authn.HookClient = new(MockClient)
var _ authn.ContextAwareClient = new(MockClient)