mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-26 01:40:36 +00:00
[GITEA] Fix session generation for database (squash) timeutil.Mock
because ofe743570f65
* Refactor timeutil package (#28623) (cherry picked from commitacc6b51be2
) (cherry picked from commit02b74317f2
)
This commit is contained in:
parent
986be6171a
commit
63b9b624bd
1 changed files with 7 additions and 7 deletions
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
func TestAuthSession(t *testing.T) {
|
func TestAuthSession(t *testing.T) {
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
defer timeutil.Unset()
|
defer timeutil.MockUnset()
|
||||||
|
|
||||||
key := "I-Like-Free-Software"
|
key := "I-Like-Free-Software"
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ func TestAuthSession(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
now := time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)
|
now := time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||||
timeutil.Set(now)
|
timeutil.MockSet(now)
|
||||||
|
|
||||||
// New session is created.
|
// New session is created.
|
||||||
sess, err := auth.ReadSession(db.DefaultContext, key)
|
sess, err := auth.ReadSession(db.DefaultContext, key)
|
||||||
|
@ -54,13 +54,13 @@ func TestAuthSession(t *testing.T) {
|
||||||
t.Run("Update session", func(t *testing.T) {
|
t.Run("Update session", func(t *testing.T) {
|
||||||
data := []byte{0xba, 0xdd, 0xc0, 0xde}
|
data := []byte{0xba, 0xdd, 0xc0, 0xde}
|
||||||
now := time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC)
|
now := time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||||
timeutil.Set(now)
|
timeutil.MockSet(now)
|
||||||
|
|
||||||
// Update session.
|
// Update session.
|
||||||
err := auth.UpdateSession(db.DefaultContext, key, data)
|
err := auth.UpdateSession(db.DefaultContext, key, data)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
timeutil.Set(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC))
|
timeutil.MockSet(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC))
|
||||||
|
|
||||||
// Read updated session.
|
// Read updated session.
|
||||||
// Ensure data is updated and expiry is set from the update session call.
|
// Ensure data is updated and expiry is set from the update session call.
|
||||||
|
@ -70,7 +70,7 @@ func TestAuthSession(t *testing.T) {
|
||||||
assert.EqualValues(t, data, sess.Data)
|
assert.EqualValues(t, data, sess.Data)
|
||||||
assert.EqualValues(t, now.Unix(), sess.Expiry)
|
assert.EqualValues(t, now.Unix(), sess.Expiry)
|
||||||
|
|
||||||
timeutil.Set(now)
|
timeutil.MockSet(now)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Delete session", func(t *testing.T) {
|
t.Run("Delete session", func(t *testing.T) {
|
||||||
|
@ -97,13 +97,13 @@ func TestAuthSession(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Cleanup sessions", func(t *testing.T) {
|
t.Run("Cleanup sessions", func(t *testing.T) {
|
||||||
timeutil.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
|
timeutil.MockSet(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
|
||||||
|
|
||||||
_, err := auth.ReadSession(db.DefaultContext, "sess-1")
|
_, err := auth.ReadSession(db.DefaultContext, "sess-1")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// One minute later.
|
// One minute later.
|
||||||
timeutil.Set(time.Date(2023, 1, 1, 0, 1, 0, 0, time.UTC))
|
timeutil.MockSet(time.Date(2023, 1, 1, 0, 1, 0, 0, time.UTC))
|
||||||
_, err = auth.ReadSession(db.DefaultContext, "sess-2")
|
_, err = auth.ReadSession(db.DefaultContext, "sess-2")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue