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 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…
Reference in New Issue
Block a user