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 s.store.CreateLoginAttempt(ctx, CreateLoginAttemptCommand{
_, err := s.store.CreateLoginAttempt(ctx, CreateLoginAttemptCommand{
Username: username,
IpAddress: IPAddress,
})
return err
}
func (s *Service) Reset(ctx context.Context, username string) error {

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

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

@ -14,14 +14,14 @@ type xormStore struct {
}
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)
DeleteLoginAttempts(ctx context.Context, cmd DeleteLoginAttemptsCommand) error
GetUserLoginAttemptCount(ctx context.Context, query GetUserLoginAttemptCountQuery) (int64, error)
}
func (xs *xormStore) CreateLoginAttempt(ctx context.Context, cmd CreateLoginAttemptCommand) error {
return xs.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
func (xs *xormStore) CreateLoginAttempt(ctx context.Context, cmd CreateLoginAttemptCommand) (result loginattempt.LoginAttempt, err error) {
err = xs.db.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
loginAttempt := loginattempt.LoginAttempt{
Username: cmd.Username,
IpAddress: cmd.IpAddress,
@ -32,10 +32,11 @@ func (xs *xormStore) CreateLoginAttempt(ctx context.Context, cmd CreateLoginAtte
return err
}
cmd.Result = loginAttempt
result = loginAttempt
return nil
})
return result, err
}
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 },
}
err := s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{
_, err := s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{
Username: user,
IpAddress: "192.168.0.1",
})
require.Nil(t, err)
mockTime = timePlusOneMinute
err = s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{
_, err = s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{
Username: user,
IpAddress: "192.168.0.1",
})
require.Nil(t, err)
mockTime = timePlusTwoMinutes
err = s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{
_, err = s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{
Username: user,
IpAddress: "192.168.0.1",
})
@ -118,21 +118,21 @@ func TestIntegrationLoginAttemptsDelete(t *testing.T) {
now: func() time.Time { return mockTime },
}
err := s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{
_, err := s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{
Username: user,
IpAddress: "192.168.0.1",
})
require.Nil(t, err)
mockTime = timePlusOneMinute
err = s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{
_, err = s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{
Username: user,
IpAddress: "192.168.0.1",
})
require.Nil(t, err)
mockTime = timePlusTwoMinutes
err = s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{
_, err = s.CreateLoginAttempt(context.Background(), CreateLoginAttemptCommand{
Username: user,
IpAddress: "192.168.0.1",
})

Loading…
Cancel
Save