2022-11-29 10:57:47 +01:00
|
|
|
package authntest
|
|
|
|
|
|
2022-12-02 15:10:03 +01:00
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/authn"
|
|
|
|
|
)
|
2022-11-29 10:57:47 +01:00
|
|
|
|
|
|
|
|
type FakeService struct {
|
|
|
|
|
authn.Service
|
|
|
|
|
}
|
2022-12-02 15:10:03 +01:00
|
|
|
|
2023-01-26 10:50:44 +01:00
|
|
|
var _ authn.ContextAwareClient = new(FakeClient)
|
2022-12-02 15:10:03 +01:00
|
|
|
|
|
|
|
|
type FakeClient struct {
|
2023-01-26 10:50:44 +01:00
|
|
|
ExpectedName string
|
2023-01-09 16:40:29 +01:00
|
|
|
ExpectedErr error
|
|
|
|
|
ExpectedTest bool
|
2023-01-26 10:50:44 +01:00
|
|
|
ExpectedPriority uint
|
2023-01-09 16:40:29 +01:00
|
|
|
ExpectedIdentity *authn.Identity
|
2023-03-16 15:34:43 +00:00
|
|
|
ExpectedStats map[string]interface{}
|
2022-12-02 15:10:03 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-26 10:50:44 +01:00
|
|
|
func (f *FakeClient) Name() string {
|
|
|
|
|
return f.ExpectedName
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-02 15:10:03 +01:00
|
|
|
func (f *FakeClient) Authenticate(ctx context.Context, r *authn.Request) (*authn.Identity, error) {
|
|
|
|
|
return f.ExpectedIdentity, f.ExpectedErr
|
|
|
|
|
}
|
2022-12-19 09:22:11 +01:00
|
|
|
|
|
|
|
|
func (f *FakeClient) Test(ctx context.Context, r *authn.Request) bool {
|
|
|
|
|
return f.ExpectedTest
|
|
|
|
|
}
|
2023-01-09 16:40:29 +01:00
|
|
|
|
2023-01-26 10:50:44 +01:00
|
|
|
func (f *FakeClient) Priority() uint {
|
|
|
|
|
return f.ExpectedPriority
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-16 15:34:43 +00:00
|
|
|
func (f *FakeClient) UsageStatFn(ctx context.Context) (map[string]interface{}, error) {
|
|
|
|
|
return f.ExpectedStats, f.ExpectedErr
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-09 16:40:29 +01:00
|
|
|
var _ authn.PasswordClient = new(FakePasswordClient)
|
|
|
|
|
|
|
|
|
|
type FakePasswordClient struct {
|
|
|
|
|
ExpectedErr error
|
|
|
|
|
ExpectedIdentity *authn.Identity
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 15:02:04 +01:00
|
|
|
func (f FakePasswordClient) AuthenticatePassword(ctx context.Context, r *authn.Request, username, password string) (*authn.Identity, error) {
|
2023-01-09 16:40:29 +01:00
|
|
|
return f.ExpectedIdentity, f.ExpectedErr
|
|
|
|
|
}
|
2023-01-23 11:54:38 +01:00
|
|
|
|
|
|
|
|
var _ authn.RedirectClient = new(FakeRedirectClient)
|
|
|
|
|
|
|
|
|
|
type FakeRedirectClient struct {
|
|
|
|
|
ExpectedErr error
|
|
|
|
|
ExpectedURL string
|
2023-01-26 10:50:44 +01:00
|
|
|
ExpectedName string
|
2023-01-30 12:45:04 +01:00
|
|
|
ExpectedOK bool
|
|
|
|
|
ExpectedRedirect *authn.Redirect
|
2023-01-23 11:54:38 +01:00
|
|
|
ExpectedIdentity *authn.Identity
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-26 10:50:44 +01:00
|
|
|
func (f FakeRedirectClient) Name() string {
|
|
|
|
|
return f.ExpectedName
|
2023-01-23 11:54:38 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-26 10:50:44 +01:00
|
|
|
func (f FakeRedirectClient) Authenticate(ctx context.Context, r *authn.Request) (*authn.Identity, error) {
|
|
|
|
|
return f.ExpectedIdentity, f.ExpectedErr
|
2023-01-23 11:54:38 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-30 12:45:04 +01:00
|
|
|
func (f FakeRedirectClient) RedirectURL(ctx context.Context, r *authn.Request) (*authn.Redirect, error) {
|
|
|
|
|
return f.ExpectedRedirect, f.ExpectedErr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (f FakeRedirectClient) Test(ctx context.Context, r *authn.Request) bool {
|
|
|
|
|
return f.ExpectedOK
|
2023-01-23 11:54:38 +01:00
|
|
|
}
|