mirror of https://github.com/grafana/grafana
Auth: Add OrgRole to ID token (#100383)
* Changes for Users and ServiceAccounts * Align testspull/98609/head
parent
a5c8b5ed83
commit
ee0a1391df
@ -0,0 +1,42 @@ |
||||
package idtest |
||||
|
||||
import ( |
||||
"context" |
||||
|
||||
authnlib "github.com/grafana/authlib/authn" |
||||
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity" |
||||
"github.com/grafana/grafana/pkg/services/auth" |
||||
) |
||||
|
||||
var _ auth.IDService = (*FakeService)(nil) |
||||
|
||||
type FakeService struct { |
||||
SignIdentityFn func(ctx context.Context, identity identity.Requester) (string, *authnlib.Claims[authnlib.IDTokenClaims], error) |
||||
RemoveIDTokenFn func(ctx context.Context, identity identity.Requester) error |
||||
} |
||||
|
||||
func (m *FakeService) SignIdentity(ctx context.Context, identity identity.Requester) (string, *authnlib.Claims[authnlib.IDTokenClaims], error) { |
||||
if m.SignIdentityFn != nil { |
||||
return m.SignIdentityFn(ctx, identity) |
||||
} |
||||
return "", nil, nil |
||||
} |
||||
|
||||
func (m *FakeService) RemoveIDToken(ctx context.Context, identity identity.Requester) error { |
||||
if m.RemoveIDTokenFn != nil { |
||||
return m.RemoveIDTokenFn(ctx, identity) |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
type FakeSigner struct { |
||||
SignIDTokenFn func(ctx context.Context, claims *auth.IDClaims) (string, error) |
||||
} |
||||
|
||||
func (s *FakeSigner) SignIDToken(ctx context.Context, claims *auth.IDClaims) (string, error) { |
||||
if s.SignIDTokenFn != nil { |
||||
return s.SignIDTokenFn(ctx, claims) |
||||
} |
||||
return "", nil |
||||
} |
@ -1,42 +1,87 @@ |
||||
// Code generated by mockery v2.42.1. DO NOT EDIT.
|
||||
|
||||
package idtest |
||||
|
||||
import ( |
||||
"context" |
||||
context "context" |
||||
|
||||
authnlib "github.com/grafana/authlib/authn" |
||||
authn "github.com/grafana/authlib/authn" |
||||
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity" |
||||
"github.com/grafana/grafana/pkg/services/auth" |
||||
) |
||||
identity "github.com/grafana/grafana/pkg/apimachinery/identity" |
||||
|
||||
var _ auth.IDService = (*MockService)(nil) |
||||
mock "github.com/stretchr/testify/mock" |
||||
) |
||||
|
||||
// MockService is an autogenerated mock type for the IDService type
|
||||
type MockService struct { |
||||
SignIdentityFn func(ctx context.Context, identity identity.Requester) (string, *authnlib.Claims[authnlib.IDTokenClaims], error) |
||||
RemoveIDTokenFn func(ctx context.Context, identity identity.Requester) error |
||||
mock.Mock |
||||
} |
||||
|
||||
func (m *MockService) SignIdentity(ctx context.Context, identity identity.Requester) (string, *authnlib.Claims[authnlib.IDTokenClaims], error) { |
||||
if m.SignIdentityFn != nil { |
||||
return m.SignIdentityFn(ctx, identity) |
||||
// RemoveIDToken provides a mock function with given fields: ctx, _a1
|
||||
func (_m *MockService) RemoveIDToken(ctx context.Context, _a1 identity.Requester) error { |
||||
ret := _m.Called(ctx, _a1) |
||||
|
||||
if len(ret) == 0 { |
||||
panic("no return value specified for RemoveIDToken") |
||||
} |
||||
return "", nil, nil |
||||
} |
||||
|
||||
func (m *MockService) RemoveIDToken(ctx context.Context, identity identity.Requester) error { |
||||
if m.RemoveIDTokenFn != nil { |
||||
return m.RemoveIDTokenFn(ctx, identity) |
||||
var r0 error |
||||
if rf, ok := ret.Get(0).(func(context.Context, identity.Requester) error); ok { |
||||
r0 = rf(ctx, _a1) |
||||
} else { |
||||
r0 = ret.Error(0) |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
type MockSigner struct { |
||||
SignIDTokenFn func(ctx context.Context, claims *auth.IDClaims) (string, error) |
||||
return r0 |
||||
} |
||||
|
||||
func (s *MockSigner) SignIDToken(ctx context.Context, claims *auth.IDClaims) (string, error) { |
||||
if s.SignIDTokenFn != nil { |
||||
return s.SignIDTokenFn(ctx, claims) |
||||
// SignIdentity provides a mock function with given fields: ctx, id
|
||||
func (_m *MockService) SignIdentity(ctx context.Context, id identity.Requester) (string, *authn.Claims[authn.IDTokenClaims], error) { |
||||
ret := _m.Called(ctx, id) |
||||
|
||||
if len(ret) == 0 { |
||||
panic("no return value specified for SignIdentity") |
||||
} |
||||
|
||||
var r0 string |
||||
var r1 *authn.Claims[authn.IDTokenClaims] |
||||
var r2 error |
||||
if rf, ok := ret.Get(0).(func(context.Context, identity.Requester) (string, *authn.Claims[authn.IDTokenClaims], error)); ok { |
||||
return rf(ctx, id) |
||||
} |
||||
if rf, ok := ret.Get(0).(func(context.Context, identity.Requester) string); ok { |
||||
r0 = rf(ctx, id) |
||||
} else { |
||||
r0 = ret.Get(0).(string) |
||||
} |
||||
return "", nil |
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, identity.Requester) *authn.Claims[authn.IDTokenClaims]); ok { |
||||
r1 = rf(ctx, id) |
||||
} else { |
||||
if ret.Get(1) != nil { |
||||
r1 = ret.Get(1).(*authn.Claims[authn.IDTokenClaims]) |
||||
} |
||||
} |
||||
|
||||
if rf, ok := ret.Get(2).(func(context.Context, identity.Requester) error); ok { |
||||
r2 = rf(ctx, id) |
||||
} else { |
||||
r2 = ret.Error(2) |
||||
} |
||||
|
||||
return r0, r1, r2 |
||||
} |
||||
|
||||
// NewMockService creates a new instance of MockService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewMockService(t interface { |
||||
mock.TestingT |
||||
Cleanup(func()) |
||||
}) *MockService { |
||||
mock := &MockService{} |
||||
mock.Mock.Test(t) |
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) }) |
||||
|
||||
return mock |
||||
} |
||||
|
Loading…
Reference in new issue