2016-10-04 20:34:36 +00:00
|
|
|
package datastore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-06-26 04:46:51 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
2016-10-04 20:34:36 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-06-06 22:07:29 +00:00
|
|
|
func testPasswordResetRequests(t *testing.T, db fleet.Datastore) {
|
2016-10-04 20:34:36 +00:00
|
|
|
createTestUsers(t, db)
|
2017-01-04 21:16:17 +00:00
|
|
|
now := time.Now().UTC()
|
2016-10-04 20:34:36 +00:00
|
|
|
tomorrow := now.Add(time.Hour * 24)
|
|
|
|
var passwordResetTests = []struct {
|
|
|
|
userID uint
|
|
|
|
expires time.Time
|
|
|
|
token string
|
|
|
|
}{
|
|
|
|
{userID: 1, expires: tomorrow, token: "abcd"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range passwordResetTests {
|
2021-06-06 22:07:29 +00:00
|
|
|
r := &fleet.PasswordResetRequest{
|
2016-10-04 20:34:36 +00:00
|
|
|
UserID: tt.userID,
|
|
|
|
ExpiresAt: tt.expires,
|
|
|
|
Token: tt.token,
|
|
|
|
}
|
|
|
|
req, err := db.NewPasswordResetRequest(r)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, tt.userID, req.UserID)
|
|
|
|
}
|
|
|
|
}
|