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() {
|
||||
bus.AddHandler("sql", ss.CreateLoginAttempt)
|
||||
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 {
|
||||
@ -65,9 +65,10 @@ 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 {
|
||||
return ss.WithDbSession(ctx, func(dbSession *DBSession) error {
|
||||
loginAttempt := new(models.LoginAttempt)
|
||||
total, err := x.
|
||||
total, err := dbSession.
|
||||
Where("username = ?", query.Username).
|
||||
And("created >= ?", query.Since.Unix()).
|
||||
Count(loginAttempt)
|
||||
@ -78,6 +79,7 @@ func GetUserLoginAttemptCount(ctx context.Context, query *models.GetUserLoginAtt
|
||||
|
||||
query.Result = total
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func toInt64(i interface{}) int64 {
|
||||
|
@ -51,7 +51,7 @@ func TestLoginAttempts(t *testing.T) {
|
||||
Username: user,
|
||||
Since: timePlusTwoMinutes.Add(time.Second * 1),
|
||||
}
|
||||
err := GetUserLoginAttemptCount(context.Background(), &query)
|
||||
err := sqlStore.GetUserLoginAttemptCount(context.Background(), &query)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, int64(0), query.Result)
|
||||
})
|
||||
@ -62,7 +62,7 @@ func TestLoginAttempts(t *testing.T) {
|
||||
Username: user,
|
||||
Since: beginningOfTime,
|
||||
}
|
||||
err := GetUserLoginAttemptCount(context.Background(), &query)
|
||||
err := sqlStore.GetUserLoginAttemptCount(context.Background(), &query)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, int64(3), query.Result)
|
||||
})
|
||||
@ -73,7 +73,7 @@ func TestLoginAttempts(t *testing.T) {
|
||||
Username: user,
|
||||
Since: timePlusOneMinute,
|
||||
}
|
||||
err := GetUserLoginAttemptCount(context.Background(), &query)
|
||||
err := sqlStore.GetUserLoginAttemptCount(context.Background(), &query)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, int64(2), query.Result)
|
||||
})
|
||||
@ -84,7 +84,7 @@ func TestLoginAttempts(t *testing.T) {
|
||||
Username: user,
|
||||
Since: timePlusTwoMinutes,
|
||||
}
|
||||
err := GetUserLoginAttemptCount(context.Background(), &query)
|
||||
err := sqlStore.GetUserLoginAttemptCount(context.Background(), &query)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, int64(1), query.Result)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user