mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Remove x from login attempt (#46853)
This commit is contained in:
parent
36483eb6bf
commit
39f14a2ec2
@ -14,7 +14,7 @@ var getTimeNow = time.Now
|
|||||||
func (ss *SQLStore) addLoginAttemptQueryAndCommandHandlers() {
|
func (ss *SQLStore) addLoginAttemptQueryAndCommandHandlers() {
|
||||||
bus.AddHandler("sql", ss.CreateLoginAttempt)
|
bus.AddHandler("sql", ss.CreateLoginAttempt)
|
||||||
bus.AddHandler("sql", ss.DeleteOldLoginAttempts)
|
bus.AddHandler("sql", ss.DeleteOldLoginAttempts)
|
||||||
bus.AddHandler("sql", GetUserLoginAttemptCount)
|
bus.AddHandler("sql", ss.GetUserLoginAttemptCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ss *SQLStore) CreateLoginAttempt(ctx context.Context, cmd *models.CreateLoginAttemptCommand) error {
|
func (ss *SQLStore) CreateLoginAttempt(ctx context.Context, cmd *models.CreateLoginAttemptCommand) error {
|
||||||
@ -65,19 +65,21 @@ func (ss *SQLStore) DeleteOldLoginAttempts(ctx context.Context, cmd *models.Dele
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUserLoginAttemptCount(ctx context.Context, query *models.GetUserLoginAttemptCountQuery) error {
|
func (ss *SQLStore) GetUserLoginAttemptCount(ctx context.Context, query *models.GetUserLoginAttemptCountQuery) error {
|
||||||
loginAttempt := new(models.LoginAttempt)
|
return ss.WithDbSession(ctx, func(dbSession *DBSession) error {
|
||||||
total, err := x.
|
loginAttempt := new(models.LoginAttempt)
|
||||||
Where("username = ?", query.Username).
|
total, err := dbSession.
|
||||||
And("created >= ?", query.Since.Unix()).
|
Where("username = ?", query.Username).
|
||||||
Count(loginAttempt)
|
And("created >= ?", query.Since.Unix()).
|
||||||
|
Count(loginAttempt)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
query.Result = total
|
query.Result = total
|
||||||
return nil
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func toInt64(i interface{}) int64 {
|
func toInt64(i interface{}) int64 {
|
||||||
|
@ -51,7 +51,7 @@ func TestLoginAttempts(t *testing.T) {
|
|||||||
Username: user,
|
Username: user,
|
||||||
Since: timePlusTwoMinutes.Add(time.Second * 1),
|
Since: timePlusTwoMinutes.Add(time.Second * 1),
|
||||||
}
|
}
|
||||||
err := GetUserLoginAttemptCount(context.Background(), &query)
|
err := sqlStore.GetUserLoginAttemptCount(context.Background(), &query)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, int64(0), query.Result)
|
require.Equal(t, int64(0), query.Result)
|
||||||
})
|
})
|
||||||
@ -62,7 +62,7 @@ func TestLoginAttempts(t *testing.T) {
|
|||||||
Username: user,
|
Username: user,
|
||||||
Since: beginningOfTime,
|
Since: beginningOfTime,
|
||||||
}
|
}
|
||||||
err := GetUserLoginAttemptCount(context.Background(), &query)
|
err := sqlStore.GetUserLoginAttemptCount(context.Background(), &query)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, int64(3), query.Result)
|
require.Equal(t, int64(3), query.Result)
|
||||||
})
|
})
|
||||||
@ -73,7 +73,7 @@ func TestLoginAttempts(t *testing.T) {
|
|||||||
Username: user,
|
Username: user,
|
||||||
Since: timePlusOneMinute,
|
Since: timePlusOneMinute,
|
||||||
}
|
}
|
||||||
err := GetUserLoginAttemptCount(context.Background(), &query)
|
err := sqlStore.GetUserLoginAttemptCount(context.Background(), &query)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, int64(2), query.Result)
|
require.Equal(t, int64(2), query.Result)
|
||||||
})
|
})
|
||||||
@ -84,7 +84,7 @@ func TestLoginAttempts(t *testing.T) {
|
|||||||
Username: user,
|
Username: user,
|
||||||
Since: timePlusTwoMinutes,
|
Since: timePlusTwoMinutes,
|
||||||
}
|
}
|
||||||
err := GetUserLoginAttemptCount(context.Background(), &query)
|
err := sqlStore.GetUserLoginAttemptCount(context.Background(), &query)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, int64(1), query.Result)
|
require.Equal(t, int64(1), query.Result)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user