mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 12:59:11 -05:00
9482b023a8
Fix #29582 and maybe more. Maybe fix #29116 (cherry picked from commit df1268ca08aaacae54c775a8eec34006dfe365e0)
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package auth
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/modules/test"
|
|
"code.gitea.io/gitea/services/contexttest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestUserLogin(t *testing.T) {
|
|
ctx, resp := contexttest.MockContext(t, "/user/login")
|
|
SignIn(ctx)
|
|
assert.Equal(t, http.StatusOK, resp.Code)
|
|
|
|
ctx, resp = contexttest.MockContext(t, "/user/login")
|
|
ctx.IsSigned = true
|
|
SignIn(ctx)
|
|
assert.Equal(t, http.StatusSeeOther, resp.Code)
|
|
assert.Equal(t, "/", test.RedirectURL(resp))
|
|
|
|
ctx, resp = contexttest.MockContext(t, "/user/login?redirect_to=/other")
|
|
ctx.IsSigned = true
|
|
SignIn(ctx)
|
|
assert.Equal(t, "/other", test.RedirectURL(resp))
|
|
|
|
ctx, resp = contexttest.MockContext(t, "/user/login")
|
|
ctx.Req.AddCookie(&http.Cookie{Name: "redirect_to", Value: "/other-cookie"})
|
|
ctx.IsSigned = true
|
|
SignIn(ctx)
|
|
assert.Equal(t, "/other-cookie", test.RedirectURL(resp))
|
|
|
|
ctx, resp = contexttest.MockContext(t, "/user/login?redirect_to="+url.QueryEscape("https://example.com"))
|
|
ctx.IsSigned = true
|
|
SignIn(ctx)
|
|
assert.Equal(t, "/", test.RedirectURL(resp))
|
|
}
|