-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make "/user/login" page redirect if the current user has signed in (#…
- Loading branch information
1 parent
4ef7e49
commit 02df269
Showing
4 changed files
with
65 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 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/contexttest" | ||
"code.gitea.io/gitea/modules/test" | ||
|
||
"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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters