Auth: Remove userauth service (#58941)
* Auth: remove userauth service * Use Revoke user tokens from UserAuthTokenService * Add function to delete user auth info to UserAuthInfo service
This commit is contained in:
@@ -13,6 +13,7 @@ type AuthInfoService interface {
|
||||
GetExternalUserInfoByLogin(ctx context.Context, query *models.GetExternalUserInfoByLoginQuery) error
|
||||
SetAuthInfo(ctx context.Context, cmd *models.SetAuthInfoCommand) error
|
||||
UpdateAuthInfo(ctx context.Context, cmd *models.UpdateAuthInfoCommand) error
|
||||
DeleteUserAuthInfo(ctx context.Context, userID int64) error
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -218,6 +218,14 @@ func (s *AuthInfoStore) DeleteAuthInfo(ctx context.Context, cmd *models.DeleteAu
|
||||
})
|
||||
}
|
||||
|
||||
func (s *AuthInfoStore) DeleteUserAuthInfo(ctx context.Context, userID int64) error {
|
||||
return s.sqlStore.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
var rawSQL = "DELETE FROM user_auth WHERE user_id = ?"
|
||||
_, err := sess.Exec(rawSQL, userID)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (s *AuthInfoStore) GetUserById(ctx context.Context, id int64) (*user.User, error) {
|
||||
query := user.GetUserByIDQuery{ID: id}
|
||||
user, err := s.userService.GetByID(ctx, &query)
|
||||
|
||||
@@ -197,6 +197,10 @@ func (s *Implementation) GetExternalUserInfoByLogin(ctx context.Context, query *
|
||||
return s.authInfoStore.GetExternalUserInfoByLogin(ctx, query)
|
||||
}
|
||||
|
||||
func (s *Implementation) DeleteUserAuthInfo(ctx context.Context, userID int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Implementation) Run(ctx context.Context) error {
|
||||
s.logger.Debug("Started AuthInfo Metrics collection service")
|
||||
return s.authInfoStore.RunMetricsCollection(ctx)
|
||||
|
||||
@@ -57,6 +57,10 @@ func (a *AuthInfoServiceFake) GetExternalUserInfoByLogin(ctx context.Context, qu
|
||||
return a.ExpectedError
|
||||
}
|
||||
|
||||
func (a *AuthInfoServiceFake) DeleteUserAuthInfo(ctx context.Context, userID int64) error {
|
||||
return a.ExpectedError
|
||||
}
|
||||
|
||||
type AuthenticatorFake struct {
|
||||
ExpectedUser *user.User
|
||||
ExpectedError error
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package userauth
|
||||
|
||||
import "context"
|
||||
|
||||
type Service interface {
|
||||
Delete(context.Context, int64) error
|
||||
DeleteToken(context.Context, int64) error
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package userauthimpl
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
)
|
||||
|
||||
type store interface {
|
||||
Delete(context.Context, int64) error
|
||||
DeleteToken(context.Context, int64) error
|
||||
}
|
||||
|
||||
type sqlStore struct {
|
||||
db db.DB
|
||||
}
|
||||
|
||||
func (ss *sqlStore) Delete(ctx context.Context, userID int64) error {
|
||||
return ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
var rawSQL = "DELETE FROM user_auth WHERE user_id = ?"
|
||||
_, err := sess.Exec(rawSQL, userID)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (ss *sqlStore) DeleteToken(ctx context.Context, userID int64) error {
|
||||
return ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
var rawSQL = "DELETE FROM user_auth_token WHERE user_id = ?"
|
||||
_, err := sess.Exec(rawSQL, userID)
|
||||
return err
|
||||
})
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package userauthimpl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
)
|
||||
|
||||
func TestIntegrationUserAuthDataAccess(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
ss := db.InitTestDB(t)
|
||||
userAuthStore := sqlStore{
|
||||
db: ss,
|
||||
}
|
||||
|
||||
t.Run("delete user auth", func(t *testing.T) {
|
||||
err := userAuthStore.Delete(context.Background(), 1)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("delete user auth token", func(t *testing.T) {
|
||||
err := userAuthStore.DeleteToken(context.Background(), 1)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package userauthimpl
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/services/userauth"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
store store
|
||||
}
|
||||
|
||||
func ProvideService(db db.DB) userauth.Service {
|
||||
return &Service{
|
||||
store: &sqlStore{
|
||||
db: db,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) Delete(ctx context.Context, userID int64) error {
|
||||
return s.store.Delete(ctx, userID)
|
||||
}
|
||||
|
||||
func (s *Service) DeleteToken(ctx context.Context, userID int64) error {
|
||||
return s.store.DeleteToken(ctx, userID)
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package userauthimpl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestUserAuthService(t *testing.T) {
|
||||
userAuthStore := &FakeUserAuthStore{}
|
||||
userAuthService := Service{
|
||||
store: userAuthStore,
|
||||
}
|
||||
|
||||
t.Run("delete user", func(t *testing.T) {
|
||||
err := userAuthService.Delete(context.Background(), 1)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("delete token", func(t *testing.T) {
|
||||
err := userAuthService.DeleteToken(context.Background(), 1)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
type FakeUserAuthStore struct {
|
||||
ExpectedError error
|
||||
}
|
||||
|
||||
func (f *FakeUserAuthStore) Delete(ctx context.Context, userID int64) error {
|
||||
return f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeUserAuthStore) DeleteToken(ctx context.Context, userID int64) error {
|
||||
return f.ExpectedError
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package userauthtest
|
||||
|
||||
import "context"
|
||||
|
||||
type FakeUserAuthService struct {
|
||||
ExpectedError error
|
||||
}
|
||||
|
||||
func NewFakeUserAuthService() *FakeUserAuthService {
|
||||
return &FakeUserAuthService{}
|
||||
}
|
||||
|
||||
func (f *FakeUserAuthService) Delete(ctx context.Context, userID int64) error {
|
||||
return f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeUserAuthService) DeleteToken(ctx context.Context, userID int64) error {
|
||||
return f.ExpectedError
|
||||
}
|
||||
Reference in New Issue
Block a user