mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Remove result field from loginattempt (#65117)
remove result field from loginattempt
This commit is contained in:
parent
e1d99365c1
commit
51fdf37faa
@ -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…
Reference in New Issue
Block a user