From d7d296df8e46aa10eed364e46351d75308785e60 Mon Sep 17 00:00:00 2001 From: Misi Date: Fri, 7 Nov 2025 16:51:41 +0100 Subject: [PATCH] Fix: Return auth labels from `/api/users/lookup` (#113584) * wip * Return auth labels from /api/users/lookup * Rename * Address feedback * Add more tests, fix tests * Cleanup --- pkg/api/common_test.go | 2 +- pkg/api/org_users.go | 2 +- pkg/api/user.go | 6 + pkg/api/user_test.go | 38 + pkg/services/login/authinfo.go | 7 +- pkg/services/login/authinfoimpl/service.go | 21 +- .../login/authinfoimpl/service_test.go | 31 + pkg/services/login/authinfoimpl/store.go | 25 +- pkg/services/login/authinfoimpl/store_test.go | 2 +- .../authinfotest/auth_info_service_mock.go | 896 +++--------------- .../authinfotest/auth_info_store_mock.go | 173 ++++ pkg/services/login/authinfotest/fake.go | 19 +- 12 files changed, 463 insertions(+), 759 deletions(-) create mode 100644 pkg/services/login/authinfoimpl/service_test.go create mode 100644 pkg/services/login/authinfotest/auth_info_store_mock.go diff --git a/pkg/api/common_test.go b/pkg/api/common_test.go index d324831b075..0578cefd724 100644 --- a/pkg/api/common_test.go +++ b/pkg/api/common_test.go @@ -273,7 +273,7 @@ func setupSimpleHTTPServer(features featuremgmt.FeatureToggles) *HTTPServer { AccessControl: acimpl.ProvideAccessControl(featuremgmt.WithFeatures()), annotationsRepo: annotationstest.NewFakeAnnotationsRepo(), authInfoService: &authinfotest.FakeService{ - ExpectedLabels: map[int64]string{int64(1): login.GetAuthProviderLabel(login.LDAPAuthModule)}, + ExpectedRecentlyUsedLabel: map[int64]string{int64(1): login.GetAuthProviderLabel(login.LDAPAuthModule)}, }, tracer: tracing.InitializeTracerForTest(), } diff --git a/pkg/api/org_users.go b/pkg/api/org_users.go index 0367f58b2f5..8a10cc24944 100644 --- a/pkg/api/org_users.go +++ b/pkg/api/org_users.go @@ -314,7 +314,7 @@ func (hs *HTTPServer) searchOrgUsersHelper(c *contextmodel.ReqContext, query *or filteredUsers = append(filteredUsers, user) } - modules, err := hs.authInfoService.GetUserLabels(c.Req.Context(), login.GetUserLabelsQuery{ + modules, err := hs.authInfoService.GetUsersRecentlyUsedLabel(c.Req.Context(), login.GetUserLabelsQuery{ UserIDs: authLabelsUserIDs, }) diff --git a/pkg/api/user.go b/pkg/api/user.go index 311f80e49ae..e8c02ed1cf0 100644 --- a/pkg/api/user.go +++ b/pkg/api/user.go @@ -115,6 +115,7 @@ func (hs *HTTPServer) GetUserByLoginOrEmail(c *contextmodel.ReqContext) response } return response.Error(http.StatusInternalServerError, "Failed to get user", err) } + result := user.UserProfileDTO{ ID: usr.ID, UID: usr.UID, @@ -128,6 +129,11 @@ func (hs *HTTPServer) GetUserByLoginOrEmail(c *contextmodel.ReqContext) response UpdatedAt: usr.Updated, CreatedAt: usr.Created, } + // Populate AuthLabels using all historically used auth modules ordered by most recent. + if modules, err := hs.authInfoService.GetUserAuthModuleLabels(c.Req.Context(), usr.ID); err == nil { + result.AuthLabels = modules + } + return response.JSON(http.StatusOK, &result) } diff --git a/pkg/api/user_test.go b/pkg/api/user_test.go index 41b11e76487..8e4b3503015 100644 --- a/pkg/api/user_test.go +++ b/pkg/api/user_test.go @@ -185,6 +185,44 @@ func TestIntegrationUserAPIEndpoint_userLoggedIn(t *testing.T) { require.NoError(t, err) }, mock) + // Multiple historical auth labels should appear ordered by recency + loggedInUserScenario(t, "When calling GET returns with multiple auth labels", "/api/users/lookup", "/api/users/lookup", func(sc *scenarioContext) { + createUserCmd := user.CreateUserCommand{ + Email: fmt.Sprint("multi", "@test.com"), + Name: "multi", + Login: "multi", + IsAdmin: true, + } + orgSvc, err := orgimpl.ProvideService(sqlStore, sc.cfg, quotatest.New(false, nil)) + require.NoError(t, err) + userSvc, err := userimpl.ProvideService( + sqlStore, orgSvc, sc.cfg, nil, nil, tracing.InitializeTracerForTest(), + quotatest.New(false, nil), supportbundlestest.NewFakeBundleService(), + ) + require.NoError(t, err) + usr, err := userSvc.Create(context.Background(), &createUserCmd) + require.Nil(t, err) + + sc.handlerFunc = hs.GetUserByLoginOrEmail + + userMock := usertest.NewUserServiceFake() + userMock.ExpectedUser = &user.User{ID: usr.ID, Email: usr.Email, Login: usr.Login, Name: usr.Name} + sc.userService = userMock + hs.userService = userMock + + fakeAuth := &authinfotest.FakeService{ExpectedAuthModuleLabels: []string{login.GetAuthProviderLabel(login.OktaAuthModule), login.GetAuthProviderLabel(login.LDAPAuthModule), login.GetAuthProviderLabel(login.SAMLAuthModule)}} + hs.authInfoService = fakeAuth + + sc.fakeReqWithParams("GET", sc.url, map[string]string{"loginOrEmail": usr.Email}).exec() + + var resp user.UserProfileDTO + require.Equal(t, http.StatusOK, sc.resp.Code) + err = json.Unmarshal(sc.resp.Body.Bytes(), &resp) + require.NoError(t, err) + expected := []string{login.GetAuthProviderLabel(login.OktaAuthModule), login.GetAuthProviderLabel(login.LDAPAuthModule), login.GetAuthProviderLabel(login.SAMLAuthModule)} + require.Equal(t, expected, resp.AuthLabels) + }, mock) + loggedInUserScenario(t, "When calling GET on", "/api/users", "/api/users", func(sc *scenarioContext) { userMock.ExpectedSearchUsers = mockResult diff --git a/pkg/services/login/authinfo.go b/pkg/services/login/authinfo.go index 095e3390ce9..e8922772240 100644 --- a/pkg/services/login/authinfo.go +++ b/pkg/services/login/authinfo.go @@ -8,15 +8,18 @@ import ( //go:generate mockery --name AuthInfoService --structname MockAuthInfoService --outpkg authinfotest --filename auth_info_service_mock.go --output ./authinfotest/ type AuthInfoService interface { GetAuthInfo(ctx context.Context, query *GetAuthInfoQuery) (*UserAuth, error) - GetUserLabels(ctx context.Context, query GetUserLabelsQuery) (map[int64]string, error) + GetUsersRecentlyUsedLabel(ctx context.Context, query GetUserLabelsQuery) (map[int64]string, error) + GetUserAuthModuleLabels(ctx context.Context, userID int64) ([]string, error) SetAuthInfo(ctx context.Context, cmd *SetAuthInfoCommand) error UpdateAuthInfo(ctx context.Context, cmd *UpdateAuthInfoCommand) error DeleteUserAuthInfo(ctx context.Context, userID int64) error } +//go:generate mockery --name Store --structname MockAuthInfoStore --outpkg authinfotest --filename auth_info_store_mock.go --output ./authinfotest/ type Store interface { GetAuthInfo(ctx context.Context, query *GetAuthInfoQuery) (*UserAuth, error) - GetUserLabels(ctx context.Context, query GetUserLabelsQuery) (map[int64]string, error) + GetUsersRecentlyUsedLabel(ctx context.Context, query GetUserLabelsQuery) (map[int64]string, error) + GetUserAuthModules(ctx context.Context, userID int64) ([]string, error) SetAuthInfo(ctx context.Context, cmd *SetAuthInfoCommand) error UpdateAuthInfo(ctx context.Context, cmd *UpdateAuthInfoCommand) error DeleteUserAuthInfo(ctx context.Context, userID int64) error diff --git a/pkg/services/login/authinfoimpl/service.go b/pkg/services/login/authinfoimpl/service.go index 1d7736c2c54..3c92e0c795f 100644 --- a/pkg/services/login/authinfoimpl/service.go +++ b/pkg/services/login/authinfoimpl/service.go @@ -67,11 +67,28 @@ func (s *Service) GetAuthInfo(ctx context.Context, query *login.GetAuthInfoQuery return authInfo, nil } -func (s *Service) GetUserLabels(ctx context.Context, query login.GetUserLabelsQuery) (map[int64]string, error) { +// GetUserAuthModuleLabels returns all auth modules for a user ordered by most recent first. +func (s *Service) GetUserAuthModuleLabels(ctx context.Context, userID int64) ([]string, error) { + modules, err := s.authInfoStore.GetUserAuthModules(ctx, userID) + if err != nil { + return nil, err + } + + result := make([]string, 0, len(modules)) + // modules should be unique and should not contain empty strings + for _, m := range modules { + label := login.GetAuthProviderLabel(m) + result = append(result, label) + } + + return result, nil +} + +func (s *Service) GetUsersRecentlyUsedLabel(ctx context.Context, query login.GetUserLabelsQuery) (map[int64]string, error) { if len(query.UserIDs) == 0 { return map[int64]string{}, nil } - return s.authInfoStore.GetUserLabels(ctx, query) + return s.authInfoStore.GetUsersRecentlyUsedLabel(ctx, query) } func (s *Service) setAuthInfoInCache(ctx context.Context, query *login.GetAuthInfoQuery, info *login.UserAuth) error { diff --git a/pkg/services/login/authinfoimpl/service_test.go b/pkg/services/login/authinfoimpl/service_test.go new file mode 100644 index 00000000000..210ac463625 --- /dev/null +++ b/pkg/services/login/authinfoimpl/service_test.go @@ -0,0 +1,31 @@ +package authinfoimpl + +import ( + "context" + "testing" + + "github.com/grafana/grafana/pkg/services/login" + "github.com/grafana/grafana/pkg/services/login/authinfotest" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" +) + +func TestAuthInfoService_GetUserAuthModuleLabels(t *testing.T) { + store := authinfotest.NewMockAuthInfoStore(t) + + userID := int64(42) + // Input modules from store (order matters, uniqueness assumed) + modules := []string{login.OktaAuthModule, login.LDAPAuthModule, login.SAMLAuthModule} + + store.On("GetUserAuthModules", mock.Anything, userID).Return(modules, nil) + + svc := ProvideService(store, nil, nil) + + actual, err := svc.GetUserAuthModuleLabels(context.Background(), userID) + require.NoError(t, err) + + expected := []string{login.GetAuthProviderLabel(login.OktaAuthModule), login.GetAuthProviderLabel(login.LDAPAuthModule), login.GetAuthProviderLabel(login.SAMLAuthModule)} + + // Verify labels mapped and order preserved + require.Equal(t, expected, actual) +} diff --git a/pkg/services/login/authinfoimpl/store.go b/pkg/services/login/authinfoimpl/store.go index 3d8dcd6c39f..49b1c565754 100644 --- a/pkg/services/login/authinfoimpl/store.go +++ b/pkg/services/login/authinfoimpl/store.go @@ -82,7 +82,7 @@ func (s *Store) GetAuthInfo(ctx context.Context, query *login.GetAuthInfoQuery) return userAuth, nil } -func (s *Store) GetUserLabels(ctx context.Context, query login.GetUserLabelsQuery) (map[int64]string, error) { +func (s *Store) GetUsersRecentlyUsedLabel(ctx context.Context, query login.GetUserLabelsQuery) (map[int64]string, error) { userAuths := []login.UserAuth{} params := make([]interface{}, 0, len(query.UserIDs)) for _, id := range query.UserIDs { @@ -105,6 +105,29 @@ func (s *Store) GetUserLabels(ctx context.Context, query login.GetUserLabelsQuer return labelMap, nil } +// GetUserAuthModules returns all auth modules a user has used ordered by most recently used first. +func (s *Store) GetUserAuthModules(ctx context.Context, userID int64) ([]string, error) { + rows := make([]struct { + AuthModule string `xorm:"auth_module"` + }, 0) + err := s.sqlStore.WithDbSession(ctx, func(sess *db.Session) error { + return sess.Table("user_auth").Where("user_id = ?", userID).Desc("created").Cols("auth_module").Find(&rows) + }) + if err != nil { + return nil, err + } + modules := make([]string, 0, len(rows)) + seen := make(map[string]struct{}, len(rows)) + for _, r := range rows { + if _, ok := seen[r.AuthModule]; ok { + continue + } + seen[r.AuthModule] = struct{}{} + modules = append(modules, r.AuthModule) + } + return modules, nil +} + func (s *Store) SetAuthInfo(ctx context.Context, cmd *login.SetAuthInfoCommand) error { authUser := &login.UserAuth{ UserId: cmd.UserId, diff --git a/pkg/services/login/authinfoimpl/store_test.go b/pkg/services/login/authinfoimpl/store_test.go index aa6f2b85083..a930580c1d7 100644 --- a/pkg/services/login/authinfoimpl/store_test.go +++ b/pkg/services/login/authinfoimpl/store_test.go @@ -45,7 +45,7 @@ func TestIntegrationAuthInfoStore(t *testing.T) { UserId: 2, })) - labels, err := store.GetUserLabels(ctx, login.GetUserLabelsQuery{UserIDs: []int64{1, 2}}) + labels, err := store.GetUsersRecentlyUsedLabel(ctx, login.GetUserLabelsQuery{UserIDs: []int64{1, 2}}) require.NoError(t, err) require.Len(t, labels, 2) diff --git a/pkg/services/login/authinfotest/auth_info_service_mock.go b/pkg/services/login/authinfotest/auth_info_service_mock.go index 42f9bd60b7f..a7004c24c54 100644 --- a/pkg/services/login/authinfotest/auth_info_service_mock.go +++ b/pkg/services/login/authinfotest/auth_info_service_mock.go @@ -1,17 +1,163 @@ -// Code generated by mockery; DO NOT EDIT. -// github.com/vektra/mockery -// template: testify +// Code generated by mockery v2.53.5. DO NOT EDIT. package authinfotest import ( - "context" + context "context" - "github.com/grafana/grafana/pkg/services/login" - "github.com/grafana/grafana/pkg/services/user" + login "github.com/grafana/grafana/pkg/services/login" mock "github.com/stretchr/testify/mock" ) +// MockAuthInfoService is an autogenerated mock type for the AuthInfoService type +type MockAuthInfoService struct { + mock.Mock +} + +// DeleteUserAuthInfo provides a mock function with given fields: ctx, userID +func (_m *MockAuthInfoService) DeleteUserAuthInfo(ctx context.Context, userID int64) error { + ret := _m.Called(ctx, userID) + + if len(ret) == 0 { + panic("no return value specified for DeleteUserAuthInfo") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok { + r0 = rf(ctx, userID) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GetAuthInfo provides a mock function with given fields: ctx, query +func (_m *MockAuthInfoService) GetAuthInfo(ctx context.Context, query *login.GetAuthInfoQuery) (*login.UserAuth, error) { + ret := _m.Called(ctx, query) + + if len(ret) == 0 { + panic("no return value specified for GetAuthInfo") + } + + var r0 *login.UserAuth + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *login.GetAuthInfoQuery) (*login.UserAuth, error)); ok { + return rf(ctx, query) + } + if rf, ok := ret.Get(0).(func(context.Context, *login.GetAuthInfoQuery) *login.UserAuth); ok { + r0 = rf(ctx, query) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*login.UserAuth) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *login.GetAuthInfoQuery) error); ok { + r1 = rf(ctx, query) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetUserAuthModuleLabels provides a mock function with given fields: ctx, userID +func (_m *MockAuthInfoService) GetUserAuthModuleLabels(ctx context.Context, userID int64) ([]string, error) { + ret := _m.Called(ctx, userID) + + if len(ret) == 0 { + panic("no return value specified for GetUserAuthModuleLabels") + } + + var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) ([]string, error)); ok { + return rf(ctx, userID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) []string); ok { + r0 = rf(ctx, userID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, userID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetUsersRecentlyUsedLabel provides a mock function with given fields: ctx, query +func (_m *MockAuthInfoService) GetUsersRecentlyUsedLabel(ctx context.Context, query login.GetUserLabelsQuery) (map[int64]string, error) { + ret := _m.Called(ctx, query) + + if len(ret) == 0 { + panic("no return value specified for GetUsersRecentlyUsedLabel") + } + + var r0 map[int64]string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, login.GetUserLabelsQuery) (map[int64]string, error)); ok { + return rf(ctx, query) + } + if rf, ok := ret.Get(0).(func(context.Context, login.GetUserLabelsQuery) map[int64]string); ok { + r0 = rf(ctx, query) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[int64]string) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, login.GetUserLabelsQuery) error); ok { + r1 = rf(ctx, query) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SetAuthInfo provides a mock function with given fields: ctx, cmd +func (_m *MockAuthInfoService) SetAuthInfo(ctx context.Context, cmd *login.SetAuthInfoCommand) error { + ret := _m.Called(ctx, cmd) + + if len(ret) == 0 { + panic("no return value specified for SetAuthInfo") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *login.SetAuthInfoCommand) error); ok { + r0 = rf(ctx, cmd) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// UpdateAuthInfo provides a mock function with given fields: ctx, cmd +func (_m *MockAuthInfoService) UpdateAuthInfo(ctx context.Context, cmd *login.UpdateAuthInfoCommand) error { + ret := _m.Called(ctx, cmd) + + if len(ret) == 0 { + panic("no return value specified for UpdateAuthInfo") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *login.UpdateAuthInfoCommand) error); ok { + r0 = rf(ctx, cmd) + } else { + r0 = ret.Error(0) + } + + return r0 +} + // NewMockAuthInfoService creates a new instance of MockAuthInfoService. 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 NewMockAuthInfoService(t interface { @@ -25,741 +171,3 @@ func NewMockAuthInfoService(t interface { return mock } - -// MockAuthInfoService is an autogenerated mock type for the AuthInfoService type -type MockAuthInfoService struct { - mock.Mock -} - -type MockAuthInfoService_Expecter struct { - mock *mock.Mock -} - -func (_m *MockAuthInfoService) EXPECT() *MockAuthInfoService_Expecter { - return &MockAuthInfoService_Expecter{mock: &_m.Mock} -} - -// DeleteUserAuthInfo provides a mock function for the type MockAuthInfoService -func (_mock *MockAuthInfoService) DeleteUserAuthInfo(ctx context.Context, userID int64) error { - ret := _mock.Called(ctx, userID) - - if len(ret) == 0 { - panic("no return value specified for DeleteUserAuthInfo") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, int64) error); ok { - r0 = returnFunc(ctx, userID) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockAuthInfoService_DeleteUserAuthInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteUserAuthInfo' -type MockAuthInfoService_DeleteUserAuthInfo_Call struct { - *mock.Call -} - -// DeleteUserAuthInfo is a helper method to define mock.On call -// - ctx context.Context -// - userID int64 -func (_e *MockAuthInfoService_Expecter) DeleteUserAuthInfo(ctx interface{}, userID interface{}) *MockAuthInfoService_DeleteUserAuthInfo_Call { - return &MockAuthInfoService_DeleteUserAuthInfo_Call{Call: _e.mock.On("DeleteUserAuthInfo", ctx, userID)} -} - -func (_c *MockAuthInfoService_DeleteUserAuthInfo_Call) Run(run func(ctx context.Context, userID int64)) *MockAuthInfoService_DeleteUserAuthInfo_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 int64 - if args[1] != nil { - arg1 = args[1].(int64) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockAuthInfoService_DeleteUserAuthInfo_Call) Return(err error) *MockAuthInfoService_DeleteUserAuthInfo_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockAuthInfoService_DeleteUserAuthInfo_Call) RunAndReturn(run func(ctx context.Context, userID int64) error) *MockAuthInfoService_DeleteUserAuthInfo_Call { - _c.Call.Return(run) - return _c -} - -// GetAuthInfo provides a mock function for the type MockAuthInfoService -func (_mock *MockAuthInfoService) GetAuthInfo(ctx context.Context, query *login.GetAuthInfoQuery) (*login.UserAuth, error) { - ret := _mock.Called(ctx, query) - - if len(ret) == 0 { - panic("no return value specified for GetAuthInfo") - } - - var r0 *login.UserAuth - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *login.GetAuthInfoQuery) (*login.UserAuth, error)); ok { - return returnFunc(ctx, query) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, *login.GetAuthInfoQuery) *login.UserAuth); ok { - r0 = returnFunc(ctx, query) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*login.UserAuth) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, *login.GetAuthInfoQuery) error); ok { - r1 = returnFunc(ctx, query) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockAuthInfoService_GetAuthInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAuthInfo' -type MockAuthInfoService_GetAuthInfo_Call struct { - *mock.Call -} - -// GetAuthInfo is a helper method to define mock.On call -// - ctx context.Context -// - query *login.GetAuthInfoQuery -func (_e *MockAuthInfoService_Expecter) GetAuthInfo(ctx interface{}, query interface{}) *MockAuthInfoService_GetAuthInfo_Call { - return &MockAuthInfoService_GetAuthInfo_Call{Call: _e.mock.On("GetAuthInfo", ctx, query)} -} - -func (_c *MockAuthInfoService_GetAuthInfo_Call) Run(run func(ctx context.Context, query *login.GetAuthInfoQuery)) *MockAuthInfoService_GetAuthInfo_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 *login.GetAuthInfoQuery - if args[1] != nil { - arg1 = args[1].(*login.GetAuthInfoQuery) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockAuthInfoService_GetAuthInfo_Call) Return(userAuth *login.UserAuth, err error) *MockAuthInfoService_GetAuthInfo_Call { - _c.Call.Return(userAuth, err) - return _c -} - -func (_c *MockAuthInfoService_GetAuthInfo_Call) RunAndReturn(run func(ctx context.Context, query *login.GetAuthInfoQuery) (*login.UserAuth, error)) *MockAuthInfoService_GetAuthInfo_Call { - _c.Call.Return(run) - return _c -} - -// GetUserLabels provides a mock function for the type MockAuthInfoService -func (_mock *MockAuthInfoService) GetUserLabels(ctx context.Context, query login.GetUserLabelsQuery) (map[int64]string, error) { - ret := _mock.Called(ctx, query) - - if len(ret) == 0 { - panic("no return value specified for GetUserLabels") - } - - var r0 map[int64]string - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, login.GetUserLabelsQuery) (map[int64]string, error)); ok { - return returnFunc(ctx, query) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, login.GetUserLabelsQuery) map[int64]string); ok { - r0 = returnFunc(ctx, query) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(map[int64]string) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, login.GetUserLabelsQuery) error); ok { - r1 = returnFunc(ctx, query) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockAuthInfoService_GetUserLabels_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUserLabels' -type MockAuthInfoService_GetUserLabels_Call struct { - *mock.Call -} - -// GetUserLabels is a helper method to define mock.On call -// - ctx context.Context -// - query login.GetUserLabelsQuery -func (_e *MockAuthInfoService_Expecter) GetUserLabels(ctx interface{}, query interface{}) *MockAuthInfoService_GetUserLabels_Call { - return &MockAuthInfoService_GetUserLabels_Call{Call: _e.mock.On("GetUserLabels", ctx, query)} -} - -func (_c *MockAuthInfoService_GetUserLabels_Call) Run(run func(ctx context.Context, query login.GetUserLabelsQuery)) *MockAuthInfoService_GetUserLabels_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 login.GetUserLabelsQuery - if args[1] != nil { - arg1 = args[1].(login.GetUserLabelsQuery) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockAuthInfoService_GetUserLabels_Call) Return(int64ToString map[int64]string, err error) *MockAuthInfoService_GetUserLabels_Call { - _c.Call.Return(int64ToString, err) - return _c -} - -func (_c *MockAuthInfoService_GetUserLabels_Call) RunAndReturn(run func(ctx context.Context, query login.GetUserLabelsQuery) (map[int64]string, error)) *MockAuthInfoService_GetUserLabels_Call { - _c.Call.Return(run) - return _c -} - -// SetAuthInfo provides a mock function for the type MockAuthInfoService -func (_mock *MockAuthInfoService) SetAuthInfo(ctx context.Context, cmd *login.SetAuthInfoCommand) error { - ret := _mock.Called(ctx, cmd) - - if len(ret) == 0 { - panic("no return value specified for SetAuthInfo") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *login.SetAuthInfoCommand) error); ok { - r0 = returnFunc(ctx, cmd) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockAuthInfoService_SetAuthInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetAuthInfo' -type MockAuthInfoService_SetAuthInfo_Call struct { - *mock.Call -} - -// SetAuthInfo is a helper method to define mock.On call -// - ctx context.Context -// - cmd *login.SetAuthInfoCommand -func (_e *MockAuthInfoService_Expecter) SetAuthInfo(ctx interface{}, cmd interface{}) *MockAuthInfoService_SetAuthInfo_Call { - return &MockAuthInfoService_SetAuthInfo_Call{Call: _e.mock.On("SetAuthInfo", ctx, cmd)} -} - -func (_c *MockAuthInfoService_SetAuthInfo_Call) Run(run func(ctx context.Context, cmd *login.SetAuthInfoCommand)) *MockAuthInfoService_SetAuthInfo_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 *login.SetAuthInfoCommand - if args[1] != nil { - arg1 = args[1].(*login.SetAuthInfoCommand) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockAuthInfoService_SetAuthInfo_Call) Return(err error) *MockAuthInfoService_SetAuthInfo_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockAuthInfoService_SetAuthInfo_Call) RunAndReturn(run func(ctx context.Context, cmd *login.SetAuthInfoCommand) error) *MockAuthInfoService_SetAuthInfo_Call { - _c.Call.Return(run) - return _c -} - -// UpdateAuthInfo provides a mock function for the type MockAuthInfoService -func (_mock *MockAuthInfoService) UpdateAuthInfo(ctx context.Context, cmd *login.UpdateAuthInfoCommand) error { - ret := _mock.Called(ctx, cmd) - - if len(ret) == 0 { - panic("no return value specified for UpdateAuthInfo") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *login.UpdateAuthInfoCommand) error); ok { - r0 = returnFunc(ctx, cmd) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockAuthInfoService_UpdateAuthInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateAuthInfo' -type MockAuthInfoService_UpdateAuthInfo_Call struct { - *mock.Call -} - -// UpdateAuthInfo is a helper method to define mock.On call -// - ctx context.Context -// - cmd *login.UpdateAuthInfoCommand -func (_e *MockAuthInfoService_Expecter) UpdateAuthInfo(ctx interface{}, cmd interface{}) *MockAuthInfoService_UpdateAuthInfo_Call { - return &MockAuthInfoService_UpdateAuthInfo_Call{Call: _e.mock.On("UpdateAuthInfo", ctx, cmd)} -} - -func (_c *MockAuthInfoService_UpdateAuthInfo_Call) Run(run func(ctx context.Context, cmd *login.UpdateAuthInfoCommand)) *MockAuthInfoService_UpdateAuthInfo_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 *login.UpdateAuthInfoCommand - if args[1] != nil { - arg1 = args[1].(*login.UpdateAuthInfoCommand) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockAuthInfoService_UpdateAuthInfo_Call) Return(err error) *MockAuthInfoService_UpdateAuthInfo_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockAuthInfoService_UpdateAuthInfo_Call) RunAndReturn(run func(ctx context.Context, cmd *login.UpdateAuthInfoCommand) error) *MockAuthInfoService_UpdateAuthInfo_Call { - _c.Call.Return(run) - return _c -} - -// NewMockStore creates a new instance of MockStore. 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 NewMockStore(t interface { - mock.TestingT - Cleanup(func()) -}) *MockStore { - mock := &MockStore{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} - -// MockStore is an autogenerated mock type for the Store type -type MockStore struct { - mock.Mock -} - -type MockStore_Expecter struct { - mock *mock.Mock -} - -func (_m *MockStore) EXPECT() *MockStore_Expecter { - return &MockStore_Expecter{mock: &_m.Mock} -} - -// DeleteUserAuthInfo provides a mock function for the type MockStore -func (_mock *MockStore) DeleteUserAuthInfo(ctx context.Context, userID int64) error { - ret := _mock.Called(ctx, userID) - - if len(ret) == 0 { - panic("no return value specified for DeleteUserAuthInfo") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, int64) error); ok { - r0 = returnFunc(ctx, userID) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockStore_DeleteUserAuthInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteUserAuthInfo' -type MockStore_DeleteUserAuthInfo_Call struct { - *mock.Call -} - -// DeleteUserAuthInfo is a helper method to define mock.On call -// - ctx context.Context -// - userID int64 -func (_e *MockStore_Expecter) DeleteUserAuthInfo(ctx interface{}, userID interface{}) *MockStore_DeleteUserAuthInfo_Call { - return &MockStore_DeleteUserAuthInfo_Call{Call: _e.mock.On("DeleteUserAuthInfo", ctx, userID)} -} - -func (_c *MockStore_DeleteUserAuthInfo_Call) Run(run func(ctx context.Context, userID int64)) *MockStore_DeleteUserAuthInfo_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 int64 - if args[1] != nil { - arg1 = args[1].(int64) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockStore_DeleteUserAuthInfo_Call) Return(err error) *MockStore_DeleteUserAuthInfo_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockStore_DeleteUserAuthInfo_Call) RunAndReturn(run func(ctx context.Context, userID int64) error) *MockStore_DeleteUserAuthInfo_Call { - _c.Call.Return(run) - return _c -} - -// GetAuthInfo provides a mock function for the type MockStore -func (_mock *MockStore) GetAuthInfo(ctx context.Context, query *login.GetAuthInfoQuery) (*login.UserAuth, error) { - ret := _mock.Called(ctx, query) - - if len(ret) == 0 { - panic("no return value specified for GetAuthInfo") - } - - var r0 *login.UserAuth - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *login.GetAuthInfoQuery) (*login.UserAuth, error)); ok { - return returnFunc(ctx, query) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, *login.GetAuthInfoQuery) *login.UserAuth); ok { - r0 = returnFunc(ctx, query) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*login.UserAuth) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, *login.GetAuthInfoQuery) error); ok { - r1 = returnFunc(ctx, query) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockStore_GetAuthInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAuthInfo' -type MockStore_GetAuthInfo_Call struct { - *mock.Call -} - -// GetAuthInfo is a helper method to define mock.On call -// - ctx context.Context -// - query *login.GetAuthInfoQuery -func (_e *MockStore_Expecter) GetAuthInfo(ctx interface{}, query interface{}) *MockStore_GetAuthInfo_Call { - return &MockStore_GetAuthInfo_Call{Call: _e.mock.On("GetAuthInfo", ctx, query)} -} - -func (_c *MockStore_GetAuthInfo_Call) Run(run func(ctx context.Context, query *login.GetAuthInfoQuery)) *MockStore_GetAuthInfo_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 *login.GetAuthInfoQuery - if args[1] != nil { - arg1 = args[1].(*login.GetAuthInfoQuery) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockStore_GetAuthInfo_Call) Return(userAuth *login.UserAuth, err error) *MockStore_GetAuthInfo_Call { - _c.Call.Return(userAuth, err) - return _c -} - -func (_c *MockStore_GetAuthInfo_Call) RunAndReturn(run func(ctx context.Context, query *login.GetAuthInfoQuery) (*login.UserAuth, error)) *MockStore_GetAuthInfo_Call { - _c.Call.Return(run) - return _c -} - -// GetUserLabels provides a mock function for the type MockStore -func (_mock *MockStore) GetUserLabels(ctx context.Context, query login.GetUserLabelsQuery) (map[int64]string, error) { - ret := _mock.Called(ctx, query) - - if len(ret) == 0 { - panic("no return value specified for GetUserLabels") - } - - var r0 map[int64]string - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, login.GetUserLabelsQuery) (map[int64]string, error)); ok { - return returnFunc(ctx, query) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, login.GetUserLabelsQuery) map[int64]string); ok { - r0 = returnFunc(ctx, query) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(map[int64]string) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, login.GetUserLabelsQuery) error); ok { - r1 = returnFunc(ctx, query) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockStore_GetUserLabels_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUserLabels' -type MockStore_GetUserLabels_Call struct { - *mock.Call -} - -// GetUserLabels is a helper method to define mock.On call -// - ctx context.Context -// - query login.GetUserLabelsQuery -func (_e *MockStore_Expecter) GetUserLabels(ctx interface{}, query interface{}) *MockStore_GetUserLabels_Call { - return &MockStore_GetUserLabels_Call{Call: _e.mock.On("GetUserLabels", ctx, query)} -} - -func (_c *MockStore_GetUserLabels_Call) Run(run func(ctx context.Context, query login.GetUserLabelsQuery)) *MockStore_GetUserLabels_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 login.GetUserLabelsQuery - if args[1] != nil { - arg1 = args[1].(login.GetUserLabelsQuery) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockStore_GetUserLabels_Call) Return(int64ToString map[int64]string, err error) *MockStore_GetUserLabels_Call { - _c.Call.Return(int64ToString, err) - return _c -} - -func (_c *MockStore_GetUserLabels_Call) RunAndReturn(run func(ctx context.Context, query login.GetUserLabelsQuery) (map[int64]string, error)) *MockStore_GetUserLabels_Call { - _c.Call.Return(run) - return _c -} - -// SetAuthInfo provides a mock function for the type MockStore -func (_mock *MockStore) SetAuthInfo(ctx context.Context, cmd *login.SetAuthInfoCommand) error { - ret := _mock.Called(ctx, cmd) - - if len(ret) == 0 { - panic("no return value specified for SetAuthInfo") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *login.SetAuthInfoCommand) error); ok { - r0 = returnFunc(ctx, cmd) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockStore_SetAuthInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetAuthInfo' -type MockStore_SetAuthInfo_Call struct { - *mock.Call -} - -// SetAuthInfo is a helper method to define mock.On call -// - ctx context.Context -// - cmd *login.SetAuthInfoCommand -func (_e *MockStore_Expecter) SetAuthInfo(ctx interface{}, cmd interface{}) *MockStore_SetAuthInfo_Call { - return &MockStore_SetAuthInfo_Call{Call: _e.mock.On("SetAuthInfo", ctx, cmd)} -} - -func (_c *MockStore_SetAuthInfo_Call) Run(run func(ctx context.Context, cmd *login.SetAuthInfoCommand)) *MockStore_SetAuthInfo_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 *login.SetAuthInfoCommand - if args[1] != nil { - arg1 = args[1].(*login.SetAuthInfoCommand) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockStore_SetAuthInfo_Call) Return(err error) *MockStore_SetAuthInfo_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockStore_SetAuthInfo_Call) RunAndReturn(run func(ctx context.Context, cmd *login.SetAuthInfoCommand) error) *MockStore_SetAuthInfo_Call { - _c.Call.Return(run) - return _c -} - -// UpdateAuthInfo provides a mock function for the type MockStore -func (_mock *MockStore) UpdateAuthInfo(ctx context.Context, cmd *login.UpdateAuthInfoCommand) error { - ret := _mock.Called(ctx, cmd) - - if len(ret) == 0 { - panic("no return value specified for UpdateAuthInfo") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *login.UpdateAuthInfoCommand) error); ok { - r0 = returnFunc(ctx, cmd) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockStore_UpdateAuthInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateAuthInfo' -type MockStore_UpdateAuthInfo_Call struct { - *mock.Call -} - -// UpdateAuthInfo is a helper method to define mock.On call -// - ctx context.Context -// - cmd *login.UpdateAuthInfoCommand -func (_e *MockStore_Expecter) UpdateAuthInfo(ctx interface{}, cmd interface{}) *MockStore_UpdateAuthInfo_Call { - return &MockStore_UpdateAuthInfo_Call{Call: _e.mock.On("UpdateAuthInfo", ctx, cmd)} -} - -func (_c *MockStore_UpdateAuthInfo_Call) Run(run func(ctx context.Context, cmd *login.UpdateAuthInfoCommand)) *MockStore_UpdateAuthInfo_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 *login.UpdateAuthInfoCommand - if args[1] != nil { - arg1 = args[1].(*login.UpdateAuthInfoCommand) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockStore_UpdateAuthInfo_Call) Return(err error) *MockStore_UpdateAuthInfo_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockStore_UpdateAuthInfo_Call) RunAndReturn(run func(ctx context.Context, cmd *login.UpdateAuthInfoCommand) error) *MockStore_UpdateAuthInfo_Call { - _c.Call.Return(run) - return _c -} - -// NewMockUserProtectionService creates a new instance of MockUserProtectionService. 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 NewMockUserProtectionService(t interface { - mock.TestingT - Cleanup(func()) -}) *MockUserProtectionService { - mock := &MockUserProtectionService{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} - -// MockUserProtectionService is an autogenerated mock type for the UserProtectionService type -type MockUserProtectionService struct { - mock.Mock -} - -type MockUserProtectionService_Expecter struct { - mock *mock.Mock -} - -func (_m *MockUserProtectionService) EXPECT() *MockUserProtectionService_Expecter { - return &MockUserProtectionService_Expecter{mock: &_m.Mock} -} - -// AllowUserMapping provides a mock function for the type MockUserProtectionService -func (_mock *MockUserProtectionService) AllowUserMapping(user1 *user.User, authModule string) error { - ret := _mock.Called(user1, authModule) - - if len(ret) == 0 { - panic("no return value specified for AllowUserMapping") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(*user.User, string) error); ok { - r0 = returnFunc(user1, authModule) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockUserProtectionService_AllowUserMapping_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllowUserMapping' -type MockUserProtectionService_AllowUserMapping_Call struct { - *mock.Call -} - -// AllowUserMapping is a helper method to define mock.On call -// - user1 *user.User -// - authModule string -func (_e *MockUserProtectionService_Expecter) AllowUserMapping(user1 interface{}, authModule interface{}) *MockUserProtectionService_AllowUserMapping_Call { - return &MockUserProtectionService_AllowUserMapping_Call{Call: _e.mock.On("AllowUserMapping", user1, authModule)} -} - -func (_c *MockUserProtectionService_AllowUserMapping_Call) Run(run func(user1 *user.User, authModule string)) *MockUserProtectionService_AllowUserMapping_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 *user.User - if args[0] != nil { - arg0 = args[0].(*user.User) - } - var arg1 string - if args[1] != nil { - arg1 = args[1].(string) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockUserProtectionService_AllowUserMapping_Call) Return(err error) *MockUserProtectionService_AllowUserMapping_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockUserProtectionService_AllowUserMapping_Call) RunAndReturn(run func(user1 *user.User, authModule string) error) *MockUserProtectionService_AllowUserMapping_Call { - _c.Call.Return(run) - return _c -} diff --git a/pkg/services/login/authinfotest/auth_info_store_mock.go b/pkg/services/login/authinfotest/auth_info_store_mock.go new file mode 100644 index 00000000000..676985404c8 --- /dev/null +++ b/pkg/services/login/authinfotest/auth_info_store_mock.go @@ -0,0 +1,173 @@ +// Code generated by mockery v2.53.5. DO NOT EDIT. + +package authinfotest + +import ( + context "context" + + login "github.com/grafana/grafana/pkg/services/login" + mock "github.com/stretchr/testify/mock" +) + +// MockAuthInfoStore is an autogenerated mock type for the Store type +type MockAuthInfoStore struct { + mock.Mock +} + +// DeleteUserAuthInfo provides a mock function with given fields: ctx, userID +func (_m *MockAuthInfoStore) DeleteUserAuthInfo(ctx context.Context, userID int64) error { + ret := _m.Called(ctx, userID) + + if len(ret) == 0 { + panic("no return value specified for DeleteUserAuthInfo") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok { + r0 = rf(ctx, userID) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GetAuthInfo provides a mock function with given fields: ctx, query +func (_m *MockAuthInfoStore) GetAuthInfo(ctx context.Context, query *login.GetAuthInfoQuery) (*login.UserAuth, error) { + ret := _m.Called(ctx, query) + + if len(ret) == 0 { + panic("no return value specified for GetAuthInfo") + } + + var r0 *login.UserAuth + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *login.GetAuthInfoQuery) (*login.UserAuth, error)); ok { + return rf(ctx, query) + } + if rf, ok := ret.Get(0).(func(context.Context, *login.GetAuthInfoQuery) *login.UserAuth); ok { + r0 = rf(ctx, query) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*login.UserAuth) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *login.GetAuthInfoQuery) error); ok { + r1 = rf(ctx, query) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetUserAuthModules provides a mock function with given fields: ctx, userID +func (_m *MockAuthInfoStore) GetUserAuthModules(ctx context.Context, userID int64) ([]string, error) { + ret := _m.Called(ctx, userID) + + if len(ret) == 0 { + panic("no return value specified for GetUserAuthModules") + } + + var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) ([]string, error)); ok { + return rf(ctx, userID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) []string); ok { + r0 = rf(ctx, userID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, userID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetUsersRecentlyUsedLabel provides a mock function with given fields: ctx, query +func (_m *MockAuthInfoStore) GetUsersRecentlyUsedLabel(ctx context.Context, query login.GetUserLabelsQuery) (map[int64]string, error) { + ret := _m.Called(ctx, query) + + if len(ret) == 0 { + panic("no return value specified for GetUsersRecentlyUsedLabel") + } + + var r0 map[int64]string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, login.GetUserLabelsQuery) (map[int64]string, error)); ok { + return rf(ctx, query) + } + if rf, ok := ret.Get(0).(func(context.Context, login.GetUserLabelsQuery) map[int64]string); ok { + r0 = rf(ctx, query) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[int64]string) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, login.GetUserLabelsQuery) error); ok { + r1 = rf(ctx, query) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SetAuthInfo provides a mock function with given fields: ctx, cmd +func (_m *MockAuthInfoStore) SetAuthInfo(ctx context.Context, cmd *login.SetAuthInfoCommand) error { + ret := _m.Called(ctx, cmd) + + if len(ret) == 0 { + panic("no return value specified for SetAuthInfo") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *login.SetAuthInfoCommand) error); ok { + r0 = rf(ctx, cmd) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// UpdateAuthInfo provides a mock function with given fields: ctx, cmd +func (_m *MockAuthInfoStore) UpdateAuthInfo(ctx context.Context, cmd *login.UpdateAuthInfoCommand) error { + ret := _m.Called(ctx, cmd) + + if len(ret) == 0 { + panic("no return value specified for UpdateAuthInfo") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *login.UpdateAuthInfoCommand) error); ok { + r0 = rf(ctx, cmd) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// NewMockAuthInfoStore creates a new instance of MockAuthInfoStore. 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 NewMockAuthInfoStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockAuthInfoStore { + mock := &MockAuthInfoStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/services/login/authinfotest/fake.go b/pkg/services/login/authinfotest/fake.go index 9a4d7843a3c..63a9796bbfc 100644 --- a/pkg/services/login/authinfotest/fake.go +++ b/pkg/services/login/authinfotest/fake.go @@ -8,11 +8,12 @@ import ( type FakeService struct { login.AuthInfoService - LatestUserID int64 - ExpectedUserAuth *login.UserAuth - ExpectedExternalUser *login.ExternalUserInfo - ExpectedError error - ExpectedLabels map[int64]string + LatestUserID int64 + ExpectedUserAuth *login.UserAuth + ExpectedExternalUser *login.ExternalUserInfo + ExpectedError error + ExpectedRecentlyUsedLabel map[int64]string + ExpectedAuthModuleLabels []string SetAuthInfoFn func(ctx context.Context, cmd *login.SetAuthInfoCommand) error UpdateAuthInfoFn func(ctx context.Context, cmd *login.UpdateAuthInfoCommand) error @@ -24,8 +25,12 @@ func (a *FakeService) GetAuthInfo(ctx context.Context, query *login.GetAuthInfoQ return a.ExpectedUserAuth, a.ExpectedError } -func (a *FakeService) GetUserLabels(ctx context.Context, query login.GetUserLabelsQuery) (map[int64]string, error) { - return a.ExpectedLabels, a.ExpectedError +func (a *FakeService) GetUsersRecentlyUsedLabel(ctx context.Context, query login.GetUserLabelsQuery) (map[int64]string, error) { + return a.ExpectedRecentlyUsedLabel, a.ExpectedError +} + +func (a *FakeService) GetUserAuthModuleLabels(ctx context.Context, userID int64) ([]string, error) { + return a.ExpectedAuthModuleLabels, a.ExpectedError } func (a *FakeService) SetAuthInfo(ctx context.Context, cmd *login.SetAuthInfoCommand) error {