1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-08-26 18:20:57 +00:00

[GITEA] Fix session generation for database

- If the session doesn't exist, it shouldn't be expected that the
variable is non-nil. Define the session variable instead and insert that.
- Add unit tests to test the behavior of the database sessions code .
- Regression caused by dd30d9d5c0.
- Resolves https://codeberg.org/forgejo/forgejo/issues/2042
This commit is contained in:
Gusted 2023-12-27 23:22:06 +01:00
parent d9dab91cec
commit 90307ad200
No known key found for this signature in database
GPG key ID: FD821B732837125F
2 changed files with 147 additions and 2 deletions

View file

@ -45,8 +45,11 @@ func ReadSession(ctx context.Context, key string) (*Session, error) {
if err != nil {
return nil, err
} else if !exist {
session.Expiry = timeutil.TimeStampNow()
if err := db.Insert(ctx, &session); err != nil {
session = &Session{
Key: key,
Expiry: timeutil.TimeStampNow(),
}
if err := db.Insert(ctx, session); err != nil {
return nil, err
}
}