mirror of https://github.com/grafana/grafana
AuthN: set org id for authentication request in service (#60528)
* AuthN: Replicate functionallity to get org id for request * Authn: parse org id for the request and populate the auth request with it * AuthN: add simple mock for client to use in test * AuthN: add tests to verify that authentication is called with correct org id * AuthN: Add ClientParams to mock * AuthN: Fix flaky org id selectionpull/60605/head
parent
17696f8dec
commit
c4b4baea2a
@ -0,0 +1,36 @@ |
||||
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) |
||||
ClientParamsFunc func() *authn.ClientParams |
||||
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) ClientParams() *authn.ClientParams { |
||||
if m.ClientParamsFunc != nil { |
||||
return m.ClientParamsFunc() |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func (m MockClient) Test(ctx context.Context, r *authn.Request) bool { |
||||
if m.TestFunc != nil { |
||||
return m.TestFunc(ctx, r) |
||||
} |
||||
return false |
||||
} |
||||
Loading…
Reference in new issue