Chore: Remove result field from loginattempt (#65117)

remove result field from loginattempt
pull/65249/head
Serge Zaitsev 2 years ago committed by GitHub
parent e1d99365c1
commit 51fdf37faa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      pkg/services/loginattempt/loginattemptimpl/login_attempt.go
  2. 5
      pkg/services/loginattempt/loginattemptimpl/login_attempt_test.go
  3. 4
      pkg/services/loginattempt/loginattemptimpl/models.go
  4. 9
      pkg/services/loginattempt/loginattemptimpl/store.go
  5. 12
      pkg/services/loginattempt/loginattemptimpl/store_test.go

@ -53,10 +53,11 @@ func (s *Service) Add(ctx context.Context, username, IPAddress string) error {
return nil return nil
} }
return s.store.CreateLoginAttempt(ctx, CreateLoginAttemptCommand{ _, err := s.store.CreateLoginAttempt(ctx, CreateLoginAttemptCommand{
Username: username, Username: username,
IpAddress: IPAddress, IpAddress: IPAddress,
}) })
return err
} }
func (s *Service) Reset(ctx context.Context, username string) error { func (s *Service) Reset(ctx context.Context, username string) error {

@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/grafana/grafana/pkg/services/loginattempt"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
@ -90,8 +91,8 @@ func (f fakeStore) GetUserLoginAttemptCount(ctx context.Context, query GetUserLo
return f.ExpectedCount, f.ExpectedErr return f.ExpectedCount, f.ExpectedErr
} }
func (f fakeStore) CreateLoginAttempt(ctx context.Context, command CreateLoginAttemptCommand) error { func (f fakeStore) CreateLoginAttempt(ctx context.Context, command CreateLoginAttemptCommand) (loginattempt.LoginAttempt, error) {
return f.ExpectedErr return loginattempt.LoginAttempt{}, f.ExpectedErr
} }
func (f fakeStore) DeleteOldLoginAttempts(ctx context.Context, command DeleteOldLoginAttemptsCommand) (int64, error) { func (f fakeStore) DeleteOldLoginAttempts(ctx context.Context, command DeleteOldLoginAttemptsCommand) (int64, error) {

@ -2,15 +2,11 @@ package loginattemptimpl
import ( import (
"time" "time"
"github.com/grafana/grafana/pkg/services/loginattempt"
) )
type CreateLoginAttemptCommand struct { type CreateLoginAttemptCommand struct {
Username string Username string
IpAddress string IpAddress string
Result loginattempt.LoginAttempt
} }
type GetUserLoginAttemptCountQuery struct { type GetUserLoginAttemptCountQuery struct {

@ -14,14 +14,14 @@ type xormStore struct {
} }
type store interface { type store interface {
CreateLoginAttempt(ctx context.Context, cmd CreateLoginAttemptCommand) error CreateLoginAttempt(ctx context.Context, cmd CreateLoginAttemptCommand) (loginattempt.LoginAttempt, error)
DeleteOldLoginAttempts(ctx context.Context, cmd DeleteOldLoginAttemptsCommand) (int64, error) DeleteOldLoginAttempts(ctx context.Context, cmd DeleteOldLoginAttemptsCommand) (int64, error)
DeleteLoginAttempts(ctx context.Context, cmd DeleteLoginAttemptsCommand) error DeleteLoginAttempts(ctx context.Context, cmd DeleteLoginAttemptsCommand) error
GetUserLoginAttemptCount(ctx context.Context, query GetUserLoginAttemptCountQuery) (int64, error) GetUserLoginAttemptCount(ctx context.Context, query GetUserLoginAttemptCountQuery) (int64, error)
} }
func (xs *xormStore) CreateLoginAttempt(ctx context.Context, cmd CreateLoginAttemptCommand) error { func (xs *xormStore) CreateLoginAttempt(ctx context.Context, cmd CreateLoginAttemptCommand) (result loginattempt.LoginAttempt, err error) {
return xs.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error { err = xs.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
loginAttempt := loginattempt.LoginAttempt{ loginAttempt := loginattempt.LoginAttempt{
Username: cmd.Username, Username: cmd.Username,
IpAddress: cmd.IpAddress, IpAddress: cmd.IpAddress,
@ -32,10 +32,11 @@ func (xs *xormStore) CreateLoginAttempt(ctx context.Context, cmd CreateLoginAtte
return err return err
} }
cmd.Result = loginAttempt result = loginAttempt
return nil return nil
}) })
return result, err
} }
func (xs *xormStore) DeleteOldLoginAttempts(ctx context.Context, cmd DeleteOldLoginAttemptsCommand) (int64, error) { func (xs *xormStore) DeleteOldLoginAttempts(ctx context.Context, cmd DeleteOldLoginAttemptsCommand) (int64, error) {

@ -53,21 +53,21 @@ func TestIntegrationLoginAttemptsQuery(t *testing.T) {
now: func() time.Time { return mockTime }, now: func() time.Time { return mockTime },
} }
err := s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{ _, err := s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{
Username: user, Username: user,
IpAddress: "192.168.0.1", IpAddress: "192.168.0.1",
}) })
require.Nil(t, err) require.Nil(t, err)
mockTime = timePlusOneMinute mockTime = timePlusOneMinute
err = s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{ _, err = s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{
Username: user, Username: user,
IpAddress: "192.168.0.1", IpAddress: "192.168.0.1",
}) })
require.Nil(t, err) require.Nil(t, err)
mockTime = timePlusTwoMinutes mockTime = timePlusTwoMinutes
err = s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{ _, err = s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{
Username: user, Username: user,
IpAddress: "192.168.0.1", IpAddress: "192.168.0.1",
}) })
@ -118,21 +118,21 @@ func TestIntegrationLoginAttemptsDelete(t *testing.T) {
now: func() time.Time { return mockTime }, now: func() time.Time { return mockTime },
} }
err := s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{ _, err := s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{
Username: user, Username: user,
IpAddress: "192.168.0.1", IpAddress: "192.168.0.1",
}) })
require.Nil(t, err) require.Nil(t, err)
mockTime = timePlusOneMinute mockTime = timePlusOneMinute
err = s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{ _, err = s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{
Username: user, Username: user,
IpAddress: "192.168.0.1", IpAddress: "192.168.0.1",
}) })
require.Nil(t, err) require.Nil(t, err)
mockTime = timePlusTwoMinutes mockTime = timePlusTwoMinutes
err = s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{ _, err = s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{
Username: user, Username: user,
IpAddress: "192.168.0.1", IpAddress: "192.168.0.1",
}) })

Loading…
Cancel
Save