diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-12-27 15:24:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-27 15:24:23 +0800 |
commit | 4c29c75968f520123f125e8305b2c29198664251 (patch) | |
tree | de556b8083fd2a1b671d7cc9536fe0f1ebe91218 /tests/integration/session_test.go | |
parent | a1dfffd723c434966152ee521c99e966a3aee065 (diff) | |
download | gitea-4c29c75968f520123f125e8305b2c29198664251.tar.gz gitea-4c29c75968f520123f125e8305b2c29198664251.zip |
Fix session key conflict with database keyword (#28613)
This is a regression from #28220 .
`builder.Cond` will not add `` ` `` automatically but xorm method
`Get/Find` adds `` ` ``.
This PR also adds tests to prevent the method from being implemented
incorrectly. The tests are added in `integrations` to test every
database.
Diffstat (limited to 'tests/integration/session_test.go')
-rw-r--r-- | tests/integration/session_test.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/integration/session_test.go b/tests/integration/session_test.go new file mode 100644 index 0000000000..d47148efa2 --- /dev/null +++ b/tests/integration/session_test.go @@ -0,0 +1,37 @@ +// 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" +) + +func Test_RegenerateSession(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + assert.NoError(t, unittest.PrepareTestDatabase()) + + key := "new_key890123456" // it must be 16 characters long + key2 := "new_key890123457" // it must be 16 characters + exist, err := auth.ExistSession(db.DefaultContext, key) + assert.NoError(t, err) + assert.False(t, exist) + + sess, err := auth.RegenerateSession(db.DefaultContext, "", key) + assert.NoError(t, err) + assert.EqualValues(t, key, sess.Key) + assert.Len(t, sess.Data, 0) + + sess, err = auth.ReadSession(db.DefaultContext, key2) + assert.NoError(t, err) + assert.EqualValues(t, key2, sess.Key) + assert.Len(t, sess.Data, 0) +} |