Files
gotea/services/auth/session_test.go
T
lotherk 1b490485ff refactor: import Gotea from Gitea v28.4.0
Rename the main module to gotea.dev and the binary to gotea, and update the application name and English locale. Keep the external gitea.dev/sdk and gitea.dev/actionslib module imports unchanged.

Assisted-by: OpenCode:DeepSeek-V4.1-Flash
2026-11-22 12:13:09 +00:00

39 lines
1022 B
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package auth
import (
"net/http"
"testing"
"gotea.dev/models/unittest"
user_model "gotea.dev/models/user"
"gotea.dev/modules/session"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSessionVerify(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
req, err := http.NewRequest(http.MethodGet, "/", nil)
require.NoError(t, err)
sess := session.NewMockMemStore("dummy-sid")
method := &Session{}
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
require.NoError(t, sess.Set(session.KeyUID, user.ID))
u, err := method.Verify(req, nil, nil, sess)
assert.NoError(t, err)
require.NotNil(t, u)
assert.Equal(t, user.ID, u.ID)
require.NoError(t, user_model.UpdateUserCols(t.Context(), &user_model.User{ID: user.ID, Type: user_model.UserTypeBot}, "type"))
u, err = method.Verify(req, nil, nil, sess)
assert.NoError(t, err)
assert.Nil(t, u)
}