2023-12-27 02:24:23 -05:00
|
|
|
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/auth"
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
"code.gitea.io/gitea/models/unittest"
|
|
|
|
"code.gitea.io/gitea/tests"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-07-30 15:42:06 -04:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-12-27 02:24:23 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_RegenerateSession(t *testing.T) {
|
|
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
|
2024-07-30 15:42:06 -04:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2023-12-27 02:24:23 -05:00
|
|
|
|
|
|
|
key := "new_key890123456" // it must be 16 characters long
|
|
|
|
key2 := "new_key890123457" // it must be 16 characters
|
|
|
|
exist, err := auth.ExistSession(db.DefaultContext, key)
|
2024-07-30 15:42:06 -04:00
|
|
|
require.NoError(t, err)
|
2023-12-27 02:24:23 -05:00
|
|
|
assert.False(t, exist)
|
|
|
|
|
|
|
|
sess, err := auth.RegenerateSession(db.DefaultContext, "", key)
|
2024-07-30 15:42:06 -04:00
|
|
|
require.NoError(t, err)
|
2023-12-27 02:24:23 -05:00
|
|
|
assert.EqualValues(t, key, sess.Key)
|
2024-07-30 15:42:06 -04:00
|
|
|
assert.Empty(t, sess.Data, 0)
|
2023-12-27 02:24:23 -05:00
|
|
|
|
|
|
|
sess, err = auth.ReadSession(db.DefaultContext, key2)
|
2024-07-30 15:42:06 -04:00
|
|
|
require.NoError(t, err)
|
2023-12-27 02:24:23 -05:00
|
|
|
assert.EqualValues(t, key2, sess.Key)
|
2024-07-30 15:42:06 -04:00
|
|
|
assert.Empty(t, sess.Data, 0)
|
2023-12-27 02:24:23 -05:00
|
|
|
}
|